lib/asciidoctor/nist/converter.rb in metanorma-nist-0.0.4 vs lib/asciidoctor/nist/converter.rb in metanorma-nist-0.0.5
- old
+ new
@@ -16,13 +16,10 @@
nil
end
def example(node)
return pseudocode_example(node) if node.attr("style") == "pseudocode"
- return recommendation(node) if node.attr("style") == "recommendation"
- return requirement(node) if node.attr("style") == "requirement"
- return permission(node) if node.attr("style") == "permission"
super
end
def pseudocode_example(node)
noko do |xml|
@@ -32,34 +29,10 @@
wrap_in_para(node, ex)
end
end.join("\n")
end
- def recommendation(node)
- noko do |xml|
- xml.recommendation **id_attr(node) do |ex|
- wrap_in_para(node, ex)
- end
- end.join("\n")
- end
-
- def requirement(node)
- noko do |xml|
- xml.requirement **id_attr(node) do |ex|
- wrap_in_para(node, ex)
- end
- end.join("\n")
- end
-
- def permission(node)
- noko do |xml|
- xml.permission **id_attr(node) do |ex|
- wrap_in_para(node, ex)
- end
- end.join("\n")
- end
-
def table(node)
return errata(node) if node.attr("style") == "errata"
super
end
@@ -130,19 +103,28 @@
nistvariable_insert(n)))
end
end
end
+ # skip annex/terms/terms, which is empty node
+ def termdef_subclause_cleanup(xmldoc)
+ xmldoc.xpath("//terms[terms]").each do |t|
+ next if t.parent.name == "terms"
+ t.children.each { |n| n.parent = t.parent }
+ t.remove
+ end
+ end
+
def makexml(node)
result = ["<?xml version='1.0' encoding='UTF-8'?>\n<nist-standard>"]
@draft = node.attributes.has_key?("draft")
result << noko { |ixml| front node, ixml }
result << noko { |ixml| middle node, ixml }
result << "</nist-standard>"
result = textcleanup(result)
ret1 = cleanup(Nokogiri::XML(result))
- validate(ret1)
+ validate(ret1) unless @novalid
ret1.root.add_namespace(nil, EXAMPLE_NAMESPACE)
ret1
end
def doctype(node)
@@ -158,10 +140,11 @@
def init(node)
@callforpatentclaims = node.attr("call-for-patent-claims")
@commitmenttolicence = node.attr("commitment-to-licence")
@patentcontact = node.attr("patent-contact")
+ @biblioasappendix = node.attr("biblio-as-appendix")
super
end
def document(node)
init(node)
@@ -199,12 +182,13 @@
preface.add_child foreword.remove if foreword
introduction = x.at("//introduction")
preface.add_child introduction.remove if introduction
x.xpath("//clause[@preface]").each do |c|
c.delete("preface")
- c.name = "reviewernote" if c&.at("./title")&.text.downcase == "note to reviewers"
- c.name = "executivesummary" if c&.at("./title")&.text.downcase == "executive summary"
+ title = c&.at("./title")&.text.downcase
+ c.name = "reviewernote" if title == "note to reviewers"
+ c.name = "executivesummary" if title == "executive summary"
preface.add_child c.remove
end
callforpatentclaims(x, preface)
end
@@ -216,11 +200,11 @@
<ol><li><p>assurance in the form of a general disclaimer to the effect that such party does not hold and does not currently intend holding any essential patent claim(s); or</p></li>
<li><p>assurance that a license to such essential patent claim(s) will be made available to applicants desiring to utilize the license for the purpose of complying with the guidance or requirements in this ITL draft publication either:</p>
- <ol><li><p>under reasonable terms and conditions that are demonstrably free of any unfair discrimination; or</p></li>
+ <ol><li><p>under reasonable terms and conditions that are demonstrably free of any unfair discrimination; or</p></li>
<li><p>without compensation and under reasonable terms and conditions that are demonstrably free of any unfair discrimination.</p></li></ol>
</li></ol>
<p>Such assurance shall indicate that the patent holder (or third party authorized to make assurances on its behalf) will include in any documents transferring ownership of patents subject to the assurance, provisions sufficient to ensure that the commitments in the assurance are binding on the transferee, and that the transferee will similarly include appropriate provisions in the event of future transfers with the goal of binding each successor-in-interest.</p>
@@ -251,12 +235,12 @@
def callforpatentclaims(x, preface)
if @callforpatentclaims
docemail = x&.at("//uri[@type = 'email']")&.text || "???"
docnumber = x&.at("//docnumber")&.text || "???"
- status = x&.at("//bibdata/status")&.text
- published = status.nil? || status == "published"
+ status = x&.at("//bibdata/status/stage")&.text
+ published = status.nil? || status == "final"
preface.add_child patent_text(published, docemail, docnumber)
end
end
def patent_text(published, docemail, docnumber)
@@ -309,12 +293,21 @@
def section(node)
a = { id: Asciidoctor::Standoc::Utils::anchor_or_uuid(node) }
noko do |xml|
case sectiontype(node)
when "normative references" then norm_ref_parse(a, xml, node)
+ when "glossary", "terminology"
+ if node.attr("style") == "appendix" && node.level == 1
+ @term_def = true
+ terms_annex_parse(a, xml, node)
+ @term_def = false
+ else
+ clause_parse(a, xml, node)
+ end
else
- if @term_def then term_def_subclause_parse(a, xml, node)
+ if @term_def
+ term_def_subclause_parse(a, xml, node)
elsif @biblio then bibliography_parse(a, xml, node)
elsif node.attr("style") == "bibliography"
bibliography_parse(a, xml, node)
elsif node.attr("style") == "abstract"
abstract_parse(a, xml, node)
@@ -325,18 +318,59 @@
end
end
end.join("\n")
end
+ def bibliography_parse(a, xml, node)
+ @biblioasappendix and node.level == 1 and
+ return bibliography_annex_parse(a, xml, node)
+ super
+ end
+
+ def bibliography_annex_parse(attrs, xml, node)
+ attrs1 = attrs.merge(id: "_" + UUIDTools::UUID.random_create)
+ xml.annex **attr_code(attrs1) do |xml_section|
+ xml_section.title { |t| t << "Bibliography" }
+ @biblio = true
+ xml.references **attr_code(attrs) do |xml_section|
+ xml_section << node.content
+ end
+ end
+ @biblio = false
+ end
+
+ def terms_annex_parse(attrs, xml, node)
+ attrs1 = attrs.merge(id: "_" + UUIDTools::UUID.random_create)
+ xml.annex **attr_code(attrs1) do |xml_section|
+ xml_section.title { |name| name << node.title }
+ xml_section.terms **attr_code(attrs) do |terms|
+ (s = node.attr("source")) && s.split(/,/).each do |s1|
+ terms.termdocsource(nil, **attr_code(bibitemid: s1))
+ end
+ terms << node.content
+ end
+ end
+ end
+
+ SECTIONS_TO_VALIDATE = "//references[not(parent::clause)]/title | "\
+ "//clause[descendant::references][not(parent::clause)]/title".freeze
+
def section_validate(doc)
super
- f = doc.xpath("//references[not(parent::clause)]/title | //clause[descendant::references][not(parent::clause)]/title")
+ f = doc.xpath(SECTIONS_TO_VALIDATE)
names = f.map { |s| s&.text }
return if names.empty?
return if names == ["References"]
return if names == ["Bibliography"]
return if names == ["References", "Bibliography"]
- warn "Reference clauses #{names.join(', ')} do not follow expected pattern in NIST"
+ warn "Reference clauses #{names.join(', ')} do not follow expected "\
+ "pattern in NIST"
+ end
+
+ def sections_order_cleanup(x)
+ s = x.at("//sections")
+ make_preface(x, s)
+ x.xpath("//sections/annex").reverse_each { |r| s.next = r.remove }
end
def html_converter(node)
IsoDoc::NIST::HtmlConvert.new(html_extract_attributes(node))
end