Skip to content

Commit

Permalink
🐛 FIX: linkify link rendering (#499)
Browse files Browse the repository at this point in the history
Linkify links should always be treated as external links,
and the child text should be rendered (rather than using the href)
  • Loading branch information
chrisjsewell authored Jan 9, 2022
1 parent 574b525 commit c90be9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions myst_parser/docutils_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def render_link(self, token: SyntaxTreeNode) -> None:
or any scheme if `myst_url_schemes` is None.
- Otherwise, forward to `render_internal_link`
"""
if token.markup == "autolink":
if token.info == "auto": # handles both autolink and linkify
return self.render_autolink(token)

if self.md_config.all_links_external:
Expand Down Expand Up @@ -733,10 +733,12 @@ def render_internal_link(self, token: SyntaxTreeNode) -> None:
self.render_children(token)

def render_autolink(self, token: SyntaxTreeNode) -> None:
refuri = target = escapeHtml(token.attrGet("href") or "") # type: ignore[arg-type]
ref_node = nodes.reference(target, target, refuri=refuri)
refuri = escapeHtml(token.attrGet("href") or "") # type: ignore[arg-type]
ref_node = nodes.reference()
ref_node["refuri"] = refuri
self.add_line_and_source_path(ref_node, token)
self.current_node.append(ref_node)
with self.current_node_context(ref_node, append=True):
self.render_children(token)

def render_html_inline(self, token: SyntaxTreeNode) -> None:
self.render_html_block(token)
Expand Down
10 changes: 10 additions & 0 deletions tests/test_renderers/fixtures/myst-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,13 @@ title: "The title *nested syntax*"
<title>
Other header
.

[linkify] --myst-enable-extensions=linkify
.
www.example.com
.
<document source="<string>">
<paragraph>
<reference refuri="http://www.example.com">
www.example.com
.

0 comments on commit c90be9a

Please sign in to comment.