How to obtain the content of the block in Block Extension API #2548
-
I'm creating my own block using Blocks Extension API,I followed the instruction and created a simple block class DialogueBlock(Block):
NAME = 'dialogue'
ARGUMENT = None
OPTIONS = {}
def on_create(self, parent):
# 获取块的内容 Get the content of the block.
return xml.etree.ElementTree.SubElement(parent, 'div') I want to get the block's content and parse it through my own code In the comments section of the code, but I didn't find any way to do that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You likely want to use At the Keep in mind that when using raw mode, it is recommended to indent the content. This is because things like the HTML parser, which is implemented as a preprocessor can sometimes adjust the content, so indenting helps preserve the content. Raw content is expected to be indented and will be dedented by one level automatically. |
Beta Was this translation helpful? Give feedback.
You likely want to use
raw
mode, so this should returnraw
IIRC: https://facelessuser.github.io/pymdown-extensions/extensions/blocks/api/#on_markdown-event.At the
on_end
event, you can extract the content from the element and do whatever you want with it: https://facelessuser.github.io/pymdown-extensions/extensions/blocks/api/#on_end-event.Keep in mind that when using raw mode, it is recommended to indent the content. This is because things like the HTML parser, which is implemented as a preprocessor can sometimes adjust the content, so indenting helps preserve the content. Raw content is expected to be indented and will be dedented by one level automatically.