frostming / marko

A markdown parser with high extensibility.
https://marko-py.readthedocs.io/
MIT License
351 stars 38 forks source link

Code examples from the documentation incorrect? #211

Closed itsdanjc closed 1 day ago

itsdanjc commented 1 day ago

When following the latest stable version of the docs (Extend Marko). The resulting code is as follows:

from marko import inline
from marko.helpers import MarkoExtension

class GitHubWiki(inline.InlineElement):
    pattern = r'\[\[ *(.+?) *\| *(.+?) *\]\]'
    parse_children = True
    priority = 6

    def __init__(self, match):
        self.target = match.group(2)

class WikiRendererMixin(object):
    def render_github_wiki(self, element):
        return '<a href="{}">{}</a>'.format(
            self.escape_url(element.target), self.render_children(element)
        )

GitHubWiki = MarkoExtension(
    elements=[GitHubWiki],
    renderer_mixins=[WikiRendererMixin]
)

marko = Markdown(extensions=[GitHubWiki])
marko.convert('# Example from marko documentation\n *This is an [[emphasis*|target]]')

Gives this result:

<h1>Example from marko documentation</h1>
<p>*This is an emphasis*</p>

The docs suggests that this is the outcome:

<h1>Example from marko documentation</h1>
<p>*This is an <a href="target">emphasis*</a></p>

Is this the correct behavior, or could you clarify if it's a mistake on my end?


Environment:

frostming commented 1 day ago

Thanks, this has been fixed on main