Repository: executablebooks/MyST-Parser
Pull request #666 (2023-01-06 02:14:08)

👌 Reference attributes title -> reftitle
Sphinx will output reftitle as the HTML title attr.
See: https://github.com/sphinx-doc/sphinx/blob/6e6b9ad45194177811551c77f5f4040213d1c661/sphinx/writers/html5.py#L227

codecov[bot]: # [Codecov](https://codecov.io/gh/executablebooks/MyST-Parser/pull/666?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) Report
Base: **89.94**% // Head: **89.94**% // No change to project coverage :thumbsup:
> Coverage data is based on head [(`025910b`)](https://codecov.io/gh/executablebooks/MyST-Parser/pull/666?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) compared to base [(`23ae135`)](https://codecov.io/gh/executablebooks/MyST-Parser/commit/23ae1350b0f3796cd51b9f5b129a85ec324352e2?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks).
> Patch coverage: 100.00% of modified lines in pull request are covered.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #666   +/-   ##
=======================================
  Coverage   89.94%   89.94%           
=======================================
  Files          23       23           
  Lines        2396     2396           
=======================================
  Hits         2155     2155           
  Misses        241      241           
```

| Flag | Coverage Δ | |
|---|---|---|
| pytests | `89.94% <100.00%> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/executablebooks/MyST-Parser/pull/666?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks) | Coverage Δ | |
|---|---|---|
| [myst\_parser/mdit\_to\_docutils/base.py](https://codecov.io/gh/executablebooks/MyST-Parser/pull/666?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks#diff-bXlzdF9wYXJzZXIvbWRpdF90b19kb2N1dGlscy9iYXNlLnB5) | `92.25% <100.00%> (ø)` | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/executablebooks/MyST-Parser/pull/666?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=executablebooks).


Patch:
diff --git a/docs/syntax/optional.md b/docs/syntax/optional.md
index 8e12e88..c10c740 100644
--- a/docs/syntax/optional.md
+++ b/docs/syntax/optional.md
@@ -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>`
@@ -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>`
diff --git a/myst_parser/mdit_to_docutils/base.py b/myst_parser/mdit_to_docutils/base.py
index 6b198ea..4e4d412 100644
--- a/myst_parser/mdit_to_docutils/base.py
+++ b/myst_parser/mdit_to_docutils/base.py
@@ -379,7 +379,14 @@ class DocutilsRenderer(RendererProtocol):
         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:
@@ -751,7 +758,9 @@ class DocutilsRenderer(RendererProtocol):
         """
         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)
@@ -769,7 +778,9 @@ class DocutilsRenderer(RendererProtocol):
         """
         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):
@@ -778,7 +789,9 @@ class DocutilsRenderer(RendererProtocol):
     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):


Test patch:
diff --git a/tests/test_renderers/fixtures/docutil_syntax_elements.md b/tests/test_renderers/fixtures/docutil_syntax_elements.md
index 9b59f3a..91123a5 100644
--- a/tests/test_renderers/fixtures/docutil_syntax_elements.md
+++ b/tests/test_renderers/fixtures/docutil_syntax_elements.md
@@ -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
 .
 
@@ -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
 .
 
diff --git a/tests/test_renderers/fixtures/sphinx_syntax_elements.md b/tests/test_renderers/fixtures/sphinx_syntax_elements.md
index 1ac085c..2d40bdb 100644
--- a/tests/test_renderers/fixtures/sphinx_syntax_elements.md
+++ b/tests/test_renderers/fixtures/sphinx_syntax_elements.md
@@ -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
 .
 
@@ -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
 .
 
diff --git a/tests/test_sphinx/test_sphinx_builds/test_basic.html b/tests/test_sphinx/test_sphinx_builds/test_basic.html
index 9813b70..b3e99c7 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_basic.html
+++ b/tests/test_sphinx/test_sphinx_builds/test_basic.html
@@ -229,7 +229,7 @@ paragraph
      </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>
diff --git a/tests/test_sphinx/test_sphinx_builds/test_basic.resolved.xml b/tests/test_sphinx/test_sphinx_builds/test_basic.resolved.xml
index 8a12765..18605dc 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_basic.resolved.xml
+++ b/tests/test_sphinx/test_sphinx_builds/test_basic.resolved.xml
@@ -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):
diff --git a/tests/test_sphinx/test_sphinx_builds/test_basic.xml b/tests/test_sphinx/test_sphinx_builds/test_basic.xml
index 34b0e3c..a3a1b65 100644
--- a/tests/test_sphinx/test_sphinx_builds/test_basic.xml
+++ b/tests/test_sphinx/test_sphinx_builds/test_basic.xml
@@ -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):