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

Fix index out of bounds #8

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def run(self, parent: etree.Element, blocks: list[str]) -> bool:
# append MARK_PREVENT_RECURSION to tail of the block to prevent recursion, we don't use a handled
# flaglist because we don't know if there's some same block in the document
self.parser.parseBlocks(parent, [block + MARK_PREVENT_RECURSION])
# fix offset index out of range
if len(parent) == 0:
return True
# fix multi blocks in same parents
if self.meta["last_parent"] == parent[-1]:
parent[-1].set("data-original-document-end", str(end))
Expand Down
77 changes: 77 additions & 0 deletions python-markdown-extension/test/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import argparse
from argparse import FileType
import markdown

from pymdownx.emoji import to_svg
from pymdownx.slugs import uslugify
from pymdownx.arithmatex import fence_mathjax_format

parser = argparse.ArgumentParser("cli")
parser.add_argument(
"file", help="Markdown file to be rendered", type=FileType(encoding="utf-8")
)
args = parser.parse_args()

result = markdown.markdown(
args.file.read(),
extensions=[
"document-offsets-injection",
"admonition",
"def_list",
"footnotes",
"meta",
"toc",
"pymdownx.arithmatex",
"pymdownx.caret",
"pymdownx.critic",
"pymdownx.details",
"pymdownx.emoji",
"pymdownx.highlight",
"pymdownx.inlinehilite",
"pymdownx.keys",
"pymdownx.magiclink",
"pymdownx.mark",
"pymdownx.snippets",
"pymdownx.progressbar",
"pymdownx.smartsymbols",
"pymdownx.superfences",
"pymdownx.tasklist",
"pymdownx.tilde",
"pymdownx.tabbed",
],
extension_configs={
"toc": {
"permalink": "",
"slugify": uslugify,
},
"pymdownx.arithmatex": {
"generic": True,
},
"pymdownx.emoji": {
"emoji_generator": to_svg,
},
"pymdownx.highlight": {
"linenums": True,
},
"pymdownx.snippets": {
"check_paths": True,
},
"pymdownx.superfences": {
"custom_fences": [
{
"name": "math",
"class": "arithmatex",
"format": fence_mathjax_format,
},
],
},
"pymdownx.tasklist": {
"custom_checkbox": True,
},
"pymdownx.tabbed": {
"alternate_style": True,
},
},
)

print(result)