markdown: don't parse "> ..." as blockquote
This commit is contained in:
parent
238f38c9f0
commit
6e65376612
1
TODO.md
1
TODO.md
|
@ -63,6 +63,7 @@
|
||||||
- Prevent using the SendBox if no permission (power levels)
|
- Prevent using the SendBox if no permission (power levels)
|
||||||
- Spinner when loading past room events, images or clicking buttons
|
- Spinner when loading past room events, images or clicking buttons
|
||||||
- Parse themes from JSON
|
- Parse themes from JSON
|
||||||
|
- Distribute fonts
|
||||||
- Settings page
|
- Settings page
|
||||||
- Message/text selection
|
- Message/text selection
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,11 @@ import html_sanitizer.sanitizer as sanitizer
|
||||||
from html_sanitizer.sanitizer import Sanitizer
|
from html_sanitizer.sanitizer import Sanitizer
|
||||||
|
|
||||||
|
|
||||||
|
class MarkdownRenderer(mistune.Renderer):
|
||||||
|
def block_quote(self, text: str) -> str:
|
||||||
|
return re.sub(r"^<p>", "<p>>", text)
|
||||||
|
|
||||||
|
|
||||||
class HtmlFilter:
|
class HtmlFilter:
|
||||||
link_regexes = [re.compile(r, re.IGNORECASE) for r in [
|
link_regexes = [re.compile(r, re.IGNORECASE) for r in [
|
||||||
(r"(?P<body>[a-zA-Z\d]+://(?P<host>[a-z\d._-]+)"
|
(r"(?P<body>[a-zA-Z\d]+://(?P<host>[a-z\d._-]+)"
|
||||||
|
@ -29,7 +34,14 @@ class HtmlFilter:
|
||||||
sanitizer.normalize_whitespace_in_text_or_tail = lambda el: el
|
sanitizer.normalize_whitespace_in_text_or_tail = lambda el: el
|
||||||
|
|
||||||
# hard_wrap: convert all \n to <br> without required two spaces
|
# hard_wrap: convert all \n to <br> without required two spaces
|
||||||
self._markdown_to_html = mistune.Markdown(hard_wrap=True)
|
self._markdown_to_html = mistune.Markdown(
|
||||||
|
hard_wrap=True, renderer=MarkdownRenderer()
|
||||||
|
)
|
||||||
|
|
||||||
|
self._markdown_to_html.block.default_rules = [
|
||||||
|
rule for rule in self._markdown_to_html.block.default_rules
|
||||||
|
if rule != "block_quote"
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def from_markdown(self, text: str) -> str:
|
def from_markdown(self, text: str) -> str:
|
||||||
|
@ -76,8 +88,8 @@ class HtmlFilter:
|
||||||
}
|
}
|
||||||
|
|
||||||
inlines_attributes = {
|
inlines_attributes = {
|
||||||
# TODO: translate font attrs to qt html subset
|
# TODO: translate font attrs to qt html subset, disallow color
|
||||||
"font": {"data-mx-bg-color", "data-mx-color"},
|
"font": {"data-mx-bg-color", "data-mx-color", "color"},
|
||||||
"a": {"href"},
|
"a": {"href"},
|
||||||
"code": {"class"},
|
"code": {"class"},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user