Digital Sovereignty for everyone

Block handlers

Other plugins can turn parts of Markdown or HTML into their own blocks when content is converted to blocks. LH Mermaid uses this so a Mermaid diagram written in Markdown or HTML lands as its Mermaid Diagram block, and any plugin with a block the conversion library has no mapping for can do the same.

Add a handler to the lh_content_converter_block_handlers filter, which takes and returns an array of callables. Each handler is called with the HTML and a claim function, and returns the HTML. Markdown has already been converted to HTML, so a code fence arrives as a pre element holding a code element with a language class. For each element it claims, the handler calls the claim function with the block markup it wants, and puts the placeholder it gets back in place of the element. LH Mermaid’s Lh_Mermaid_Block::claim_diagrams() is a worked example.

  • The placeholder is a paragraph of its own, so claim only elements that can stand as a block where they are.
  • Once the library has run, each placeholder’s paragraph block is swapped for the block markup exactly as given, so give what the block editor would save.
  • Handlers run before code blocks are protected, so a handler can claim a fenced code block.
  • If a placeholder isn’t found exactly once afterwards, the conversion fails with the lh_content_converter_block_restore_failed error rather than return content that can’t be trusted.

Handlers only apply to conversions to blocks, and every caller gets them: the post abilities, the knowledge base, LH Email drafts and LH Presentations slides.

If you like this plugin please consider making a donation to further development

Install LHero.org

lhero.org

Open it straight from your home screen, full screen and quicker to load.

  1. Tap the Share button . If you cannot see it, tap ••• first.
  2. Scroll down and tap Add to Home Screen.
  3. Tap Add.
  1. Tap the browser menu â‹®.
  2. Tap Install app or Add to Home screen.
  1. In the menu bar, choose File, then Add to Dock.

Use your browser's menu to install this site or add it to your home screen.