Skip to content

Commit

Permalink
markdown: use wikilink extension
Browse files Browse the repository at this point in the history
For easier internal wiki links, activate the wikilink extension https://github.com/neurobin/mdx_wikilink_plus
Previously, an internal link had to be: `[OtherPage](OtherPage)`
now, this works too `[[OtherPage]]` and `[[Page/Subpage]]`

The wikilink extension of python-markdown itself (https://python-markdown.github.io/extensions/wikilinks/)
is very limited and does not handle links with slashes in their name, so
no sub pages
  • Loading branch information
wagner-intevation committed Sep 20, 2023
1 parent a1147ae commit fd2373c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
16 changes: 16 additions & 0 deletions docs/user/markdown.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ Inline links use the form: ::
**reST NOTE**: Links with title attributes and images as links are not supported in reST.
The internal links above are broken.

Wikilinks
---------

Wikilinks use the form: ::

[[PageName]]

=========================================== ===============================================
**Markup** **Result**
=========================================== ===============================================
[[Page]] `Page <http:Page>`_
[[Page/Subpage]] `Subpage <http:Page/Subpage>`_
=========================================== ===============================================

This features uses the `mdx_wikilink_plus <https://github.com/neurobin/mdx_wikilink_plus>`_ extension.

Reference Links
---------------

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
'blinker>=1.1', # event signalling (e.g. for change notification trigger)
'docutils>=0.18.1', # reST markup processing
'Markdown>=3.4.1', # Markdown markup processing
'mdx_wikilink_plus' >= mdx_wikilink_plus, # Markdown Wikilinks extension
'Flask<2.3.0', # micro framework
'Flask-Babel<3.0.0', # i18n support
'Flask-Caching>=1.2.0', # caching support
Expand Down
9 changes: 9 additions & 0 deletions src/moin/converters/_tests/test_markdown_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ def test_list(self, input, output):
def test_image(self, input, output):
self.do(input, output)

data = [('[[Bracketed]]',
'<p><a xlink:href="wiki.local:Bracketed">Bracketed</a></p>'),
('[[Main/sub]]', # check if label is kept lower case, check if slash in link is detected
'<p><a xlink:href="wiki.local:Main/sub">sub</a></p>')]
@pytest.mark.parametrize('input,output', data)
def test_wikilinks(self, input, output):
""" Test the Wikilinks extension: https://python-markdown.github.io/extensions/wikilinks/"""
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
16 changes: 13 additions & 3 deletions src/moin/converters/markdown_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import markdown.util as md_util
from markdown.extensions.extra import ExtraExtension
from markdown.extensions.codehilite import CodeHiliteExtension
from markdown.extensions.wikilinks import WikiLinkExtension

from . import default_registry
from moin.utils.mime import Type, type_moin_document
Expand Down Expand Up @@ -530,9 +531,18 @@ def convert_invalid_p_nodes(self, node):

def __init__(self):
self.markdown = Markdown(extensions=[
ExtraExtension(),
CodeHiliteExtension(guess_lang=False),
])
ExtraExtension(),
CodeHiliteExtension(guess_lang=False),
'mdx_wikilink_plus',
],
extension_configs={
'mdx_wikilink_plus': {
'html_class': None,
'image_class': None,
'label_case': 'none', # do not automatically CamelCase the label, keep it untouched
}
},
)

@classmethod
def _factory(cls, input, output, **kw):
Expand Down

0 comments on commit fd2373c

Please sign in to comment.