Skip to content

Commit

Permalink
Merge pull request #429 from lorenzo-rovigatti/master
Browse files Browse the repository at this point in the history
Make the myst plugin compatible with myst-parser > 0.17.2
  • Loading branch information
Kwpolska authored Jul 15, 2023
2 parents e53af93 + 660250a commit 31c67bb
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions v8/myst/myst.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@

try:
import myst_parser
import myst_parser.main

# this works for myst-parser versions <= 0.17.2
try:
from myst_parser.main import to_html
old_myst = True
except ImportError:
from docutils.core import publish_string
from myst_parser.docutils_ import Parser
old_myst = False
except ImportError:
myst_parser = None
nikola_extension = None
Expand Down Expand Up @@ -63,7 +71,35 @@ def compile_string(
if not is_two_file:
_, data = self.split_metadata(data, post, lang)
new_data, shortcodes = sc.extract_shortcodes(data)
output = myst_parser.main.to_html(new_data)

if old_myst:
output = to_html(new_data)
else:
output = publish_string(
source=new_data,
writer_name="html5",
settings_overrides={
"myst_enable_extensions":
[
"attrs_inline",
"colon_fence",
"deflist",
"fieldlist",
"html_admonition",
"html_image",
"linkify",
"smartquotes",
"strikethrough",
"substitution",
"tasklist",
],
"embed_stylesheet": True,
'output_encoding': 'unicode',
'myst_suppress_warnings': ["myst.header"],
'myst_heading_anchors': 4
},
parser=Parser(),
)
output, shortcode_deps = self.site.apply_shortcodes_uuid(
output, shortcodes, filename=source_path, extra_context={"post": post}
)
Expand Down

0 comments on commit 31c67bb

Please sign in to comment.