Skip to content

Commit

Permalink
Update subscript and superscript plugins to work with Python-Markdown…
Browse files Browse the repository at this point in the history
… 3.4.
  • Loading branch information
crisluengo committed Sep 14, 2022
1 parent 05775aa commit bfafe54
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
14 changes: 6 additions & 8 deletions doxpp/markdown/mdx_subscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@
<p>The molecular composition of water is H<sub>2</sub>O.</p>
:website: https://github.com/jambonrose/markdown_subscript_extension
:copyright: Copyright 2014-2018 Andrew Pinkham
:copyright: Copyright 2014-2018 Andrew Pinkham, Copyright 2022 Cris Luengo
:license: Simplified BSD, see LICENSE for details.
"""

from markdown.extensions import Extension
from markdown.inlinepatterns import SimpleTagPattern
from markdown.inlinepatterns import SimpleTagInlineProcessor

# match ~, at least one character that is not ~, and ~ again
SUBSCRIPT_RE = r"(\~)([^\~]+)\2"
SUBSCRIPT_RE = r"()\~(.*?)\~"


def makeExtension(*args, **kwargs): # noqa: N802
def makeExtension(*args, **kwargs):
"""Inform Markdown of the existence of the extension."""
return SubscriptExtension(*args, **kwargs)


class SubscriptExtension(Extension):
"""Extension: text between ~ characters will be subscripted."""

def extendMarkdown(self, md, md_globals): # noqa: N802
def extendMarkdown(self, md):
"""Insert 'subscript' pattern before 'not_strong' pattern."""
md.inlinePatterns.add(
"subscript", SimpleTagPattern(SUBSCRIPT_RE, "sub"), "<not_strong"
)
md.inlinePatterns.register(SimpleTagInlineProcessor(SUBSCRIPT_RE, "sub"), "subscript", 75)
16 changes: 6 additions & 10 deletions doxpp/markdown/mdx_superscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,25 @@
2<sup>10</sup> is 1024.
:website: https://github.com/jambonrose/markdown_superscript_extension
:copyright: Copyright 2014-2018 Andrew Pinkham
:copyright: Copyright 2014-2018 Andrew Pinkham, Copyright 2022 Cris Luengo
:license: Simplified BSD, see LICENSE for details.
"""

from markdown.extensions import Extension
from markdown.inlinepatterns import SimpleTagPattern
from markdown.inlinepatterns import SimpleTagInlineProcessor

# match ^, at least one character that is not ^, and ^ again
SUPERSCRIPT_RE = r"(\^)([^\^]+)\2"
SUPERSCRIPT_RE = r"()\^(.*?)\^"


def makeExtension(*args, **kwargs): # noqa: N802
def makeExtension(*args, **kwargs):
"""Inform Markdown of the existence of the extension."""
return SuperscriptExtension(*args, **kwargs)


class SuperscriptExtension(Extension):
"""Extension: text between ^ characters will be superscripted."""

def extendMarkdown(self, md, md_globals): # noqa: N802
def extendMarkdown(self, md):
"""Insert 'superscript' pattern before 'not_strong' pattern."""
md.inlinePatterns.add(
"superscript",
SimpleTagPattern(SUPERSCRIPT_RE, "sup"),
"<not_strong",
)
md.inlinePatterns.register(SimpleTagInlineProcessor(SUPERSCRIPT_RE, "sup"), "superscript", 74)

0 comments on commit bfafe54

Please sign in to comment.