diff --git a/src/backend/html_markdown.py b/src/backend/html_markdown.py
index aa0c1321..93836bb1 100644
--- a/src/backend/html_markdown.py
+++ b/src/backend/html_markdown.py
@@ -21,8 +21,6 @@ from .color import SVGColor
class MarkdownInlineGrammar(mistune.InlineGrammar):
"""Markdown inline elements syntax modifications for the Mistune parser.
- Modifications:
-
- Disable underscores for bold/italics (e.g. `__bold__`)
- Add syntax for coloring text: `(text)`,
@@ -42,6 +40,15 @@ class MarkdownInlineGrammar(mistune.InlineGrammar):
)
+class MarkdownBlockGrammar(mistune.BlockGrammar):
+ """Markdown block elements syntax modifications for the Mistune parser.
+
+ - Require a space after # for titles
+ """
+
+ heading = re.compile(r"^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)")
+
+
class MarkdownInlineLexer(mistune.InlineLexer):
"""Apply the changes from `MarkdownInlineGrammar` for Mistune."""
@@ -74,6 +81,12 @@ class MarkdownInlineLexer(mistune.InlineLexer):
return self.renderer.color(color, text)
+class MarkdownBlockLexer(mistune.BlockLexer):
+ """Apply the changes from `MarkdownBlockGrammar` for Mistune."""
+
+ grammar_class = MarkdownBlockGrammar
+
+
class MarkdownRenderer(mistune.Renderer):
def color(self, color: str, text: str) -> str:
"""Render given text with a color using ``."""
@@ -186,10 +199,11 @@ class HTMLProcessor:
# hard_wrap: convert all \n to
without required two spaces
# escape: escape HTML characters in the input string, e.g. tags
self._markdown_to_html = mistune.Markdown(
- hard_wrap=True,
- escape=True,
- inline=MarkdownInlineLexer,
- renderer=MarkdownRenderer(),
+ hard_wrap = True,
+ escape = True,
+ inline = MarkdownInlineLexer,
+ block = MarkdownBlockLexer,
+ renderer = MarkdownRenderer(),
)
self._markdown_to_html.block.default_rules = [