Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Markdown: Enable Admonition extension #1514

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/user/markdown.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://python-markdown.github.io/extensions/admonition/>`_ adds `rST-style <http://docutils.sourceforge.net/docs/ref/rst/directives.html#specific-admonitions>`_ 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.
15 changes: 15 additions & 0 deletions src/moin/converters/_tests/test_markdown_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
'<div class="admonition note"><p class="admonition-title">Note</p><p>You should note that the title will be automatically capitalized.</p></div>'),
('!!! danger "Don\'t try this at home"\n ...',
'<div class="admonition danger"><p class="admonition-title">Don\'t try this at home</p><p>...</p></div>'),
('!!! important ""\n This is an admonition box without a title.',
'<div class="admonition important"><p>This is an admonition box without a title.</p></div>'),
('!!! danger highlight blink "Don\'t try this at home"\n ...',
'<div class="admonition danger highlight blink"><p class="admonition-title">Don\'t try this at home</p><p>...</p></div>'),
]

@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)
Expand Down
1 change: 1 addition & 0 deletions src/moin/converters/markdown_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,7 @@ def __init__(self):
ExtraExtension(),
CodeHiliteExtension(guess_lang=False),
'mdx_wikilink_plus',
'admonition',
],
extension_configs={
'mdx_wikilink_plus': {
Expand Down
5 changes: 5 additions & 0 deletions src/moin/static/css/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down