Wagtail RichTextBlock 扩展以选择颜色
Wagtail RichTextBlock extend to pick color
我正在尝试在 wagtail RichTextBlock
中实现颜色选择器选项,这样我就可以 select 我的 selected 文本的任何颜色。
这是我的 wagtail_hooks.py
文件:
@hooks.register("register_rich_text_features")
def register_colortext_feature(features):
"""Creates centered text in our richtext editor and page."""
# Step 1
feature_name = "Text Color Picker"
type_ = "TEXTCOLOR"
tag = "span"
# Step 2
control = {
"type": type_,
"label": "color",
"description": "Color Text",
# "style": {
# "display": "block",
# "text-align": "center",
# },
}
# Step 3
features.register_editor_plugin(
"draftail", feature_name, draftail_features.InlineStyleFeature(control)
)
# Step 4
db_conversion = {
"from_database_format": {tag: InlineStyleElementHandler(type_)},
"to_database_format": {
"style_map": {
type_: {
"element": tag,
"props": {
"style": "color:colorcode"
}
}
}
}
}
# Step 5
features.register_converter_rule("contentstate", feature_name, db_conversion)
# Step 6, This is optional.
features.default_features.append(feature_name)
有没有人可以帮我解决这个问题?我只是尽力做到这一点,但没有运气。
您能否将字符字段或字符块添加到您的模型或流块中,您可以在其中输入十六进制值并在模板中读取字段值并将文本颜色设置为该值?
我正在尝试在 wagtail RichTextBlock
中实现颜色选择器选项,这样我就可以 select 我的 selected 文本的任何颜色。
这是我的 wagtail_hooks.py
文件:
@hooks.register("register_rich_text_features")
def register_colortext_feature(features):
"""Creates centered text in our richtext editor and page."""
# Step 1
feature_name = "Text Color Picker"
type_ = "TEXTCOLOR"
tag = "span"
# Step 2
control = {
"type": type_,
"label": "color",
"description": "Color Text",
# "style": {
# "display": "block",
# "text-align": "center",
# },
}
# Step 3
features.register_editor_plugin(
"draftail", feature_name, draftail_features.InlineStyleFeature(control)
)
# Step 4
db_conversion = {
"from_database_format": {tag: InlineStyleElementHandler(type_)},
"to_database_format": {
"style_map": {
type_: {
"element": tag,
"props": {
"style": "color:colorcode"
}
}
}
}
}
# Step 5
features.register_converter_rule("contentstate", feature_name, db_conversion)
# Step 6, This is optional.
features.default_features.append(feature_name)
有没有人可以帮我解决这个问题?我只是尽力做到这一点,但没有运气。
您能否将字符字段或字符块添加到您的模型或流块中,您可以在其中输入十六进制值并在模板中读取字段值并将文本颜色设置为该值?