From 384399cae4a52fbb689abacfdf1a55c3217276db Mon Sep 17 00:00:00 2001 From: Kesara Rathnayake Date: Tue, 10 May 2022 10:08:19 +1200 Subject: [PATCH] fix: Display ASCII names for authors in references (#771) Display ASCII names for authors in references with non-Latin characters in their names. --- tests/input/elements.xml | 14 ++++++++ tests/valid/draft-v3-features.text | 15 +++++---- tests/valid/elements.bom.text | 54 +++++++++++++++--------------- tests/valid/elements.pages.text | 54 +++++++++++++++--------------- tests/valid/elements.prepped.xml | 25 +++++++++++++- tests/valid/elements.text | 7 +++- tests/valid/elements.v3.py36.html | 6 +++- tests/valid/elements.v3.py37.html | 6 +++- tests/valid/elements.v3.py38.html | 6 +++- tests/valid/elements.wip.text | 54 +++++++++++++++--------------- xml2rfc/writers/text.py | 40 ++++++++++------------ 11 files changed, 165 insertions(+), 116 deletions(-) diff --git a/tests/input/elements.xml b/tests/input/elements.xml index 57067391f..b8da3cb3d 100644 --- a/tests/input/elements.xml +++ b/tests/input/elements.xml @@ -1332,6 +1332,20 @@ for opt, value in opts: + + + Lots of authors + + + Example Org. + + + This is a fun document. + + + + + diff --git a/tests/valid/draft-v3-features.text b/tests/valid/draft-v3-features.text index edb0135f5..30699dcc3 100644 --- a/tests/valid/draft-v3-features.text +++ b/tests/valid/draft-v3-features.text @@ -1392,13 +1392,14 @@ Table of Contents - [STPETER] ᏚᎢᎵᎬᎢᎬᏒ Inc., "ᏚᎢᎵᎬᎢᎬᏒ's document". A document where the - author element specifies just an organization, and both - title and organization name have an ASCII equivalent. - - [SVG11] Ferraiolo, J., 藤沢, 淳, and D. Jackson, "Scalable Vector - Graphics (SVG) 1.1 Specification", W3C Recommendation REC- - SVG11-20030114, January 14, 2003, + [STPETER] ᏚᎢᎵᎬᎢᎬᏒ Inc. (STPETER Inc.), "ᏚᎢᎵᎬᎢᎬᏒ's document". A + document where the author element specifies just an + organization, and both title and organization name have an + ASCII equivalent. + + [SVG11] Ferraiolo, J., 藤沢, 淳 (Fujisawa, J.), and D. Jackson, + "Scalable Vector Graphics (SVG) 1.1 Specification", W3C + Recommendation REC-SVG11-20030114, January 14, 2003, . Latest version available at http://www.w3.org/TR/SVG11/. diff --git a/tests/valid/elements.bom.text b/tests/valid/elements.bom.text index 9febb5bef..8127f41e3 100644 --- a/tests/valid/elements.bom.text +++ b/tests/valid/elements.bom.text @@ -1391,8 +1391,8 @@ MIME-SPEC References Other References - [DATE-RANGE] - Moe, J., "Document with date range", 2002-2003. + + @@ -1402,6 +1402,14 @@ Author, et al. Expires 13 January 2019 [Page 25] Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 + [AUTHORS] Πυθαγόρας ὁ Σάμιος (Samos, P. O.), Doe, J., Bergström, A., + and J. Doe, "Lots of authors", RFC 7539, + DOI 10.17487/RFC7539, May 2015, + . + + [DATE-RANGE] + Moe, J., "Document with date range", 2002-2003. + [FUZZY-DATE] Mae, J., "Document with fuzzy date", Second quarter 2010. @@ -1410,7 +1418,7 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 [NO-DATE] Mae, N., "Document — with no date", Advances in Cryptology - AACC Edition pp. 235-265. - [REPUBLIC] Πλάτων, "Πολιτεία", 375 BC. + [REPUBLIC] Πλάτων (Plato), "Πολιτεία", 375 BC. [RFC0952] Harrenstien, K., Stahl, M., and E. Feinler, "DoD Internet host table specification", RFC 952, DOI 10.17487/RFC0952, @@ -1441,6 +1449,15 @@ A.1. Contributors Additional contact information: + + + + +Author, et al. Expires 13 January 2019 [Page 26] + +Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 + + רוני אבן וואווי דוד המלך 14 @@ -1451,13 +1468,6 @@ A.1. Contributors Reviews and helpful comments have also been received from ანა კიკაბიძე (Ana Kikabidze). - - -Author, et al. Expires 13 January 2019 [Page 26] - -Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 - - A.2. Arbitrary^superscript in section _title_ Arbitrary text @@ -1497,6 +1507,13 @@ Authors' Addresses Additional contact information: + + +Author, et al. Expires 13 January 2019 [Page 27] + +Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 + + 田中花子 様 日本 〒112-0001 @@ -1505,15 +1522,6 @@ Authors' Addresses 3階B号室 - - - - -Author, et al. Expires 13 January 2019 [Page 27] - -Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 - - No Org Tokyo 112-0001 @@ -1548,14 +1556,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 - - - - - - - - diff --git a/tests/valid/elements.pages.text b/tests/valid/elements.pages.text index b31680f0b..f9da68b5b 100644 --- a/tests/valid/elements.pages.text +++ b/tests/valid/elements.pages.text @@ -1391,8 +1391,8 @@ MIME-SPEC References Other References - [DATE-RANGE] - Moe, J., "Document with date range", 2002-2003. + + @@ -1402,6 +1402,14 @@ Author, et al. Expires January 13, 2019 [Page 25] Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 + [AUTHORS] Πυθαγόρας ὁ Σάμιος (Samos, P. O.), Doe, J., Bergström, A., + and J. Doe, "Lots of authors", RFC 7539, + DOI 10.17487/RFC7539, May 2015, + . + + [DATE-RANGE] + Moe, J., "Document with date range", 2002-2003. + [FUZZY-DATE] Mae, J., "Document with fuzzy date", Second quarter 2010. @@ -1410,7 +1418,7 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 [NO-DATE] Mae, N., "Document — with no date", Advances in Cryptology - AACC Edition pp. 235-265. - [REPUBLIC] Πλάτων, "Πολιτεία", 375 BC. + [REPUBLIC] Πλάτων (Plato), "Πολιτεία", 375 BC. [RFC0952] Harrenstien, K., Stahl, M., and E. Feinler, "DoD Internet host table specification", RFC 952, DOI 10.17487/RFC0952, @@ -1441,6 +1449,15 @@ A.1. Contributors Additional contact information: + + + + +Author, et al. Expires January 13, 2019 [Page 26] + +Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 + + רוני אבן וואווי דוד המלך 14 @@ -1451,13 +1468,6 @@ A.1. Contributors Reviews and helpful comments have also been received from ანა კიკაბიძე (Ana Kikabidze). - - -Author, et al. Expires January 13, 2019 [Page 26] - -Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 - - A.2. Arbitrary^superscript in section _title_ Arbitrary text @@ -1497,6 +1507,13 @@ Authors' Addresses Additional contact information: + + +Author, et al. Expires January 13, 2019 [Page 27] + +Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 + + 田中花子 様 日本 〒112-0001 @@ -1505,15 +1522,6 @@ Authors' Addresses 3階B号室 - - - - -Author, et al. Expires January 13, 2019 [Page 27] - -Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 - - No Org Tokyo 112-0001 @@ -1548,14 +1556,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 - - - - - - - - diff --git a/tests/valid/elements.prepped.xml b/tests/valid/elements.prepped.xml index 3d230bf57..7f59bda97 100644 --- a/tests/valid/elements.prepped.xml +++ b/tests/valid/elements.prepped.xml @@ -1,5 +1,5 @@ - + @@ -1704,6 +1704,29 @@ for opt, value in opts: Other References + + + Lots of authors + + + + + + + + Example Org. + + + + + + + This is a fun document. + + + + + Document with date range diff --git a/tests/valid/elements.text b/tests/valid/elements.text index ff62977aa..547de0125 100644 --- a/tests/valid/elements.text +++ b/tests/valid/elements.text @@ -1141,6 +1141,11 @@ MIME-SPEC References Other References + [AUTHORS] Πυθαγόρας ὁ Σάμιος (Samos, P. O.), Doe, J., Bergström, A., + and J. Doe, "Lots of authors", RFC 7539, + DOI 10.17487/RFC7539, May 2015, + . + [DATE-RANGE] Moe, J., "Document with date range", 2002-2003. @@ -1152,7 +1157,7 @@ Other References [NO-DATE] Mae, N., "Document — with no date", Advances in Cryptology - AACC Edition pp. 235-265. - [REPUBLIC] Πλάτων, "Πολιτεία", 375 BC. + [REPUBLIC] Πλάτων (Plato), "Πολιτεία", 375 BC. [RFC0952] Harrenstien, K., Stahl, M., and E. Feinler, "DoD Internet host table specification", RFC 952, DOI 10.17487/RFC0952, diff --git a/tests/valid/elements.v3.py36.html b/tests/valid/elements.v3.py36.html index c325dfd12..9a0dccc14 100644 --- a/tests/valid/elements.v3.py36.html +++ b/tests/valid/elements.v3.py36.html @@ -15,7 +15,7 @@ - + @@ -1733,6 +1733,10 @@

Other References

+
[AUTHORS]
+
+Πυθαγόρας ὁ Σάμιος (Samos, P. O.), Doe, J., Bergström, A., and J. Doe, "Lots of authors", RFC 7539, DOI 10.17487/RFC7539, , <https://www.rfc-editor.org/rfc/rfc7539>.
+
[DATE-RANGE]
Moe, J., "Document with date range", 2002-2003.
diff --git a/tests/valid/elements.v3.py37.html b/tests/valid/elements.v3.py37.html index c325dfd12..9a0dccc14 100644 --- a/tests/valid/elements.v3.py37.html +++ b/tests/valid/elements.v3.py37.html @@ -15,7 +15,7 @@ - + @@ -1733,6 +1733,10 @@

Other References

+
[AUTHORS]
+
+Πυθαγόρας ὁ Σάμιος (Samos, P. O.), Doe, J., Bergström, A., and J. Doe, "Lots of authors", RFC 7539, DOI 10.17487/RFC7539, , <https://www.rfc-editor.org/rfc/rfc7539>.
+
[DATE-RANGE]
Moe, J., "Document with date range", 2002-2003.
diff --git a/tests/valid/elements.v3.py38.html b/tests/valid/elements.v3.py38.html index c325dfd12..9a0dccc14 100644 --- a/tests/valid/elements.v3.py38.html +++ b/tests/valid/elements.v3.py38.html @@ -15,7 +15,7 @@ - + @@ -1733,6 +1733,10 @@

Other References

+
[AUTHORS]
+
+Πυθαγόρας ὁ Σάμιος (Samos, P. O.), Doe, J., Bergström, A., and J. Doe, "Lots of authors", RFC 7539, DOI 10.17487/RFC7539, , <https://www.rfc-editor.org/rfc/rfc7539>.
+
[DATE-RANGE]
Moe, J., "Document with date range", 2002-2003.
diff --git a/tests/valid/elements.wip.text b/tests/valid/elements.wip.text index bfbcf976f..e08b072bb 100644 --- a/tests/valid/elements.wip.text +++ b/tests/valid/elements.wip.text @@ -1391,8 +1391,8 @@ MIME-SPEC References Other References - [DATE-RANGE] - Moe, J., "Document with date range", 2002-2003. + + @@ -1402,6 +1402,14 @@ Author, et al. Expires 13 January 2019 [Page 25] Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 + [AUTHORS] Πυθαγόρας ὁ Σάμιος (Samos, P. O.), Doe, J., Bergström, A., + and J. Doe, "Lots of authors", RFC 7539, + DOI 10.17487/RFC7539, May 2015, + . + + [DATE-RANGE] + Moe, J., "Document with date range", 2002-2003. + [FUZZY-DATE] Mae, J., "Document with fuzzy date", Second quarter 2010. @@ -1410,7 +1418,7 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 [NO-DATE] Mae, N., "Document — with no date", Advances in Cryptology - AACC Edition pp. 235-265. - [REPUBLIC] Πλάτων, "Πολιτεία", 375 BC. + [REPUBLIC] Πλάτων (Plato), "Πολιτεία", 375 BC. [RFC0952] Harrenstien, K., Stahl, M., and E. Feinler, "DoD Internet host table specification", RFC 952, DOI 10.17487/RFC0952, @@ -1441,6 +1449,15 @@ A.1. Contributors Additional contact information: + + + + +Author, et al. Expires 13 January 2019 [Page 26] + +Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 + + רוני אבן וואווי דוד המלך 14 @@ -1451,13 +1468,6 @@ A.1. Contributors Reviews and helpful comments have also been received from ანა კიკაბიძე (Ana Kikabidze). - - -Author, et al. Expires 13 January 2019 [Page 26] - -Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 - - A.2. Arbitrary^superscript in section _title_ Arbitrary text @@ -1497,6 +1507,13 @@ Authors' Addresses Additional contact information: + + +Author, et al. Expires 13 January 2019 [Page 27] + +Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 + + 田中花子 様 日本 〒112-0001 @@ -1505,15 +1522,6 @@ Authors' Addresses 3階B号室 - - - - -Author, et al. Expires 13 January 2019 [Page 27] - -Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 - - No Org Tokyo 112-0001 @@ -1548,14 +1556,6 @@ Internet-Draft Xml2rfc Vocabulary V3 Elements July 2018 - - - - - - - - diff --git a/xml2rfc/writers/text.py b/xml2rfc/writers/text.py index ff4428f68..1d8bfc4c8 100644 --- a/xml2rfc/writers/text.py +++ b/xml2rfc/writers/text.py @@ -28,8 +28,9 @@ from xml2rfc import utils from xml2rfc.uniscripts import is_script from xml2rfc.util.date import extract_date, augment_date, get_expiry_date, format_date -from xml2rfc.util.name import short_author_name, short_author_ascii_name, short_author_name_parts, short_org_name_set - +from xml2rfc.util.name import (short_author_name, short_author_ascii_name, + short_org_name_set, ref_author_name_first, + ref_author_name_last) from xml2rfc.util.name import full_author_name_set from xml2rfc.util.num import ol_style_formatter, num_width from xml2rfc.util.unicode import expand_unicode_element, textwidth @@ -1126,28 +1127,21 @@ def render_authors(self, e, width, **kwargs): for i, author in enumerate(authors): if i == len(authors) - 1 and len(authors) > 1: buf.append('and ') - organization = author.find('organization') - initials, surname = short_author_name_parts(author) - if surname: - initials = initials or '' - if i == len(authors) - 1 and len(authors) > 1: - # Last author is rendered in reverse - if len(initials) > 0: - buf.append(initials + ' ' + \ - surname) - else: - buf.append(surname) - elif len(initials) > 0: - buf.append(surname + ', ' + initials) - else: - buf.append(surname) - if author.attrib.get('role', '') == 'editor': - buf.append(', Ed.') - elif organization is not None and organization.text: - # Use organization instead of name - buf.append(organization.text.strip(stripspace)) + + if i == len(authors) - 1 and len(authors) > 1: + # Last author is rendered in reverse + name, ascii = ref_author_name_last(author) else: - continue + name, ascii = ref_author_name_first(author) + + if ascii: + buf.append('{name} ({ascii})'.format(name=name, ascii=ascii)) + elif name: + buf.append(name) + + if author.attrib.get('role', '') == 'editor': + buf.append(', Ed.') + if len(authors) == 2 and i == 0: buf.append(' ') elif i < len(authors) - 1: