Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

author-date referencing of non-standards/websites in normative refere… #405

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/html2doc/ieee/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def list2para1(list, level, type)
l["class"] ||= list_style(type, level, "Middle")
next unless l&.first_element_child&.name == "p"

l["style"] += (l.first_element_child["style"]&.sub(/mso-list[^;]+;/, "") || "")
l["style"] +=
l.first_element_child["style"]&.sub(/mso-list[^;]+;/, "") || ""
l.first_element_child.replace(l.first_element_child.children)
end
list.replace(list.children)
Expand Down
11 changes: 1 addition & 10 deletions lib/isodoc/ieee/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ def initialize(lang, script, i18n, fonts_options = {})
logos
end

def logos
here = File.join(File.dirname(__FILE__), "html")
%i(wp_image001_emz wp_image003_emz wp_image008_emz)
.each do |w|
img = w.to_s.sub("_emz", ".emz")
set(w, File.expand_path(File.join(here, img)))
end
end

def logos
here = File.join(File.dirname(__FILE__), "html")
suffix = ".emz"
Expand All @@ -33,7 +24,7 @@ def logos

def bibdate(isoxml, _out)
isoxml.xpath(ns("//bibdata/date[@format = 'ddMMMyyyy']")).each do |d|
set("#{d['type'].gsub('-', '_')}date".to_sym, Common::date_range(d))
set("#{d['type'].tr('-', '_')}date".to_sym, Common::date_range(d))
end
draft = isoxml.at(ns("//bibdata/date[@type = 'issued']")) ||
isoxml.at(ns("//bibdata/date[@type = 'circulated']")) ||
Expand Down
25 changes: 23 additions & 2 deletions lib/isodoc/ieee/presentation_ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,36 @@ def references_render(docxml)
super
end

KEEP_BIBRENDER_XPATH =
"./docidentifier | ./uri | ./note | ./title | ./biblio-tag".freeze

def bibrender_relaton(xml, renderings)
f = renderings[xml["id"]][:formattedref]
fn = availability_note(xml)
f &&= "<formattedref>#{f}#{fn}</formattedref>"
keep = "./docidentifier | ./uri | ./note | ./title | ./biblio-tag"
xml.children = "#{f}#{xml.xpath(ns(keep)).to_xml}"
xml.children = "#{f}#{xml.xpath(ns(KEEP_BIBRENDER_XPATH)).to_xml}"
author_date(xml, renderings)
@author[xml["id"]] = renderings[xml["id"]][:author]
end

def author_date(xml, renderings)
author_date?(xml) or return
cit = renderings[xml["id"]][:citation]
xml << "<docidentifier type='metanorma'>#{cit}</docidentifier>"
xml.at(ns("./biblio-tag"))&.remove
xml << "<biblio-tag>#{cit}, </biblio-tag>"
end

def author_date?(xml)
ret = !xml["type"]
ret ||= %w(standard techreport website webresource)
.include?(xml["type"])
ret ||= xml.at(".//ancestor::xmlns:references[@normative = 'false']")
ret ||= xml.at(ns("./docidentifier[@type = 'metanorma']"))
ret and return false
true
end

def creatornames(bibitem)
::Relaton::Render::IEEE::General
.new(language: @lang, i18nhash: @i18n.get,
Expand Down
4 changes: 2 additions & 2 deletions lib/isodoc/ieee/presentation_terms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def term_related_reorder(coll)
ins = coll.first.previous_element
ret = sort_related(coll)
coll.each(&:remove)
ret.reverse.each { |t| ins.next = t }
ret.reverse_each { |t| ins.next = t }
ins.parent.xpath(ns("./related"))
end

Expand Down Expand Up @@ -144,7 +144,7 @@ def term_reorder1(terms)
coll = terms.xpath(ns("./term"))
ret = sort_terms(coll)
coll.each(&:remove)
ret.reverse.each { |t| ins.next = t }
ret.reverse_each { |t| ins.next = t }
end

def sort_terms(terms)
Expand Down
8 changes: 6 additions & 2 deletions lib/isodoc/ieee/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,17 @@ def anchor_linkend1(node)
capitalise_xref(node, linkend, anchor_value(node["target"]))
end

def eref_locality_populate(type, node, number)
type == "page" and return ""
super
end

def block_delim
"&#x2014;"
end

def note1(elem)
return if elem.parent.name == "bibitem" || elem["notag"] == "true"

elem.parent.name == "bibitem" || elem["notag"] == "true" and return
n = @xrefs.get[elem["id"]]
lbl = if n.nil? || n[:label].nil? || n[:label].empty? then @i18n.note
else l10n("#{@i18n.note} #{n[:label]}")
Expand Down
77 changes: 72 additions & 5 deletions spec/isodoc/refs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@
</iso-standard>
INPUT

# <xref type="inline" target="ref2">https://doi.org/10.1017/9781108877831</xref>
# <!-- known issue: with no other identifier supplied (as a normative reference), DOI is still last resort, citeas no longer overwrites that -->

presxml = <<~PRESXML
<iso-standard xmlns="http://riboseinc.com/isoxml" type="presentation">
<preface> <clause type="toc" id="_" displayorder="1"> <title depth="1">Contents</title> </clause> </preface>
Expand All @@ -265,7 +262,7 @@
<p id="_">
<xref type="inline" target="ref1"><span class="std_publisher">ISO </span><span class="std_docNumber">639</span>:<span class="std_year">1967</span></xref>
<xref type="inline" target="ref7"><span class="std_publisher">ISO </span><span class="std_docNumber">639-2</span>:<span class="std_year">1998</span></xref>
<xref type="inline" target="ref2">https://doi.org/10.1017/9781108877831</xref>
<xref type="inline" target="ref2">Aluffi, Anderson, Hering, Mustaţă and Payne 2022a</xref>
<xref type="inline" target="ref3">REF4</xref>
<xref type="inline" target="ref4">ISO 639:1967 [B3]</xref>
<xref type="inline" target="ref5">Aluffi, Anderson, Hering, Mustaţă and Payne [B2]</xref>
Expand Down Expand Up @@ -321,7 +318,8 @@
<p id="_">IEEE 194-1977 has been withdrawn; however, copies can be obtained from Global Engineering, 15 Inverness Way East, Englewood, CO 80112-5704, USA, tel. (303) 792-2181 (http://global.ihs.com/).
</p>
</note>
<biblio-tag/>
<docidentifier type="metanorma">Aluffi, Anderson, Hering, Mustaţă and Payne 2022a</docidentifier>
<biblio-tag>Aluffi, Anderson, Hering, Mustaţă and Payne 2022a, </biblio-tag>
</bibitem>
<bibitem type="standard" id="ref1">
<formattedref>Indiana Jones and the Last Crusade.</formattedref>
Expand Down Expand Up @@ -520,4 +518,73 @@
expect(Xml::C14n.format(strip_guid(out.to_xml)))
.to be_equivalent_to Xml::C14n.format(presxml)
end

it "removes page locality" do
input = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
<sections>
<clause id='A' inline-header='false' obligation='normative'>
<title>Clause</title>
<p id='_'>
<eref type='inline' bibitemid='IETF_6281' citeas='ISO 639:1967'>
<localityStack><locality type="page"><referenceFrom>4</referenceFrom><referenceTo>9</referenceTo></locality></localityStack>
</eref>
<eref type='inline' bibitemid='IETF_6281' citeas='ISO 639:1967'>
<localityStack><locality type="figure"><referenceFrom>4</referenceFrom><referenceTo>9</referenceTo></locality></localityStack>
</eref>
<eref type='inline' bibitemid='Johns' citeas='ISO 639-2:1998'>
<localityStack><locality type="page"><referenceFrom>4</referenceFrom><referenceTo>9</referenceTo></locality></localityStack>
</eref>
<eref type='inline' bibitemid='Johns' citeas='ISO 639-2:1998'>
<localityStack><locality type="figure"><referenceFrom>4</referenceFrom><referenceTo>9</referenceTo></locality></localityStack>
</eref>
</p>
</clause>
</sections>
<bibliography>
<references id='_' normative='true' obligation='informative'>
<title>Normative References</title>
<bibitem id="IETF_6281" type="standard" schema-version="v1.2.1">
<title>Title 1</title>
<docidentifier>IETF 6281</docidentifier>
</bibitem>
<bibitem id="Johns" type="book" schema-version="v1.2.1">
<title>Title 1</title>
<docidentifier type="metanorma">Johns 2022</docidentifier>
</bibitem>
</references>
</bibliography>
</iso-standard>
INPUT
presxml = <<~PRESXML
<clause id="A" inline-header="false" obligation="normative" displayorder="4">
<title depth="1">
2.
<tab/>
Clause
</title>
<p id="_">
<xref type="inline" target="IETF_6281">
<span class="std_publisher">IETF </span>
<span class="std_docNumber">6281</span>
, 4–9
</xref>
<xref type="inline" target="IETF_6281">
<span class="std_publisher">IETF </span>
<span class="std_docNumber">6281</span>
, Figure 4–9
</xref>
<xref type="inline" target="Johns">Johns 2022, 4–9</xref>
<xref type="inline" target="Johns">Johns 2022, Figure 4–9</xref>
</p>
</clause>
PRESXML
out = Nokogiri::XML(
IsoDoc::IEEE::PresentationXMLConvert.new(presxml_options)
.convert("test", input, true),
)
out = out.at("//xmlns:clause[@id = 'A']")
expect(Xml::C14n.format(strip_guid(out.to_xml)))
.to be_equivalent_to Xml::C14n.format(presxml)
end
end
39 changes: 25 additions & 14 deletions spec/isodoc/terms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,14 @@

expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(presxml)
expect(Xml::C14n.format(Nokogiri::XML(IsoDoc::IEEE::HtmlConvert.new({})
.convert("test", presxml, true))
.at("//body").to_xml)).to be_equivalent_to Xml::C14n.format(html)
expect(Xml::C14n.format(Nokogiri::XML(IsoDoc::IEEE::WordConvert.new({})
.convert("test", presxml, true))
.at("//body").to_xml)).to be_equivalent_to Xml::C14n.format(word)
.at("//body").to_xml)).to be_equivalent_to Xml::C14n.format(word)
end

