feat: Parse markdown within html block elements

By default, markdown within an HTML block element is not parsed.
Add markdown extension to support markdown text within block
elements.

With this we can annotate our element with a "markdown" attribute:
E.g. <details markdown>*Markdown*</details>
And thus indicate that the content should be parsed.

Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
moson 2023-11-27 14:08:04 +01:00
parent 1ba9e6eb44
commit a0b2e826be
No known key found for this signature in database
GPG key ID: 4A4760AB4EE15296
2 changed files with 17 additions and 0 deletions

View file

@ -151,6 +151,7 @@ def update_comment_render(comment: PackageComment) -> None:
html = markdown.markdown(
text,
extensions=[
"md_in_html",
"fenced_code",
LinkifyExtension(),
FlysprayLinksExtension(),

View file

@ -105,6 +105,22 @@ def test_markdown_conversion(user: User, pkgbase: PackageBase):
assert comment.RenderedComment == expected
def test_markdown_in_html_block(user: User, pkgbase: PackageBase):
# without "markdown" attribute
text = "<details><summary>test</summary>*Hello*</details>"
comment = create_comment(user, pkgbase, text)
expected = "<details><summary>test</summary>*Hello*</details>"
assert comment.RenderedComment == expected
# with "markdown" attribute
text = "<details markdown><summary>test</summary>*Hello*</details>"
comment = create_comment(user, pkgbase, text)
expected = (
"<details>\n<p></p><summary>test</summary><em>Hello</em><p></p>\n</details>"
)
assert comment.RenderedComment == expected
def test_markdown_strikethrough(user: User, pkgbase: PackageBase):
text = "*~~Hello~~world*~~!~~"
comment = create_comment(user, pkgbase, text)