From 09a910ed06361a2c5a3249aeb1067abd433780d5 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Tue, 26 Sep 2023 18:38:34 +1300 Subject: [PATCH 1/3] fix: Render child elements in the xref element This change fixes a bug where child elements were not rendered in `xref` element with `section` attribute. This change only affects HTML & PDF outputs. Fixes #1034 --- tests/input/elements.xml | 3 ++- xml2rfc/writers/html.py | 30 +++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/tests/input/elements.xml b/tests/input/elements.xml index c066b9de..8834dbe9 100644 --- a/tests/input/elements.xml +++ b/tests/input/elements.xml @@ -181,7 +181,8 @@
  • Text and format="default": Sections Person Names and - Company Names of + Company Names and + a lot more information of .
  • diff --git a/xml2rfc/writers/html.py b/xml2rfc/writers/html.py index f9f9bff9..65f8c5d0 100644 --- a/xml2rfc/writers/html.py +++ b/xml2rfc/writers/html.py @@ -2888,7 +2888,9 @@ def render_xref(self, h, x): label = 'Section' if section[0].isdigit() else 'Appendix' if re.search(r'^[A-Z](\.|$)', section) else 'Part' link = x.get('derivedLink') format = x.get('sectionFormat') - exptext = ("%s " % x.text.strip()) if (x.text and x.text.strip()) else '' + exptext = f'{x.text.lstrip()}' if x.text else '' + expchildren = list(x.getchildren()) + separator = ' ' if exptext != '' or len(expchildren) > 0 else '' # 9.44.1. displayFormat='of' # # The output is an HTML tag, with contents of @@ -2912,7 +2914,11 @@ def render_xref(self, h, x): if format == 'of': span = add.span(h, None, build.a('%s %s'%(label, section), href=link, classes='relref'), - ' of %s[' % exptext, + ' of ', + exptext, + *expchildren, + separator, + '[', build.a(reftext, href='#%s'%target, classes='xref cite'), ']', ) @@ -2939,7 +2945,10 @@ def render_xref(self, h, x): # for an overview. elif format == 'comma': span = add.span(h, None, - '%s[' % exptext, + exptext, + *expchildren, + separator, + '[', build.a(reftext, href='#%s'%target, classes='xref cite'), '], ', build.a('%s %s'%(label, section), href=link, classes='relref'), @@ -2974,7 +2983,10 @@ def render_xref(self, h, x): # 2.3) for an overview. elif format == 'parens': span = add.span(h, None, - '%s[' % exptext, + exptext, + *expchildren, + separator, + '[', build.a(reftext, href='#%s'%target, classes='xref cite'), '] (', build.a('%s %s'%(label, section), href=link, classes='relref'), @@ -3003,9 +3015,13 @@ def render_xref(self, h, x): # 2.3 and ... elif format == 'bare': a = build.a(section, href=link, classes='relref') - if x.text and x.text.strip() and x.text.strip() != section: - aa = build.a(x.text, href=link, classes='relref') - hh = build.span(a, ' (', aa, ')') + if content: + hh = build.span( + a, + ' (', + build.a(exptext, *expchildren, href=link, classes='relref'), + ')', + ) else: hh = a hh.tail = x.tail From 38db1dca4e32a002469697b134ba447b2e5a72d0 Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Wed, 27 Sep 2023 15:29:39 +1300 Subject: [PATCH 2/3] chore: Run yestests --- tests/valid/docfile.html | 4 ++-- tests/valid/draft-miek-test.html | 2 +- tests/valid/draft-template.html | 2 +- tests/valid/indexes.pages.text | 16 ++++++++-------- tests/valid/indexes.prepped.xml | 6 +++--- tests/valid/indexes.text | 6 +++--- tests/valid/indexes.v3.html | 10 +++++----- tests/valid/manpage.txt | 2 +- tests/valid/rfc7911.html | 2 +- tests/valid/sourcecode.pages.text | 20 ++++++++++---------- tests/valid/sourcecode.prepped.xml | 6 +++--- tests/valid/sourcecode.text | 6 +++--- tests/valid/sourcecode.v3.html | 10 +++++----- 13 files changed, 46 insertions(+), 46 deletions(-) diff --git a/tests/valid/docfile.html b/tests/valid/docfile.html index 84e8f396..88ee49f7 100644 --- a/tests/valid/docfile.html +++ b/tests/valid/docfile.html @@ -24,7 +24,7 @@ Xml2rfc Vocabulary V3 Schema -August 2023 +September 2023 xml2rfc(1) @@ -39,7 +39,7 @@
    xml2rfc(1)
    Published:
    - +
    Author:
    diff --git a/tests/valid/draft-miek-test.html b/tests/valid/draft-miek-test.html index 359cf1f9..15b29508 100644 --- a/tests/valid/draft-miek-test.html +++ b/tests/valid/draft-miek-test.html @@ -33,7 +33,7 @@ intervaltree 3.1.0 Jinja2 3.1.2 lxml 4.9.3 - platformdirs 3.9.1 + platformdirs 3.10.0 pycountry 22.3.5 PyYAML 6.0.1 requests 2.31.0 diff --git a/tests/valid/draft-template.html b/tests/valid/draft-template.html index 080dd8f0..ef3c9ce7 100644 --- a/tests/valid/draft-template.html +++ b/tests/valid/draft-template.html @@ -22,7 +22,7 @@ intervaltree 3.1.0 Jinja2 3.1.2 lxml 4.9.3 - platformdirs 3.9.1 + platformdirs 3.10.0 pycountry 22.3.5 PyYAML 6.0.1 requests 2.31.0 diff --git a/tests/valid/indexes.pages.text b/tests/valid/indexes.pages.text index d5ae368a..e4316cc1 100644 --- a/tests/valid/indexes.pages.text +++ b/tests/valid/indexes.pages.text @@ -3,9 +3,9 @@ Network Working Group H. Person, Ed. -Internet-Draft August 30, 2023 +Internet-Draft September 27, 2023 Intended status: Experimental -Expires: March 2, 2024 +Expires: March 30, 2024 xml2rfc index tests @@ -26,7 +26,7 @@ Status of This Memo time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." - This Internet-Draft will expire on March 2, 2024. + This Internet-Draft will expire on March 30, 2024. Copyright Notice @@ -53,9 +53,9 @@ Table of Contents -Person Expires March 2, 2024 [Page 1] +Person Expires March 30, 2024 [Page 1] -Internet-Draft xml2rfc index tests August 2023 +Internet-Draft xml2rfc index tests September 2023 This is another section! @@ -109,9 +109,9 @@ Index -Person Expires March 2, 2024 [Page 2] +Person Expires March 30, 2024 [Page 2] -Internet-Draft xml2rfc index tests August 2023 +Internet-Draft xml2rfc index tests September 2023 E @@ -165,4 +165,4 @@ Author's Address -Person Expires March 2, 2024 [Page 3] +Person Expires March 30, 2024 [Page 3] diff --git a/tests/valid/indexes.prepped.xml b/tests/valid/indexes.prepped.xml index 8e9b9b28..2bcbb07f 100644 --- a/tests/valid/indexes.prepped.xml +++ b/tests/valid/indexes.prepped.xml @@ -1,5 +1,5 @@ - + @@ -20,7 +20,7 @@ - +
    Status of This Memo @@ -41,7 +41,7 @@ material or to cite them other than as "work in progress." - This Internet-Draft will expire on 2 March 2024. + This Internet-Draft will expire on 30 March 2024.
    diff --git a/tests/valid/indexes.text b/tests/valid/indexes.text index 9124f2f7..02ce692f 100644 --- a/tests/valid/indexes.text +++ b/tests/valid/indexes.text @@ -3,9 +3,9 @@ Network Working Group H. Person, Ed. -Internet-Draft August 30, 2023 +Internet-Draft September 27, 2023 Intended status: Experimental -Expires: March 2, 2024 +Expires: March 30, 2024 xml2rfc index tests @@ -26,7 +26,7 @@ Status of This Memo time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress." - This Internet-Draft will expire on March 2, 2024. + This Internet-Draft will expire on March 30, 2024. Copyright Notice diff --git a/tests/valid/indexes.v3.html b/tests/valid/indexes.v3.html index f01c4b89..2ec4646f 100644 --- a/tests/valid/indexes.v3.html +++ b/tests/valid/indexes.v3.html @@ -19,11 +19,11 @@ Internet-Draft xml2rfc index tests -August 2023 +September 2023 Person -Expires March 2, 2024 +Expires March 30, 2024 [Page] @@ -36,12 +36,12 @@
    indexes-00
    Published:
    - +
    Intended Status:
    Experimental
    Expires:
    -
    +
    Author:
    @@ -71,7 +71,7 @@

    time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

    - This Internet-Draft will expire on March 2, 2024.

    + This Internet-Draft will expire on March 30, 2024.