it "sorts terms" do
Expand Down Expand Up @@ -417,7 +418,8 @@
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(output)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(output)
end

it "processes IsoXML term with multiple paragraph definitions" do
Expand Down Expand Up @@ -478,7 +480,8 @@
PRESXML
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(presxml)
end

it "processes IsoXML term with multiple definitions" do
Expand Down Expand Up @@ -564,7 +567,8 @@
PRESXML
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(presxml)

input = <<~INPUT
<iso-standard xmlns="http://riboseinc.com/isoxml">
Expand Down Expand Up @@ -652,7 +656,8 @@
PRESXML
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(presxml)
end

it "processes IsoXML term with multiple preferred or preferred and admitted terms" do
Expand Down Expand Up @@ -801,7 +806,8 @@
PRESXML
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(presxml)
end

it "processes IsoXML term with grammatical information" do
Expand Down Expand Up @@ -870,7 +876,8 @@
PRESXML
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(presxml)
end

it "processes IsoXML term with empty or graphical designations" do
Expand Down Expand Up @@ -919,7 +926,8 @@
PRESXML
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(presxml)
end

it "processes IsoXML term with nonverbal definitions" do
Expand Down Expand Up @@ -1031,8 +1039,9 @@
</iso-standard>
PRESXML
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml)
.new(presxml_options)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(presxml)
end

it "processes related terms and admitted terms" do
Expand Down Expand Up @@ -1147,7 +1156,8 @@
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(output)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(output)
end

it "processes missing related terms" do
Expand Down Expand Up @@ -1218,7 +1228,8 @@
</iso-standard>
OUTPUT
expect(Xml::C14n.format(strip_guid(IsoDoc::IEEE::PresentationXMLConvert
.new(presxml_options)
.convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(output)
.new(presxml_options)
.convert("test", input, true))))
.to be_equivalent_to Xml::C14n.format(output)
end
end
Loading