Skip to content

Commit

Permalink
fix: Render child elements in the xref element
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kesara committed Sep 27, 2023
1 parent b6bdd70 commit c886139
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion tests/input/elements.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@
<li>
Text and format="default": Sections
<xref target="RFC7997" format="default" sectionFormat="bare" section="3.2">Person Names</xref> and
<xref target="RFC7997" format="default" sectionFormat="bare" section="3.3">Company Names</xref> of
<xref target="RFC7997" format="default" sectionFormat="bare" section="3.3">Company Names</xref> and
<xref target="RFC7997" format="default" sectionFormat="bare" section="3.3">a <em>lot</em> <strong>other</strong> information</xref> of
<xref target="RFC7997" format="default"/>.

</li>
Expand Down
30 changes: 23 additions & 7 deletions xml2rfc/writers/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a class='relref'> HTML tag, with contents of
Expand All @@ -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'),
']',
)
Expand All @@ -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'),
Expand Down Expand Up @@ -2974,7 +2983,10 @@ def render_xref(self, h, x):
# 2.3</a>) 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'),
Expand Down Expand Up @@ -3003,9 +3015,13 @@ def render_xref(self, h, x):
# 2.3</a> 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
Expand Down

0 comments on commit c886139

Please sign in to comment.