From 66ab3aee5f0402cc1b51acaa27cc22e492412703 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Wed, 20 Sep 2023 21:24:11 +0200 Subject: [PATCH] Markdown: Enable Admonition extension the Admonition extension is built in the markdown-parser: https://python-markdown.github.io/extensions/admonition/ This PR enables the extension and adds documentation to it, as well as tests The rst admonitions don't handle titles, so the documentation can't contain examples for this feature. --- docs/user/markdown.rst | 36 +++++++++++++++++++ .../converters/_tests/test_markdown_in.py | 15 ++++++++ src/moin/converters/markdown_in.py | 1 + src/moin/static/css/common.css | 5 +++ 4 files changed, 57 insertions(+) diff --git a/docs/user/markdown.rst b/docs/user/markdown.rst index ff8682c0d..3f4028526 100644 --- a/docs/user/markdown.rst +++ b/docs/user/markdown.rst @@ -717,3 +717,39 @@ Footnotes [1]_ have a label [#label]_ and a definition [#DEF]_. .. [#label] A footnote on "label" .. [#DEF] The footnote for definition + +Admonition +---------- + +The `Admonition extension `_ adds `rST-style `_ admonitions to Markdown. + +**Syntax**: :: + + !!! type "optional explicit title within double quotes" + Any number of other indented markdown elements. + + This is the second paragraph. + +If you don’t want a title, use a blank string "". + +The following types are supported: + +* attention +* caution +* danger +* error +* hint +* important +* note +* tip +* warning + +**Markup**: :: + + !!! note + You should note that the title will be automatically capitalized. + +**Result**: + +.. note:: + You should note that the title will be automatically capitalized. diff --git a/src/moin/converters/_tests/test_markdown_in.py b/src/moin/converters/_tests/test_markdown_in.py index 21498c66d..9a1217675 100644 --- a/src/moin/converters/_tests/test_markdown_in.py +++ b/src/moin/converters/_tests/test_markdown_in.py @@ -153,6 +153,21 @@ def test_wikilinks(self, input, output): """ Test the Wikilinks extension: https://python-markdown.github.io/extensions/wikilinks/""" self.do(input, output) + data = [ + ('!!! note\n You should note that the title will be automatically capitalized.', + '

Note

You should note that the title will be automatically capitalized.

'), + ('!!! danger "Don\'t try this at home"\n ...', + '

Don\'t try this at home

...

'), + ('!!! important ""\n This is an admonition box without a title.', + '

This is an admonition box without a title.

'), + ('!!! danger highlight blink "Don\'t try this at home"\n ...', + ''), + ] + + @pytest.mark.parametrize('input,output', data) + def test_admonition(self, input, output): + self.do(input, output) + def serialize_strip(self, elem, **options): result = serialize(elem, namespaces=self.namespaces, **options) return self.output_re.sub('', result) diff --git a/src/moin/converters/markdown_in.py b/src/moin/converters/markdown_in.py index a6dece241..8904e6325 100644 --- a/src/moin/converters/markdown_in.py +++ b/src/moin/converters/markdown_in.py @@ -533,6 +533,7 @@ def __init__(self): ExtraExtension(), CodeHiliteExtension(guess_lang=False), 'mdx_wikilink_plus', + 'admonition', ], extension_configs={ 'mdx_wikilink_plus': { diff --git a/src/moin/static/css/common.css b/src/moin/static/css/common.css index 23090a93c..5e560891f 100644 --- a/src/moin/static/css/common.css +++ b/src/moin/static/css/common.css @@ -99,6 +99,11 @@ div.tip > p, div.warning > ol, div.warning > ul, div.warning > p { margin-top: 8px; padding-left: 4em; } +/* Admonition extension of Markdown parser */ +.admonition-title { + font-weight: bold; + font-size: 1.1em; +} /* end of admonitions */ /* mime type icons */