Skip to content

Commit

Permalink
Merge pull request #888 from metanorma/features/unnumbered-clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis authored Apr 16, 2024
2 parents 4c1848e + c04a23d commit 650946d
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 101 deletions.
24 changes: 12 additions & 12 deletions lib/metanorma/standoc/cleanup_section.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
require "date"
require "htmlentities"
require "json"
require_relative "cleanup_section_names"

module Metanorma
Expand Down Expand Up @@ -51,8 +48,9 @@ def make_abstract(xml, sect)

def clean_abstract(dupabstract)
dupabstract.traverse { |n| n.remove_attribute("id") }
dupabstract.remove_attribute("language")
dupabstract.remove_attribute("script")
%w(language script unnumbered).each do |w|
dupabstract.remove_attribute(w)
end
dupabstract.at("./title")&.remove
dupabstract
end
Expand Down Expand Up @@ -100,9 +98,9 @@ def make_annexes(xml)
y.name == "annex" || !y.ancestors("annex").empty? and next
y.wrap("<annex/>")
y.parent["id"] = "_#{UUIDTools::UUID.random_create}"
y.parent["obligation"] = y["obligation"]
y.parent["language"] = y["language"]
y.parent["script"] = y["script"]
%w(obligation language script).each do |w|
y.parent[w] = y[w]
end
end
end

Expand Down Expand Up @@ -195,7 +193,8 @@ def preface_clausebefore_cleanup(xmldoc)
def sections_clausebefore_cleanup(xmldoc)
xmldoc.at("//sections") or return
ins = insert_before(xmldoc, "//sections")
xmldoc.xpath("//sections//*[@beforeclauses = 'true']").reverse.each do |x|
xmldoc.xpath("//sections//*[@beforeclauses = 'true']")
.reverse.each do |x|
x.delete("beforeclauses")
ins.previous = x.remove
end
Expand All @@ -204,9 +203,10 @@ def sections_clausebefore_cleanup(xmldoc)

# only move clausebefore notes at the very end of preface
def endofpreface_clausebefore(xmldoc, ins)
xmldoc.xpath("//preface//*[@beforeclauses = 'true']").reverse.each do |x|
textafternote = xmldoc.xpath("//preface//*") & x.xpath("./following::*")
textafternote.text.strip.empty? or break
xmldoc.xpath("//preface//*[@beforeclauses = 'true']").reverse
.each do |x|
textafter = xmldoc.xpath("//preface//*") & x.xpath("./following::*")
textafter.text.strip.empty? or break
x.delete("beforeclauses")
ins.previous = x.remove
end
Expand Down
1 change: 1 addition & 0 deletions lib/metanorma/standoc/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def preface_main_filter(ret, node)
def section_attributes(node)
ret =
{ id: Metanorma::Utils::anchor_or_uuid(node),
unnumbered: node.option?("unnumbered") ? "true" : nil,
annex: role_style(node, "appendix") && node.level == 1 ? true : nil,
colophon: role_style(node, "colophon") ? true : nil,
preface: role_style(node, "preface") ? true : nil }
Expand Down
8 changes: 5 additions & 3 deletions spec/metanorma/blocks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
#{BLANK_HDR}
<sections>
<formula id="ABC" tag="X" columns="1" multilingual-rendering="common" number="3" keep-with-next="true" keep-lines-together="true" inequality="true">
<stem type="MathML" block="true">
Expand Down Expand Up @@ -179,7 +179,8 @@
<mstyle displaystyle="true">
<mi>M</mi>
<mo>=</mo>
<mfenced open="[" close="]">
<mrow>
<mo>[</mo>
<mtable>
<mtr>
<mtd>
Expand Down Expand Up @@ -300,7 +301,8 @@
</mtd>
</mtr>
</mtable>
</mfenced>
<mo>]</mo>
</mrow>
</mstyle>
</math>
<latexmath>M =
Expand Down
2 changes: 2 additions & 0 deletions spec/metanorma/cleanup_math_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="false">
<mstyle mathvariant="sans-serif">
<mrow>
<mstyle mathvariant="sans-serif">
<mi>cd</mi>
</mstyle>
</mrow>
</mstyle>
</mstyle>
</math>
Expand Down
189 changes: 103 additions & 86 deletions spec/metanorma/section_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -710,139 +710,156 @@
.to be_equivalent_to xmlpp(output)
end

