Once this is registered, do I have to modify each RichTextField that I have to include it in the features setting, or is there a way to add this to all RTF in my application?推荐答案我相信我已经想出了如何做到这一点,希望如果有更好的方法,有人会纠正我!I believe I have figured out how to do this, hopefully, someone will correct me if there is a better way!在您注册的应用目录之一(在 INSTALLED_APPS 中)创建一个名为 wagtail_hooks.py 的文件.在文件中加入以下代码:Create a file in one of your registered (in INSTALLED_APPS) app directories called wagtail_hooks.py.Put the following code in the file:import wagtail.admin.rich_text.editors.draftail.features as draftail_featuresfrom wagtail.admin.rich_text.converters.html_to_contentstate import InlineStyleElementHandlerfrom wagtail.core import [email protected]('register_rich_text_features')def register_strikethrough_feature(features): feature_name = 'superscript' type_ = 'SUPERSCRIPT' tag = 'sup' control = { 'type': type_, 'label': '^', 'description': 'Superscript', } features.register_editor_plugin( 'draftail', feature_name, draftail_features.InlineStyleFeature(control) ) db_conversion = { 'from_database_format': {tag: InlineStyleElementHandler(type_)}, 'to_database_format': {'style_map': {type_: tag}}, } features.default_features.append(feature_name) features.register_converter_rule('contentstate', feature_name, db_conversion)行 features.default_features.append(feature_name) 回答了我问题的最后一部分 - 文档中没有(嗯,它在那里,但不在这个上下文中)).这会将功能添加到所有 RichTextFields,而无需将 features=[] 设置添加到每个现有和/或新 RTF.The line features.default_features.append(feature_name) is what answers the last part of my question - and is missing from the docs (well, it's there, but not in this context). This adds the feature to all RichTextFields without having to add the features=[] setting to each existing and/or new RTF.要修改它以与另一个内置 Draftail 功能一起使用,请修改 feature_name、type_、tag、label 和 description 字段.Draftail 支持以下类型:To modify this to work with another built in Draftail feature, modify the feature_name, type_, tag, label, and description fields. Draftail supports the following types:区块类型:H1、H2、H3、H4、H5、H6、Blockquote、Code、UL、OL、P内联样式:粗体、斜体、下划线、代码、删除线、标记、键盘、上标、下标还有人力资源部,BR带粗体、斜体、h2、h3、h4、ul、ol、hr 和 br 已经在 RichTextField 的 Wagtail 默认设置中.With bold, italic, h2, h3, h4, ul, ol, hr, and br already being in the Wagtail default set for a RichTextField. 这篇关于在 Wagtail 2.0 中为 Draftail 添加上标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-29 03:55