Skip to content

Commit

Permalink
19/56
Browse files Browse the repository at this point in the history
  • Loading branch information
CrossNox committed Jul 29, 2024
1 parent 7eb852b commit 064498d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions m2r2/m2r2.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,25 +292,23 @@ def parse_rest_code_block(self, match: Match, state: State) -> Token:


class RestInlineParser(mistune.InlineParser):
IMAGE_LINK = re.compile(
r"\[!\[(?P<alt>.*?)\]\((?P<url>.*?)\).*?\]\((?P<target>.*?)\)"
)
REST_ROLE = re.compile(r":.*?:`.*?`|`[^`]+`:.*?:")
REST_LINK = re.compile(r"`[^`]*?`_")
INLINE_MATH = re.compile(r"`\$(.*?)\$`")
EOL_LITERAL_MARKER = re.compile(r"(\s+)?::\s*$")
IMAGE_LINK = r"\[!\[(?P<alt>.*?)\]\((?P<url>.*?)\).*?\]\((?P<target>.*?)\)"
REST_ROLE = r":.*?:`.*?`|`[^`]+`:.*?:"
REST_LINK = r"`[^`]*?`_"
INLINE_MATH = r"`\$(.*?)\$`"
EOL_LITERAL_MARKER = r"(\s+)?::\s*$"
# add colon and space as special text
TEXT = re.compile(r"^[\s\S]+?(?=[\\<!\[:_*`~ ]|https?://| {2,}\n|$)")
TEXT = r"^[\s\S]+?(?=[\\<!\[:_*`~ ]|https?://| {2,}\n|$)"
# __word__ or **word**
DOUBLE_EMPHASIS = re.compile(r"^([_*]){2}(?P<text>[\s\S]+?)\1{2}(?!\1)")
DOUBLE_EMPHASIS = r"^([_*]){2}(?P<text>[\s\S]+?)\1{2}(?!\1)"
# _word_ or *word*
EMPHASIS = re.compile(
EMPHASIS = (
r"^\b_((?:__|[^_])+?)_\b" # _word_
r"|"
r"^\*(?P<text>(?:\*\*|[^\*])+?)\*(?!\*)" # *word*
)

RUlE_NAMES = (
RULE_NAMES = (
"inline_math",
"image_link",
"rest_role",
Expand Down Expand Up @@ -366,10 +364,10 @@ def __init__(self, renderer, *args, **kwargs):
if disable_inline_math: # or getattr(options, "disable_inline_math", False):
if inline_maths:
self.RULE_NAMES = tuple(
x for x in self.RUlE_NAMES if x != "inline_math"
x for x in self.RULE_NAMES if x != "inline_math"
)
elif not inline_maths:
self.RUlE_NAMES = ("inline_math", *self.RUlE_NAMES)
self.RULE_NAMES = ("inline_math", *self.RULE_NAMES)


class M2R2(mistune.Markdown):
Expand Down

0 comments on commit 064498d

Please sign in to comment.