it "processes sections with title and type attributes" do
it "processes sections with title, type, and unnumbered attributes" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
.Foreword
Text
[abstract]
[abstract%unnumbered]
== Περίληψη
Text
[heading=introduction]
[%unnumbered,heading=introduction]
== Εισαγωγή
[%unnumbered]
=== Introduction Subsection
[heading=acknowledgements]
[%unnumbered,heading=acknowledgements]
== Ευχαριστίες
[heading=normative references]
[%unnumbered,heading=normative references]
== Κανονιστικές Παραπομπές
[heading=terms and definitions]
[%unnumbered,heading=terms and definitions]
== Όροι και Ορισμοί
[%unnumbered]
=== Term1
[heading="terms, definitions, symbols and abbreviated terms"]
[%unnumbered,heading="terms, definitions, symbols and abbreviated terms"]
== Όροι, Ορισμοί, Σύμβολα και Συντομογραφίες
[%unnumbered]
=== Normal Terms
[%unnumbered]
==== Term2
[heading=symbols]
[%unnumbered,heading=symbols]
=== Σύμβολα και Συντομογραφίες
[heading=abbreviated terms]
[%unnumbered,heading=abbreviated terms]
== Σύμβολα και Συντομογραφίες
[type=ABC]
[%unnumbered,type=ABC]
== Clause 4
[type=DEF]
[%unnumbered,type=DEF]
=== Introduction
[%unnumbered]
=== Clause 4.2
[appendix]
[appendix%unnumbered]
== Annex
[%unnumbered]
=== Annex A.1
[heading=bibliography]
[%unnumbered,heading=bibliography]
== Βιβλιογραφία
[%unnumbered]
=== Bibliography Subsection
INPUT
output = <<~OUTPUT
#{BLANK_HDR.sub('<status>', '<abstract> <p>Text</p> </abstract><status>')}
<preface>
<abstract id='_'>
<title>Abstract</title>
<p id='_'>Text</p>
</abstract>
<foreword id='_' obligation='informative'>
<title>Foreword</title>
<p id='_'>Text</p>
</foreword>
<introduction id='_' obligation='informative'>
<title>Introduction</title>
<clause id='_' inline-header='false' obligation='informative'>
<title>Introduction Subsection</title>
</clause>
</introduction>
<acknowledgements id='_' obligation='informative'>
<title>Acknowledgements</title>
</acknowledgements>
</preface>
<sections>
<terms id='_' obligation='normative'>
<title>Terms and definitions</title>
<p id="_">For the purposes of this document, the following terms and definitions apply.</p>
<term id='term-Term1'>
<preferred><expression><name>Term1</name></expression></preferred>
</term>
</terms>
<clause id='_' obligation='normative'>
<title>Terms, definitions and symbols</title>
<p id='_'>For the purposes of this document, the following terms and definitions apply.</p>
<terms id='_' obligation='normative'>
<title>Normal Terms</title>
<term id='term-Term2'>
<preferred><expression><name>Term2</name></expression></preferred>
</term>
</terms>
<definitions id='_' obligation="normative" type="symbols">
<title>Symbols</title>
</definitions>
</clause>
<definitions id='_' obligation="normative" type="abbreviated_terms">
<title>Abbreviated terms</title>
</definitions>
<clause id='_' inline-header='false' obligation='normative' type="ABC">
<title>Clause 4</title>
<clause id='_' inline-header='false' obligation='normative' type="DEF">
<title>Introduction</title>
</clause>
<clause id='_' inline-header='false' obligation='normative'>
<title>Clause 4.2</title>
</clause>
</clause>
</sections>
<annex id='_' inline-header='false' obligation='normative'>
<title>Annex</title>
<clause id='_' inline-header='false' obligation='normative'>
<title>Annex A.1</title>
</clause>
</annex>
<bibliography>
<references id='_' obligation='informative' normative="true">
<title>Normative references</title>
<p id="_">There are no normative references in this document.</p>
</references>
<clause id='_' obligation='informative'>
<title>Bibliography</title>
<references id='_' obligation='informative' normative="false">
<title>Bibliography Subsection</title>
</references>
</clause>
</bibliography>
</standard-document>
#{BLANK_HDR.sub('<status>', '<abstract> <p>Text</p> </abstract><status>')}
<preface>
<abstract id="_" unnumbered="true">
<title>Abstract</title>
<p id="_">Text</p>
</abstract>
<foreword id="_" obligation="informative">
<title>Foreword</title>
<p id="_">Text</p>
</foreword>
<introduction id="_" unnumbered="true" obligation="informative">
<title>Introduction</title>
<clause id="_" unnumbered="true" inline-header="false" obligation="informative">
<title>Introduction Subsection</title>
</clause>
</introduction>
<acknowledgements id="_" unnumbered="true" obligation="informative">
<title>Acknowledgements</title>
</acknowledgements>
</preface>
<sections>
<terms id="_" unnumbered="true" obligation="normative">
<title>Terms and definitions</title>
<p id="_">For the purposes of this document,
the following terms and definitions apply.</p>
<term id="term-Term1" unnumbered="true">
<preferred>
<expression>
<name>Term1</name>
</expression>
</preferred>
</term>
</terms>
<clause id="_" unnumbered="true" obligation="normative">
<title>Terms, definitions and symbols</title>
<p id="_">For the purposes of this document,
the following terms and definitions apply.</p>
<terms id="_" unnumbered="true" obligation="normative">
<title>Normal Terms</title>
<term id="term-Term2" unnumbered="true">
<preferred>
<expression>
<name>Term2</name>
</expression>
</preferred>
</term>
</terms>
<definitions id="_" unnumbered="true" type="symbols" obligation="normative">
<title>Symbols</title>
</definitions>
</clause>
<definitions id="_" unnumbered="true" type="abbreviated_terms" obligation="normative">
<title>Abbreviated terms</title>
</definitions>
<clause id="_" unnumbered="true" type="ABC" inline-header="false" obligation="normative">
<title>Clause 4</title>
<clause id="_" unnumbered="true" type="DEF" inline-header="false" obligation="normative">
<title>Introduction</title>
</clause>
<clause id="_" unnumbered="true" inline-header="false" obligation="normative">
<title>Clause 4.2</title>
</clause>
</clause>
</sections>
<annex id="_" unnumbered="true" inline-header="false" obligation="normative">
<title>Annex</title>
<clause id="_" unnumbered="true" inline-header="false" obligation="normative">
<title>Annex A.1</title>
</clause>
</annex>
<bibliography>
<references id="_" unnumbered="true" normative="true" obligation="informative">
<title>Normative references</title>
<p id="_">There are no normative references in this document.</p>
</references>
<clause id="_" unnumbered="true" obligation="informative">
<title>Bibliography</title>
<references id="_" unnumbered="true" normative="false" obligation="informative">
<title>Bibliography Subsection</title>
</references>
</clause>
</bibliography>
</standard-document>
OUTPUT
expect(xmlpp(strip_guid(Asciidoctor.convert(input, *OPTIONS))))
.to be_equivalent_to xmlpp(output)
Expand Down

0 comments on commit 650946d

Please sign in to comment.