Hikkaba icon indicating copy to clipboard operation
Hikkaba copied to clipboard

Refine markup parser

Open magicxor opened this issue 11 months ago • 0 comments

The current markup parsing logic requires improvement to prevent formatting rules from accidentally modifying text inside code blocks. We need to implement a mechanism to safely isolate code sections before applying other transformations.

While we considered a full migration to Markdig (with EmphasisExtra, AutoLinks, and custom BBCode extensions), we have decided to proceed with a custom "Hide-Replace-Restore" implementation for now.

We will implement a pipeline that processes text in three stages:

  1. Hide: Scan the input text for code blocks (both Markdown backticks and BBCode [code]). Extract these sections into a temporary array and replace them in the main text with unique placeholders (e.g., %%CODE_BLOCK_0%%).
  2. Replace: Perform all necessary text formatting, regex replacements, etc. on the main text (which now contains only placeholders for code).
  3. Restore: Iterate through the text one last time and replace the placeholders with the original, untouched code content from the array.

magicxor avatar Apr 01 '25 04:04 magicxor