Skip to content

Commit

Permalink
馃憣 Reference attributes title -> reftitle (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Jan 6, 2023
1 parent 23ae135 commit 936cba7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/syntax/optional.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ For example, the following Markdown:
- `A literal with attributes`{#literalid .bg-warning},
{ref}`a reference to the literal <literalid>

- An autolink with attributes: <https://example.com>{.bg-warning}
- An autolink with attributes: <https://example.com>{.bg-warning title="a title"}

- [A link with attributes](syntax/attributes){#linkid .bg-warning},
{ref}`a reference to the link <linkid>`
Expand All @@ -778,7 +778,7 @@ will be parsed as:
- `A literal with attributes`{#literalid .bg-warning},
{ref}`a reference to the literal <literalid>`

- An autolink with attributes: <https://example.com>{.bg-warning}
- An autolink with attributes: <https://example.com>{.bg-warning title="a title"}

- [A link with attributes](syntax/attributes){#linkid .bg-warning},
{ref}`a reference to the link <linkid>`
Expand Down
21 changes: 17 additions & 4 deletions myst_parser/mdit_to_docutils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,14 @@ def copy_attributes(
converters: dict[str, Callable[[str], Any]] | None = None,
aliases: dict[str, str] | None = None,
) -> None:
"""Copy attributes on the token to the docutils node."""
"""Copy attributes on the token to the docutils node.
:param token: the token to copy attributes from
:param node: the node to copy attributes to
:param keys: the keys to copy from the token (after aliasing)
:param converters: a dictionary of converters for the attributes
:param aliases: a dictionary mapping the token key name to the node key name
"""
if converters is None:
converters = {}
if aliases is None:
Expand Down Expand Up @@ -751,7 +758,9 @@ def render_external_url(self, token: SyntaxTreeNode) -> None:
"""
ref_node = nodes.reference()
self.add_line_and_source_path(ref_node, token)
self.copy_attributes(token, ref_node, ("class", "id", "title"))
self.copy_attributes(
token, ref_node, ("class", "id", "reftitle"), aliases={"title": "reftitle"}
)
ref_node["refuri"] = cast(str, token.attrGet("href") or "")
with self.current_node_context(ref_node, append=True):
self.render_children(token)
Expand All @@ -769,7 +778,9 @@ def render_internal_link(self, token: SyntaxTreeNode) -> None:
"""
ref_node = nodes.reference()
self.add_line_and_source_path(ref_node, token)
self.copy_attributes(token, ref_node, ("class", "id", "title"))
self.copy_attributes(
token, ref_node, ("class", "id", "reftitle"), aliases={"title": "reftitle"}
)
ref_node["refname"] = cast(str, token.attrGet("href") or "")
self.document.note_refname(ref_node)
with self.current_node_context(ref_node, append=True):
Expand All @@ -778,7 +789,9 @@ def render_internal_link(self, token: SyntaxTreeNode) -> None:
def render_autolink(self, token: SyntaxTreeNode) -> None:
refuri = escapeHtml(token.attrGet("href") or "") # type: ignore[arg-type]
ref_node = nodes.reference()
self.copy_attributes(token, ref_node, ("class", "id"))
self.copy_attributes(
token, ref_node, ("class", "id", "reftitle"), aliases={"title": "reftitle"}
)
ref_node["refuri"] = refuri
self.add_line_and_source_path(ref_node, token)
with self.current_node_context(ref_node, append=True):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_renderers/fixtures/docutil_syntax_elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ Link Reference:
.
<document source="notset">
<paragraph>
<reference refuri="https://www.google.com" title="a title">
<reference reftitle="a title" refuri="https://www.google.com">
name
.

Expand All @@ -388,7 +388,7 @@ Link Reference short version:
.
<document source="notset">
<paragraph>
<reference refuri="https://www.google.com" title="a title">
<reference reftitle="a title" refuri="https://www.google.com">
name
.

Expand Down
4 changes: 2 additions & 2 deletions tests/test_renderers/fixtures/sphinx_syntax_elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ Link Reference:
.
<document source="<src>/index.md">
<paragraph>
<reference refuri="https://www.google.com" title="a title">
<reference reftitle="a title" refuri="https://www.google.com">
name
.

Expand All @@ -391,7 +391,7 @@ Link Reference short version:
.
<document source="<src>/index.md">
<paragraph>
<reference refuri="https://www.google.com" title="a title">
<reference reftitle="a title" refuri="https://www.google.com">
name
.

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sphinx/test_sphinx_builds/test_basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ <h1>
</a>
</p>
<p>
<a class="reference external" href="https://www.google.com">
<a class="reference external" href="https://www.google.com" title="a title">
name
</a>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
<comment classes="block_break" xml:space="preserve">
a block break
<paragraph>
<reference refuri="https://www.google.com" title="a title">
<reference reftitle="a title" refuri="https://www.google.com">
name
<literal_block language="default" linenos="False" xml:space="preserve">
def func(a, b=1):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sphinx/test_sphinx_builds/test_basic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
<comment classes="block_break" xml:space="preserve">
a block break
<paragraph>
<reference refuri="https://www.google.com" title="a title">
<reference reftitle="a title" refuri="https://www.google.com">
name
<literal_block language="default" xml:space="preserve">
def func(a, b=1):
Expand Down

0 comments on commit 936cba7

Please sign in to comment.