Skip to content
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
12 changes: 12 additions & 0 deletions docs/user/markdown.rst
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,15 @@ The following types are supported:

.. note::
You should note that the title will be automatically capitalized.

Instance-specific extensions
----------------------------

You can specify a list of additional extensions to the markdown parser per instance.
A list of potentially interesting extensions can be access in `Python-markdown's wiki <https://github.com/Python-Markdown/markdown/wiki/Third-Party-Extensions>`_.

For example, to automatically link URLs: ::

class Config(DefaultConfig):
...
markdown_extensions = ['pymdownx.magiclink']
1 change: 1 addition & 0 deletions src/moin/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class for the benefit of the WikiConfig macro.
auth_have_login = None
auth_login_inputs = None
_site_plugin_lists = None
markdown_extensions = []

def __init__(self):
"""Init Config instance"""
Expand Down
15 changes: 14 additions & 1 deletion src/moin/converters/_tests/test_markdown_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
MoinMoin - Tests for moin.converters.markdown_in
"""

from collections import namedtuple
import pytest
from flask import Flask

from . import serialize, XMLNS_RE

Expand All @@ -15,13 +17,24 @@
from ..markdown_in import Converter


DefaultConfig = namedtuple("DefaultConfig", ("markdown_extensions",))
config = DefaultConfig(markdown_extensions=[])


class TestConverter:
namespaces = {moin_page: "", xlink: "xlink", xinclude: "xinclude", html: "html"}

output_re = XMLNS_RE

def setup_class(self):
self.conv = Converter()
# mock patching flask.current_app.cfg does not work here as for speccing the original object is called and that causes a "RuntimeError: working outside of application context"
app = Flask(__name__)
# DefaultConfig doesn't work here as it does not provide all the defaults required to be initialized
app.cfg = config
ctx = app.app_context()
ctx.push()
with ctx:
self.conv = Converter()

data = [
("Text", "<p>Text</p>"),
Expand Down
15 changes: 14 additions & 1 deletion src/moin/converters/_tests/test_markdown_in_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
MoinMoin - Tests for markdown->DOM->markdown using markdown_in and markdown_out converters
"""

from collections import namedtuple
import pytest
from flask import Flask

from emeraldtree import ElementTree as ET

Expand All @@ -18,6 +20,10 @@
from moin.converters.markdown_out import Converter as conv_out


DefaultConfig = namedtuple("DefaultConfig", ("markdown_extensions",))
config = DefaultConfig(markdown_extensions=[])


class TestConverter:

input_namespaces = 'xmlns="{}" xmlns:page="{}" xmlns:xlink="{}" xmlns:xinclude="{}" xmlns:html="{}"'.format(
Expand All @@ -36,7 +42,14 @@ class TestConverter:
output_re = XMLNS_RE

def setup_class(self):
self.conv_in = conv_in()
# mock patching flask.current_app.cfg does not work here as for speccing the original object is called and that causes a "RuntimeError: working outside of application context"
app = Flask(__name__)
# DefaultConfig doesn't work here as it does not provide all the defaults required to be initialized
app.cfg = config
ctx = app.app_context()
ctx.push()
with ctx:
self.conv_in = conv_in()
self.conv_out = conv_out()

data = [
Expand Down
7 changes: 6 additions & 1 deletion src/moin/converters/markdown_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ._util import decode_data
from moin.utils.iri import Iri
from moin.converters.html_in import Converter as HTML_IN_Converter
from flask import current_app

from emeraldtree import ElementTree as ET

Expand Down Expand Up @@ -558,8 +559,12 @@ def convert_invalid_p_nodes(self, node):
self.convert_invalid_p_nodes(child)

def __init__(self):
# The Moin configuration
self.app_configuration = current_app.cfg

self.markdown = Markdown(
extensions=[ExtraExtension(), CodeHiliteExtension(guess_lang=False), "mdx_wikilink_plus", "admonition"],
extensions=[ExtraExtension(), CodeHiliteExtension(guess_lang=False), "mdx_wikilink_plus", "admonition"]
+ self.app_configuration.markdown_extensions,
extension_configs={
"mdx_wikilink_plus": {
"html_class": None,
Expand Down
Loading