Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for newer version of the markdown dependency. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 8 additions & 8 deletions pelican_jsmath/jsmath_markdown_extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import markdown

from markdown.util import etree
import xml.etree.ElementTree as etree
from markdown.util import AtomicString


Expand All @@ -13,7 +13,7 @@ def __init__(self, tag, pattern):
self.tag = tag

def handleMatch(self, m):
node = markdown.util.etree.Element(self.tag)
node = etree.Element(self.tag)
node.set('class', self.math_tag_class)

prefix = '\\(' if m.group('prefix') == '$' else m.group('prefix')
Expand All @@ -40,7 +40,7 @@ def correct_html(self, root, children, div_math, insert_idx, text):
current_idx = 0

for idx in div_math:
el = markdown.util.etree.Element('p')
el = etree.Element('p')
el.text = text
el.extend(children[current_idx:idx])

Expand All @@ -55,7 +55,7 @@ def correct_html(self, root, children, div_math, insert_idx, text):
insert_idx += 1
current_idx = idx+1

el = markdown.util.etree.Element('p')
el = etree.Element('p')
el.text = text
el.extend(children[current_idx:])

Expand Down Expand Up @@ -90,12 +90,12 @@ class JsMathExtension(markdown.Extension):
def __init__(self):
super(JsMathExtension, self).__init__()

def extendMarkdown(self, md, md_globals):
def extendMarkdown(self, md):
inline_regex = r'(?P<prefix>\$)(?P<math>.+?)(?P<suffix>(?<!\s)\2)'
display_regex = r'(?P<prefix>\$\$|\\begin\{(.+?)\})(?P<math>.+?)(?P<suffix>\2|\\end\{\3\})'

md.inlinePatterns.add('jsmath_displayed', JsMathPattern('div', display_regex), '<escape')
md.inlinePatterns.add('jsmath_inlined', JsMathPattern('span', inline_regex), '<escape')
md.inlinePatterns.register(name='jsmath_displayed', item=JsMathPattern('div', display_regex), priority=19)
md.inlinePatterns.register(name='jsmath_inlined', item=JsMathPattern('span', inline_regex), priority=19)

# Correct the invalid HTML that results from the displayed math (<div> tag within a <p> tag)
md.treeprocessors.add('jsmath_correctdisplayedmath', JsMathCorrectDisplayMath(), '>inline')
md.treeprocessors.register(name='jsmath_correctdisplayedmath', item=JsMathCorrectDisplayMath(), priority=21)