Rich text
dexterity在設計編輯欄位的時候比較特別,使用RichText來處理
使用到的package說明如下
https://pypi.python.org/pypi/plone.app.textfield
示範代碼如下:
from plone.app.textfield import RichText
....
body = RichText(
title=_(u'Body'),
required=False,)
然後,要設定欄位內容,代碼如下:
from plone.app.textfield.value import RichTextValue
...
item.body=RichTextValue(u'<h2>This is Title</h2>', 'text/plain', 'text/html')
其中,text/plain是指定輸入方式
text/html是指定輸出方式
其他可能的選項還有諸如:
text/plain-pre
text/restructured
text/structured
text/x-python
text/x-rst
text/x-web-intelligent
text/x-web-markdown
text/x-web-textile
但不是每個都能正常使用,要依系統設定值而定,
這個選項會影響編輯畫面使用的編輯框
如果是text/html, 會使用WYSIWYG編輯器做為預設的篇輯框(例如TinyMCE)
如果是text/plain,那就會出現文字框來編輯了
特別要注意的是,如果內文要引用 dexteritytextindexer,做為全文檢索,
一定要使用text/html,
如果使用text/plain,那麼連 div, span, 這種html tag都會被納入全文檢索,這樣檢索品質就不好了!