diff --git a/TODO.md b/TODO.md index 7a0e4319..66929b5f 100644 --- a/TODO.md +++ b/TODO.md @@ -92,7 +92,6 @@ - Way to open context menus without a right mouse button - `smartVerticalFlick()` gradual acceleration - Make banner buttons look better -- Way to color HTML from the composer - Choose a better default easing type for animations - Make HListView scrollbars visible diff --git a/src/backend/html_markdown.py b/src/backend/html_markdown.py index ee6758f6..968c04e4 100644 --- a/src/backend/html_markdown.py +++ b/src/backend/html_markdown.py @@ -16,17 +16,41 @@ class MarkdownInlineGrammar(mistune.InlineGrammar): Modifications: - Disable underscores for bold/italics (e.g. `__bold__`) + + - Add syntax for coloring text: `(text)`, + e.g. `(Lorem ipsum)` or `<#000040>(sit dolor amet...)` """ + escape = re.compile(r"^\\([\\`*{}\[\]()#+\-.!_<>~|])") # Add < emphasis = re.compile(r"^\*((?:\*\*|[^\*])+?)\*(?!\*)") double_emphasis = re.compile(r"^\*{2}([\s\S]+?)\*{2}(?!\*)") + # test string: r"(x) (x) \b>(x) b>(x) (\(z) (foo\)xyz)" + color = re.compile( + r"^<(.+?)>" # capture the color in `` + r"\((.+?)" # capture text in `(text` + r"(?`.""" + + return f'{text}' + + class HTMLProcessor: """Provide HTML filtering and conversion from Markdown. @@ -95,7 +132,10 @@ 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, + hard_wrap=True, + escape=True, + inline=MarkdownInlineLexer, + renderer=MarkdownRenderer(), ) self._markdown_to_html.block.default_rules = [