I created a wagtail hook for adding a code block from the Richtext editor. The hook is working but I have the problem. The hook supposed to work like as follows,
<div class="code">
content line one
content line two
</div>
But when I apply the block from editor , it is applying each line with the code like,
<div class="code">content line one </div>
<div class="code">content line two </div>
This was supposed to be one line, The wagtail editor is applying multiple divs for each of the lines instead of one div for the selected block
My hook code is as follows,
@hooks.register('register_rich_text_features')
def register_py_code_block_feature(features):
"""
Registering for adding python code block
"""
feature_name = 'py-code-block'
type_ = 'py-code-block'
control = {
'type': type_,
'label': 'PY',
'description': 'Python Code Block',
# Optionally, we can tell Draftail what element to use when displaying those blocks in the editor.
'element': 'div',
'style': {
"display": "block",
},
}
db_conversion = {
'from_database_format': {'div': BlockElementHandler(type_)},
'to_database_format': {'block_map': {type_: {
'element': 'div',
'props': {
'class': 'code blog_code language-python'
}
}
}
},
}
features.register_editor_plugin('draftail', feature_name, draftail_features.BlockFeature(control))
features.register_converter_rule('contentstate', feature_name, db_conversion)
features.default_features.append('py-code-block')
Can some one point me the right direction