Skip to content

Commit

Permalink
feat: Add classes to xref (#867)
Browse files Browse the repository at this point in the history
* chore: yestests

* feat: xref classes

`<xref ... format="none">` will be marked with `.xref.plain`.

Links to the references section (those in `[...]`) will be marked
`.xref.cite`.

* test: add tests for format="none"

I wanted to test that the new classes were added and that seems fine.

This revealed that format="none" is accepted for a link to the
contributors section, but that it adds a parenthetical where it should
not.  I'll open a bug on that separately.

* test: actually set format="none" on the element

* feat: add some classes to xref links

Documentation for this has been added to the top of the
render_xref function.

* tests: update expectations

* Remove stale text.
  • Loading branch information
martinthomson authored Sep 22, 2022
1 parent 055d64d commit 7fec225
Show file tree
Hide file tree
Showing 18 changed files with 1,121 additions and 1,085 deletions.
7 changes: 7 additions & 0 deletions tests/input/draft-v3-features.xml
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@
<t>(default, TEXTCONTENT) see <xref target="listitem">TEXTCONTENT</xref>.</t>
<t>(counter, TEXTCONTENT) see <xref target="listitem" format="counter">TEXTCONTENT</xref>.</t>
<t>(title, TEXTCONTENT) see <xref target="listitem" format="title">TEXTCONTENT</xref>.</t>
<t>(none, TEXTCONTENT) see <xref target="listitem" format="none">TEXTCONTENT</xref>.</t>
</section>
</section>
<section>
Expand Down Expand Up @@ -2621,6 +2622,9 @@ foo = bar
<t>
See <xref target="some.references">references below</xref>.
</t>
<t>
We might also link to <xref target="some.references" format="none">references below</xref> without perturbing text.
</t>
</section>
<section>
<name>To Unnumbered Section</name>
Expand All @@ -2630,6 +2634,9 @@ foo = bar
<t>
See <xref target="contributors">contributors below</xref>.
</t>
<t>
We might also link to <xref target="contributors" format="none">contributors</xref> without perturbing text.
</t>
</section>
</section>
</middle>
Expand Down
508 changes: 254 additions & 254 deletions tests/valid/docfile.html

Large diffs are not rendered by default.

182 changes: 91 additions & 91 deletions tests/valid/draft-miek-test.html

Large diffs are not rendered by default.

184 changes: 92 additions & 92 deletions tests/valid/draft-miek-test.v3.html

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions tests/valid/draft-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -1279,78 +1279,78 @@ <h2 id="name-copyright-notice-2">
</h2>
<nav class="toc"><ul class="compact toc ulBare ulEmpty">
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.1">
<p id="section-toc.1-1.1.1" class="keepWithNext"><a href="#section-1" class="xref">1</a>.  <a href="#name-introduction-2" class="xref">Introduction</a></p>
<p id="section-toc.1-1.1.1" class="keepWithNext"><a href="#section-1" class="auto internal xref">1</a>.  <a href="#name-introduction-2" class="internal xref">Introduction</a></p>
<ul class="compact toc ulBare ulEmpty">
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.1.2.1">
<p id="section-toc.1-1.1.2.1.1" class="keepWithNext"><a href="#section-1.1" class="xref">1.1</a>.  <a href="#name-requirements-language-2" class="xref">Requirements Language</a></p>
<p id="section-toc.1-1.1.2.1.1" class="keepWithNext"><a href="#section-1.1" class="auto internal xref">1.1</a>.  <a href="#name-requirements-language-2" class="internal xref">Requirements Language</a></p>
</li>
</ul>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.2">
<p id="section-toc.1-1.2.1" class="keepWithNext"><a href="#section-2" class="xref">2</a>.  <a href="#name-simple-list-2" class="xref">Simple List</a></p>
<p id="section-toc.1-1.2.1" class="keepWithNext"><a href="#section-2" class="auto internal xref">2</a>.  <a href="#name-simple-list-2" class="internal xref">Simple List</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.3">
<p id="section-toc.1-1.3.1"><a href="#section-3" class="xref">3</a>.  <a href="#name-figures-2" class="xref">Figures</a></p>
<p id="section-toc.1-1.3.1"><a href="#section-3" class="auto internal xref">3</a>.  <a href="#name-figures-2" class="internal xref">Figures</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.4">
<p id="section-toc.1-1.4.1"><a href="#section-4" class="xref">4</a>.  <a href="#name-subsections-and-tables-2" class="xref">Subsections and Tables</a></p>
<p id="section-toc.1-1.4.1"><a href="#section-4" class="auto internal xref">4</a>.  <a href="#name-subsections-and-tables-2" class="internal xref">Subsections and Tables</a></p>
<ul class="compact toc ulBare ulEmpty">
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.4.2.1">
<p id="section-toc.1-1.4.2.1.1"><a href="#section-4.1" class="xref">4.1</a>.  <a href="#name-a-subsection-2" class="xref">A Subsection</a></p>
<p id="section-toc.1-1.4.2.1.1"><a href="#section-4.1" class="auto internal xref">4.1</a>.  <a href="#name-a-subsection-2" class="internal xref">A Subsection</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.4.2.2">
<p id="section-toc.1-1.4.2.2.1"><a href="#section-4.2" class="xref">4.2</a>.  <a href="#name-tables-2" class="xref">Tables</a></p>
<p id="section-toc.1-1.4.2.2.1"><a href="#section-4.2" class="auto internal xref">4.2</a>.  <a href="#name-tables-2" class="internal xref">Tables</a></p>
</li>
</ul>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.5">
<p id="section-toc.1-1.5.1"><a href="#section-5" class="xref">5</a>.  <a href="#name-more-about-lists-2" class="xref">More about Lists</a></p>
<p id="section-toc.1-1.5.1"><a href="#section-5" class="auto internal xref">5</a>.  <a href="#name-more-about-lists-2" class="internal xref">More about Lists</a></p>
<ul class="compact toc ulBare ulEmpty">
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.5.2.1">
<p id="section-toc.1-1.5.2.1.1"><a href="#section-5.1" class="xref">5.1</a>.  <a href="#name-numbering-lists-across-lists" class="xref">Numbering Lists across Lists and Sections</a></p>
<p id="section-toc.1-1.5.2.1.1"><a href="#section-5.1" class="auto internal xref">5.1</a>.  <a href="#name-numbering-lists-across-lists" class="internal xref">Numbering Lists across Lists and Sections</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.5.2.2">
<p id="section-toc.1-1.5.2.2.1"><a href="#section-5.2" class="xref">5.2</a>.  <a href="#name-where-the-list-numbering-con" class="xref">Where the List Numbering Continues</a></p>
<p id="section-toc.1-1.5.2.2.1"><a href="#section-5.2" class="auto internal xref">5.2</a>.  <a href="#name-where-the-list-numbering-con" class="internal xref">Where the List Numbering Continues</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.5.2.3">
<p id="section-toc.1-1.5.2.3.1"><a href="#section-5.3" class="xref">5.3</a>.  <a href="#name-nested-lists-2" class="xref">nested lists</a></p>
<p id="section-toc.1-1.5.2.3.1"><a href="#section-5.3" class="auto internal xref">5.3</a>.  <a href="#name-nested-lists-2" class="internal xref">nested lists</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.5.2.4">
<p id="section-toc.1-1.5.2.4.1"><a href="#section-5.4" class="xref">5.4</a>.  <a href="#name-list-formats-2" class="xref">List Formats</a></p>
<p id="section-toc.1-1.5.2.4.1"><a href="#section-5.4" class="auto internal xref">5.4</a>.  <a href="#name-list-formats-2" class="internal xref">List Formats</a></p>
</li>
</ul>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.6">
<p id="section-toc.1-1.6.1"><a href="#section-6" class="xref">6</a>.  <a href="#name-example-of-code-or-mib-modul" class="xref">Example of Code or MIB Module To Be Extracted</a></p>
<p id="section-toc.1-1.6.1"><a href="#section-6" class="auto internal xref">6</a>.  <a href="#name-example-of-code-or-mib-modul" class="internal xref">Example of Code or MIB Module To Be Extracted</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.7">
<p id="section-toc.1-1.7.1"><a href="#section-7" class="xref">7</a>.  <a href="#name-acknowledgements-2" class="xref">Acknowledgements</a></p>
<p id="section-toc.1-1.7.1"><a href="#section-7" class="auto internal xref">7</a>.  <a href="#name-acknowledgements-2" class="internal xref">Acknowledgements</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.8">
<p id="section-toc.1-1.8.1"><a href="#section-8" class="xref">8</a>.  <a href="#name-iana-considerations-2" class="xref">IANA Considerations</a></p>
<p id="section-toc.1-1.8.1"><a href="#section-8" class="auto internal xref">8</a>.  <a href="#name-iana-considerations-2" class="internal xref">IANA Considerations</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.9">
<p id="section-toc.1-1.9.1"><a href="#section-9" class="xref">9</a>.  <a href="#name-security-considerations-2" class="xref">Security Considerations</a></p>
<p id="section-toc.1-1.9.1"><a href="#section-9" class="auto internal xref">9</a>.  <a href="#name-security-considerations-2" class="internal xref">Security Considerations</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.10">
<p id="section-toc.1-1.10.1"><a href="#section-10" class="xref">10</a><a href="#name-references-2" class="xref">References</a></p>
<p id="section-toc.1-1.10.1"><a href="#section-10" class="auto internal xref">10</a><a href="#name-references-2" class="internal xref">References</a></p>
<ul class="compact toc ulBare ulEmpty">
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.10.2.1">
<p id="section-toc.1-1.10.2.1.1"><a href="#section-10.1" class="xref">10.1</a>.  <a href="#name-normative-references-2" class="xref">Normative References</a></p>
<p id="section-toc.1-1.10.2.1.1"><a href="#section-10.1" class="auto internal xref">10.1</a>.  <a href="#name-normative-references-2" class="internal xref">Normative References</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.10.2.2">
<p id="section-toc.1-1.10.2.2.1"><a href="#section-10.2" class="xref">10.2</a>.  <a href="#name-informative-references-2" class="xref">Informative References</a></p>
<p id="section-toc.1-1.10.2.2.1"><a href="#section-10.2" class="auto internal xref">10.2</a>.  <a href="#name-informative-references-2" class="internal xref">Informative References</a></p>
</li>
</ul>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.11">
<p id="section-toc.1-1.11.1"><a href="#appendix-A" class="xref">Appendix A</a>.  <a href="#name-additional-stuff-2" class="xref">Additional Stuff</a></p>
<p id="section-toc.1-1.11.1"><a href="#appendix-A" class="auto internal xref">Appendix A</a>.  <a href="#name-additional-stuff-2" class="internal xref">Additional Stuff</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.12">
<p id="section-toc.1-1.12.1"><a href="#appendix-B" class="xref"></a><a href="#name-contributors-2" class="xref">Contributors</a></p>
<p id="section-toc.1-1.12.1"><a href="#appendix-B" class="auto internal xref"></a><a href="#name-contributors-2" class="internal xref">Contributors</a></p>
</li>
<li class="compact toc ulBare ulEmpty" id="section-toc.1-1.13">
<p id="section-toc.1-1.13.1"><a href="#appendix-C" class="xref"></a><a href="#name-authors-addresses-2" class="xref">Authors' Addresses</a></p>
<p id="section-toc.1-1.13.1"><a href="#appendix-C" class="auto internal xref"></a><a href="#name-authors-addresses-2" class="internal xref">Authors' Addresses</a></p>
</li>
</ul>
</nav>
Expand All @@ -1360,14 +1360,14 @@ <h2 id="name-copyright-notice-2">
<h2 id="name-introduction-2">
<a href="#section-1" class="section-number selfRef">1. </a><a href="#name-introduction-2" class="section-name selfRef">Introduction</a>
</h2>
<p id="section-1-1">The original specification of xml2rfc format is in <span><a href="#RFC2629" class="xref">RFC 2629</a> [<a href="#RFC2629" class="xref">RFC2629</a>]</span>.<a href="#section-1-1" class="pilcrow"></a></p>
<p id="section-1-1">The original specification of xml2rfc format is in <span><a href="#RFC2629" class="internal xref">RFC 2629</a> [<a href="#RFC2629" class="cite xref">RFC2629</a>]</span>.<a href="#section-1-1" class="pilcrow"></a></p>
<section id="section-1.1">
<h3 id="name-requirements-language-2">
<a href="#section-1.1" class="section-number selfRef">1.1. </a><a href="#name-requirements-language-2" class="section-name selfRef">Requirements Language</a>
</h3>
<p id="section-1.1-1">The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this
document are to be interpreted as described in <span><a href="#RFC2119" class="xref">RFC 2119</a> [<a href="#RFC2119" class="xref">RFC2119</a>]</span>.<a href="#section-1.1-1" class="pilcrow"></a></p>
document are to be interpreted as described in <span><a href="#RFC2119" class="internal xref">RFC 2119</a> [<a href="#RFC2119" class="cite xref">RFC2119</a>]</span>.<a href="#section-1.1-1" class="pilcrow"></a></p>
</section>
</section>
<div id="simple_list">
Expand Down Expand Up @@ -1406,7 +1406,7 @@ <h2 id="name-figures-2">
</div>
<figcaption><a href="#figure-1" class="selfRef">Figure 1</a></figcaption></figure>
</div>
<p id="section-3-4" class="keepWithPrevious">Cross-references allowed in pre- and postamble. <span>[<a href="#min_ref" class="xref">min_ref</a>]</span>.<a href="#section-3-4" class="pilcrow"></a></p>
<p id="section-3-4" class="keepWithPrevious">Cross-references allowed in pre- and postamble. <span>[<a href="#min_ref" class="cite xref">min_ref</a>]</span>.<a href="#section-3-4" class="pilcrow"></a></p>
<p id="section-3-5">The CDATA means you don't need to escape meta-characters (especially
&lt; (&amp;lt;) and &amp; (&amp;amp;)) but is not essential.
Figures may also have a title attribute but it won't be displayed unless
Expand Down Expand Up @@ -1948,8 +1948,8 @@ <h2 id="name-acknowledgements-2">
<p id="section-7-1">This template was derived from an initial version written by Pekka
Savola and contributed by him to the xml2rfc project.<a href="#section-7-1" class="pilcrow"></a></p>
<p id="section-7-2">
This document is part of a plan to make xml2rfc indispensable <span>[<a href="#DOMINATION" class="xref">DOMINATION</a>]</span>.
This document may be shared as needed <span>[<a href="#SHARING" class="xref">SHARING</a>]</span>. If necessary, appeal to <span>[<a href="#DOI_10.1145_2975159" class="xref">DOI_10.1145_2975159</a>]</span>.<a href="#section-7-2" class="pilcrow"></a></p>
This document is part of a plan to make xml2rfc indispensable <span>[<a href="#DOMINATION" class="cite xref">DOMINATION</a>]</span>.
This document may be shared as needed <span>[<a href="#SHARING" class="cite xref">SHARING</a>]</span>. If necessary, appeal to <span>[<a href="#DOI_10.1145_2975159" class="cite xref">DOI_10.1145_2975159</a>]</span>.<a href="#section-7-2" class="pilcrow"></a></p>
</section>
</div>
<div id="IANA">
Expand All @@ -1959,8 +1959,8 @@ <h2 id="name-iana-considerations-2">
</h2>
<p id="section-8-1">This memo includes no request to IANA.<a href="#section-8-1" class="pilcrow"></a></p>
<p id="section-8-2">All drafts are required to have an IANA considerations section (see
<span><a href="#I-D.narten-iana-considerations-rfc2434bis" class="xref">the update of
RFC 2434</a> [<a href="#I-D.narten-iana-considerations-rfc2434bis" class="xref">I-D.narten-iana-considerations-rfc2434bis</a>]</span> for a guide). If the draft does not require IANA to do
<span><a href="#I-D.narten-iana-considerations-rfc2434bis" class="internal xref">the update of
RFC 2434</a> [<a href="#I-D.narten-iana-considerations-rfc2434bis" class="cite xref">I-D.narten-iana-considerations-rfc2434bis</a>]</span> for a guide). If the draft does not require IANA to do
anything, the section contains an explicit statement that this is the
case (as above). If there are no requirements for IANA, the section will
be removed during conversion into an RFC by the RFC Editor.<a href="#section-8-2" class="pilcrow"></a></p>
Expand All @@ -1972,7 +1972,7 @@ <h2 id="name-security-considerations-2">
<a href="#section-9" class="section-number selfRef">9. </a><a href="#name-security-considerations-2" class="section-name selfRef">Security Considerations</a>
</h2>
<p id="section-9-1">All drafts are required to have a security considerations section.
See <span><a href="#RFC3552" class="xref">RFC 3552</a> [<a href="#RFC3552" class="xref">RFC3552</a>]</span> for a guide.<a href="#section-9-1" class="pilcrow"></a></p>
See <span><a href="#RFC3552" class="internal xref">RFC 3552</a> [<a href="#RFC3552" class="cite xref">RFC3552</a>]</span> for a guide.<a href="#section-9-1" class="pilcrow"></a></p>
</section>
</div>
<section id="section-10">
Expand Down
Loading

0 comments on commit 7fec225

Please sign in to comment.