Skip to content

Commit

Permalink
NBSP in SDO erefs: metanorma/metanorma-iso#882
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Jan 23, 2023
1 parent f3eb53d commit 992cbae
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 79 deletions.
10 changes: 5 additions & 5 deletions lib/isodoc/ietf/i18n-en.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
term_def_boilerplate:
no_terms_boilerplate:
internal_terms_boilerplate:
external_terms_boilerplate:
internal_external_terms_boilerplate:
term_def_boilerplate: ""
no_terms_boilerplate: ""
internal_terms_boilerplate: ""
external_terms_boilerplate: ""
internal_external_terms_boilerplate: ""
31 changes: 14 additions & 17 deletions lib/isodoc/ietf/references.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def bibliography(isoxml, out)
isoxml.xpath(ns("//references/bibitem/docidentifier")).each do |i|
i.children = docid_prefix(i["type"], i.text)
end
isoxml.xpath(ns("//bibliography/references | "\
"//bibliography/clause[.//references] | "\
"//annex/clause[.//references] | "\
"//annex/references | "\
isoxml.xpath(ns("//bibliography/references | " \
"//bibliography/clause[.//references] | " \
"//annex/clause[.//references] | " \
"//annex/references | " \
"//sections/clause[.//references]")).each do |f|
bibliography1(f, out)
end
Expand Down Expand Up @@ -64,15 +64,15 @@ def docidentifier_render(bib, out)
!id[:sdo].nil? && id[:sdo] != "(NO ID)" and out.refcontent id[:sdo]
docidentifiers&.each do |u|
u["type"] == "DOI" and
out.seriesInfo nil, **attr_code(value: u.text.sub(/^DOI /, ""),
out.seriesInfo nil, **attr_code(value: u.text.sub(/^DOI[  ]/, ""),
name: "DOI")
%w(IETF RFC).include?(u["type"]) and docidentifier_ietf(u, out)
end
end

def docidentifier_ietf(ident, out)
if /^RFC /.match?(ident.text)
out.seriesInfo nil, **attr_code(value: ident.text.sub(/^RFC 0*/, ""),
if /^RFC[  ]/.match?(ident.text)
out.seriesInfo nil, **attr_code(value: ident.text.sub(/^RFC[  ]0*/, ""),
name: "RFC")
elsif /^I-D\./.match?(ident.text)
out.seriesInfo nil, **attr_code(value: ident.text.sub(/^I-D\./, ""),
Expand All @@ -99,25 +99,23 @@ def relaton_to_title(bib, node)
end

def relaton_to_author(bib, node)
auths = bib.xpath(ns("./contributor[xmlns:role/@type = 'author' or "\
auths = bib.xpath(ns("./contributor[xmlns:role/@type = 'author' or " \
"xmlns:role/@type = 'editor']"))
auths.empty? and
auths = bib.xpath(ns("./contributor[xmlns:role/@type = "\
auths = bib.xpath(ns("./contributor[xmlns:role/@type = " \
"'publisher']"))
auths.each do |a|
role = a.at(ns("./role[@type = 'editor']")) ? "editor" : nil
p = a&.at(ns("./person/name")) and
relaton_person_to_author(p, role, node) or
(p = a&.at(ns("./person/name")) and
relaton_person_to_author(p, role, node)) or
relaton_org_to_author(a&.at(ns("./organization")), role, node)
end
end

def relaton_person_to_author(pers, role, node)
full = pers&.at(ns("./completename"))&.text
surname = pers&.at(ns("./surname"))&.text
initials = pers&.xpath(ns("./initial"))&.map do |i|
i.text
end&.join(" ") ||
initials = pers&.xpath(ns("./initial"))&.map(&:text)&.join(" ") ||
pers&.xpath(ns("./forename"))&.map { |i| i.text[0] }&.join(" ")
initials = nil if initials.empty?
node.author nil, **attr_code(
Expand All @@ -143,9 +141,8 @@ def relaton_to_date(bib, node)
date = bib.at(ns("./date[@type = 'published']")) ||
bib.at(ns("./date[@type = 'issued']")) ||
bib.at(ns("./date[@type = 'circulated']"))
return unless date

attr = date_attr(date&.at(ns("./on | ./from"))&.text) || return
date or return
attr = date_attr(date.at(ns("./on | ./from"))&.text) or return
node.date **attr_code(attr)
end

Expand Down
64 changes: 33 additions & 31 deletions lib/isodoc/ietf/table.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
module IsoDoc::Ietf
class RfcConvert < ::IsoDoc::Convert
def table_attrs(node)
attr_code(anchor: node["id"], align: node["align"])
end
module IsoDoc
module Ietf
class RfcConvert < ::IsoDoc::Convert
def table_attrs(node)
attr_code(anchor: node["id"], align: node["align"])
end

def table_parse(node, out)
@in_table = true
out.table **table_attrs(node) do |t|
table_title_parse(node, out)
thead_parse(node, t)
tbody_parse(node, t)
tfoot_parse(node, t)
def table_parse(node, out)
@in_table = true
out.table **table_attrs(node) do |t|
table_title_parse(node, out)
thead_parse(node, t)
tbody_parse(node, t)
tfoot_parse(node, t)
end
(dl = node.at(ns("./dl"))) && parse(dl, out)
node.xpath(ns("./note")).each { |n| parse(n, out) }
@in_table = false
end
(dl = node.at(ns("./dl"))) && parse(dl, out)
node.xpath(ns("./note")).each { |n| parse(n, out) }
@in_table = false
end

def table_title_parse(node, out)
name = node.at(ns("./name")) || return
out.name do |p|
name.children.each { |n| parse(n, p) }
def table_title_parse(node, out)
name = node.at(ns("./name")) || return
out.name do |p|
name.children.each { |n| parse(n, p) }
end
end
end

def tr_parse(node, out, ord, totalrows, header)
out.tr do |r|
node.elements.each do |td|
attrs = make_tr_attr(td, ord, totalrows - 1, header)
r.send td.name, **attrs do |entry|
td.children.each { |n| parse(n, entry) }
def tr_parse(node, out, ord, totalrows, header)
out.tr do |r|
node.elements.each do |td|
attrs = make_tr_attr(td, ord, totalrows - 1, header)
r.send td.name, **attrs do |entry|
td.children.each { |n| parse(n, entry) }
end
end
end
end
end

def make_tr_attr(td, row, totalrows, header)
attr_code(rowspan: td["rowspan"], colspan: td["colspan"],
align: td["align"] )
def make_tr_attr(cell, _row, _totalrows, _header)
attr_code(rowspan: cell["rowspan"], colspan: cell["colspan"],
align: cell["align"])
end
end
end
end
2 changes: 1 addition & 1 deletion lib/metanorma/ietf/biblio.rng
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@
<value>commentaryOf</value>
<value>hasCommentary</value>
<value>related</value>
<value>complements</value>
<value>hasComplement</value>
<value>complementOf</value>
<value>obsoletes</value>
<value>obsoletedBy</value>
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/ietf/isodoc.rng
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@
</element>
</define>
<define name="misccontainer">
<element name="misc-container">
<element name="metanorma-extension">
<oneOrMore>
<ref name="AnyElement"/>
</oneOrMore>
Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/ietf/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Metanorma
module Ietf
VERSION = "3.1.1".freeze
VERSION = "3.1.2".freeze
end
end
6 changes: 3 additions & 3 deletions spec/isodoc/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@
<organization abbrev='ISO'/>
</author>
</front>
<refcontent>ISO 712</refcontent>
<refcontent>ISO&#xa0;712</refcontent>
</reference>
</references>
</back>
Expand Down Expand Up @@ -505,7 +505,7 @@
<organization abbrev='ISO'/>
</author>
</front>
<refcontent>ISO 712</refcontent>
<refcontent>ISO&#xa0;712</refcontent>
</reference>
</references>
</back>
Expand Down Expand Up @@ -746,7 +746,7 @@
<organization ascii='International Organization for Standardization'>International Organization for Standardization</organization>
</author>
</front>
<refcontent>ISO 712</refcontent>
<refcontent>ISO&#xa0;712</refcontent>
</reference>
</references>
</back>
Expand Down
34 changes: 20 additions & 14 deletions spec/isodoc/ref_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe IsoDoc::Ietf do
it "processes IsoXML bibliographies" do
expect(xmlpp(IsoDoc::Ietf::RfcConvert.new({}).convert("test", <<~"INPUT", true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
input = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
<bibdata>
</bibdata>
Expand Down Expand Up @@ -150,6 +150,7 @@
</bibliography>
</iso-standard>
INPUT
output = <<~OUTPUT
#{XML_HDR}
<t anchor='_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f'>
<relref target='ISO712' section='' relative=''/>
Expand All @@ -174,7 +175,7 @@
</author>
</front>
<format target='http://www.example.com'/>
<refcontent>ISO 712</refcontent>
<refcontent>ISO&#xa0;712</refcontent>
</reference>
<reference anchor='ISO16634'>
<front>
Expand Down Expand Up @@ -208,7 +209,7 @@
<t>This is an abstract</t>
</abstract>
</front>
<refcontent>ISO 20483:2013-2014</refcontent>
<refcontent>ISO&#xa0;20483:2013-2014</refcontent>
</reference>
<reference anchor='ref1'>
<front>
Expand All @@ -224,7 +225,7 @@
)
</title>
</front>
<refcontent>ICC 167</refcontent>
<refcontent>ICC&#xa0;167</refcontent>
</reference>
<aside>
<t>NOTE: This is an annotation of ISO 20483:2013-2014</t>
Expand Down Expand Up @@ -261,7 +262,7 @@
<organization ascii='International Standards Organization' abbrev='ISO'>International Standards Organization</organization>
</author>
</front>
<refcontent>ISO 3696</refcontent>
<refcontent>ISO&#xa0;3696</refcontent>
</reference>
<reference anchor='ref10'>
<front>
Expand All @@ -283,7 +284,7 @@
<title>Internet Calendaring and Scheduling Core Object Specification (iCalendar)</title>
</front>
<format target='https://xml2rfc.tools.ietf.org/10.xml' type='xml'/>
<refcontent>RFC 10</refcontent>
<refcontent>RFC&#xa0;10</refcontent>
<seriesInfo value='10' name='RFC'/>
</reference>
<reference anchor='ref12'>
Expand Down Expand Up @@ -311,10 +312,11 @@
</rfc>
OUTPUT
expect(xmlpp(IsoDoc::Ietf::RfcConvert.new({}).convert("test", input, true))).to be_equivalent_to xmlpp(output)
end

it "processes IsoXML bibliographies with xincludes" do
expect(xmlpp(IsoDoc::Ietf::RfcConvert.new({use_xinclude: "true"}).convert("test", <<~"INPUT", true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
input = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
<bibdata>
</bibdata>
Expand All @@ -334,7 +336,7 @@
<title format="text/plain">Cereals or cereal products</title>
<title type="main" format="text/plain">Cereals and cereal products</title>
<uri>http://www.example.com</uri>
<docidentifier type="ISO">ISO 712</docidentifier>
<docidentifier type="ISO">ISO&#xa0;712</docidentifier>
<contributor>
<role type="publisher"/>
<organization>
Expand Down Expand Up @@ -463,6 +465,7 @@
</bibliography>
</iso-standard>
INPUT
output = <<~OUTPUT
#{XML_HDR}
<t anchor='_f06fd0d1-a203-4f3d-a515-0bdba0f8d83f'>
<relref target='ISO712' section='' relative=''/>
Expand All @@ -487,7 +490,7 @@
</author>
</front>
<format target='http://www.example.com'/>
<refcontent>ISO 712</refcontent>
<refcontent>ISO&#xa0;712</refcontent>
</reference>
<reference anchor='ISO16634'>
<front>
Expand Down Expand Up @@ -521,7 +524,7 @@
<t>This is an abstract</t>
</abstract>
</front>
<refcontent>ISO 20483:2013-2014</refcontent>
<refcontent>ISO&#xa0;20483:2013-2014</refcontent>
</reference>
<reference anchor='ref1'>
<front>
Expand All @@ -537,7 +540,7 @@
)
</title>
</front>
<refcontent>ICC 167</refcontent>
<refcontent>ICC&#xa0;167</refcontent>
</reference>
<aside>
<t>NOTE: This is an annotation of ISO 20483:2013-2014</t>
Expand Down Expand Up @@ -574,7 +577,7 @@
<organization ascii='International Standards Organization' abbrev='ISO'>International Standards Organization</organization>
</author>
</front>
<refcontent>ISO 3696</refcontent>
<refcontent>ISO&#xa0;3696</refcontent>
</reference>
<reference anchor='ref10'>
<front>
Expand All @@ -596,7 +599,7 @@
<title>Internet Calendaring and Scheduling Core Object Specification (iCalendar)</title>
</front>
<format target='https://xml2rfc.tools.ietf.org/10.xml' type='xml'/>
<refcontent>RFC 10</refcontent>
<refcontent>RFC&#xa0;10</refcontent>
<seriesInfo value='10' name='RFC'/>
</reference>
<reference anchor='ref12'>
Expand All @@ -613,10 +616,11 @@
</rfc>
OUTPUT
expect(xmlpp(IsoDoc::Ietf::RfcConvert.new({use_xinclude: "true"}).convert("test", input, true))).to be_equivalent_to xmlpp(output)
end

it "processes nested bibliographies" do
expect(xmlpp(IsoDoc::Ietf::RfcConvert.new({}).convert("test", <<~"INPUT", true))).to be_equivalent_to xmlpp(<<~"OUTPUT")
input = <<~INPUT
<ietf-standard xmlns="http://riboseinc.com/isoxml">
<sections><clause id="_clause" inline-header="false" obligation="normative">
<title>Clause</title>
Expand Down Expand Up @@ -657,6 +661,7 @@
</references></clause></sections>
</ietf-standard>
INPUT
output = <<~OUTPUT
<?xml version='1.0'?>
<?rfc strict="yes"?>
<?rfc compact="yes"?>
Expand Down Expand Up @@ -721,6 +726,7 @@
</back>
</rfc>
OUTPUT
expect(xmlpp(IsoDoc::Ietf::RfcConvert.new({}).convert("test", input, true))).to be_equivalent_to xmlpp(output)
end

end
Loading

0 comments on commit 992cbae

Please sign in to comment.