Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hukkin committed Dec 12, 2024
1 parent dc4f7b5 commit 7679d91
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/mdformat_gfm/_mdformat_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def _postprocess_inline(text: str, node: RenderTreeNode, context: RenderContext)


def _gfm_autolink_renderer(node: RenderTreeNode, context: RenderContext) -> str:
return node.meta["source_autolink"]
return node.meta["source_text"]


def _escape_text(text: str, node: RenderTreeNode, context: RenderContext) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/mdformat_gfm/_mdit_gfm_autolink_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def push_tokens(
return
token = state.push("gfm_autolink_open", "a", 1)
token.attrs = {"href": full_url}
token.meta = {"source_autolink": source_url}
token.meta = {"source_text": source_url}

token = state.push("text", "", 0)
token.content = state.md.normalizeLinkText(source_url)
Expand Down
8 changes: 3 additions & 5 deletions src/mdformat_gfm/_text_inline_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from markdown_it.rules_inline import StateInline

GFM_WHITESPACE = frozenset(" \t\n\v\f\r")
BEFORE_VALID_AUTOLINK_CHARS = GFM_WHITESPACE | {"*", "_", "~", "("}
BEFORE_AUTOLINK_CHARS = GFM_WHITESPACE | {"*", "_", "~", "("}

# The default set of terminator characters
_TerminatorChars = {
Expand Down Expand Up @@ -46,9 +46,7 @@
_gfm_autolink_terminator = (
r"(?:" r"www\." "|" "http" "|" "mailto:" "|" "xmpp:" "|" r"[a-zA-Z0-9._+-]+@" r")"
)
_before_autolink_terminator = (
"[" + re.escape("".join(BEFORE_VALID_AUTOLINK_CHARS)) + "]"
)
_before_autolink = "[" + re.escape("".join(BEFORE_AUTOLINK_CHARS)) + "]"

_RE_TERMINATOR_FIRST_CHAR = re.compile(
_default_terminator + "|" + _gfm_autolink_terminator
Expand All @@ -57,7 +55,7 @@
r"(?s:.)" # match any character (also newline)
+ _default_terminator
+ "|"
+ _before_autolink_terminator
+ _before_autolink
+ _gfm_autolink_terminator
)

Expand Down

0 comments on commit 7679d91

Please sign in to comment.