Skip to content

Commit

Permalink
Merge pull request #3631 from AdamWill/gist-inlinepattern
Browse files Browse the repository at this point in the history
mdx_gist: inherit from InlineProcessor, work on Python 3.11 (#3630)
  • Loading branch information
Kwpolska committed Jun 21, 2022
2 parents 476e0c6 + 499a9ea commit 4fff5cd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions nikola/plugins/compile/markdown/mdx_gist.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@

try:
from markdown.extensions import Extension
from markdown.inlinepatterns import Pattern
from markdown.inlinepatterns import InlineProcessor
from markdown.util import AtomicString
from markdown.util import etree
except ImportError:
# No need to catch this, if you try to use this without Markdown,
# the markdown compiler will fail first
Extension = Pattern = object
Extension = InlineProcessor = object


LOGGER = get_logger('compile_markdown.mdx_gist')
Expand All @@ -112,12 +112,12 @@ def __init__(self, url, status_code):
status_code, url)


class GistPattern(Pattern):
class GistPattern(InlineProcessor):
"""InlinePattern for footnote markers in a document's body text."""

def __init__(self, pattern, configs):
"""Initialize the pattern."""
Pattern.__init__(self, pattern)
InlineProcessor.__init__(self, pattern)

def get_raw_gist_with_filename(self, gist_id, filename):
"""Get raw gist text for a filename."""
Expand All @@ -139,8 +139,9 @@ def get_raw_gist(self, gist_id):

return resp.text

def handleMatch(self, m):
def handleMatch(self, m, _):
"""Handle pattern match."""
# The third arg is "data", wider context around the match; we don't need it.
gist_id = m.group('gist_id')
gist_file = m.group('filename')

Expand Down Expand Up @@ -170,7 +171,7 @@ def handleMatch(self, m):
warning_comment = etree.Comment(' WARNING: {0} '.format(e.message))
noscript_elem.append(warning_comment)

return gist_elem
return (gist_elem, m.start(0), m.end(0))


class GistExtension(MarkdownExtension, Extension):
Expand Down

0 comments on commit 4fff5cd

Please sign in to comment.