Skip to content

Commit

Permalink
deal with combination of floating title and beforeclauses note: #815
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Oct 13, 2023
1 parent 49b8ca9 commit a6e072c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def cleanup(xmldoc)
element_name_cleanup(xmldoc)
ref_cleanup(xmldoc) # feeds: bibitem_cleanup
note_cleanup(xmldoc)
clausebefore_cleanup(xmldoc)
clausebefore_cleanup(xmldoc) # feeeds: floatingtitle_cleanup
floatingtitle_cleanup(xmldoc)
bibitem_cleanup(xmldoc) # feeds: normref_cleanup, biblio_cleanup,
# reference_names, bpart_cleanup
Expand Down
19 changes: 15 additions & 4 deletions lib/metanorma/standoc/cleanup_section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def obligations_cleanup_inherit(xml)
end

def clausebefore_cleanup(xmldoc)
preface_clausebefore_cleanup(xmldoc)
sections_clausebefore_cleanup(xmldoc)
preface_clausebefore_cleanup(xmldoc)
end

def preface_clausebefore_cleanup(xmldoc)
Expand All @@ -196,10 +196,20 @@ def preface_clausebefore_cleanup(xmldoc)
end

def sections_clausebefore_cleanup(xmldoc)
return unless xmldoc.at("//sections")

xmldoc.at("//sections") or return
ins = insert_before(xmldoc, "//sections")
xmldoc.xpath("//sections//*[@beforeclauses = 'true']").each do |x|
xmldoc.xpath("//sections//*[@beforeclauses = 'true']").reverse.each do |x|
x.delete("beforeclauses")
ins.previous = x.remove
end
endofpreface_clausebefore(xmldoc, ins)
end

# 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
x.delete("beforeclauses")
ins.previous = x.remove
end
Expand All @@ -214,6 +224,7 @@ def insert_before(xmldoc, xpath)
end

def floatingtitle_cleanup(xmldoc)
pop_floating_title(xmldoc) # done again, after endofpreface_clausebefore
floating_title_preface2sections(xmldoc)
end

Expand Down
82 changes: 82 additions & 0 deletions spec/metanorma/cleanup_sections_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1889,4 +1889,86 @@
expect(xmlpp(strip_guid(ret.to_xml)))
.to be_equivalent_to(xmlpp(output))
end

it "puts floating title + clausebefore note before scope into sections container" do
input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
== Foreword
A
[discrete%section]
== Basic layout and preliminary elements
[NOTE,beforeclauses=true]
Initial Note
== Scope
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
<preface>
<foreword id="_" obligation="informative">
<title>Foreword</title>
<p id="_">A</p>
</foreword>
</preface>
<sections>
<floating-title id="_" depth="1" type="floating-title">Basic layout and preliminary elements</floating-title>
<note id="_">
<p id="_">Initial Note</p>
</note>
<clause id="_" type="scope" inline-header="false" obligation="normative">
<title>Scope</title>
</clause>
</sections>
</standard-document>
OUTPUT
ret = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS))
expect(xmlpp(strip_guid(ret.to_xml)))
.to be_equivalent_to(xmlpp(output))

input = <<~INPUT
#{ASCIIDOC_BLANK_HDR}
== Foreword
A
[discrete%section]
== Basic layout and preliminary elements
[NOTE,beforeclauses=true]
Initial Note
More
== Scope
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
<preface>
<note id="_">
<p id="_">Initial Note</p>
</note>
<foreword id="_" obligation="informative">
<title>Foreword</title>
<p id="_">A</p>
<floating-title id="_" depth="1" type="floating-title">Basic layout and preliminary elements</floating-title>
<p id="_">More</p>
</foreword>
</preface>
<sections>
<clause id="_" type="scope" inline-header="false" obligation="normative">
<title>Scope</title>
</clause>
</sections>
</standard-document>
OUTPUT
ret = Nokogiri::XML(Asciidoctor.convert(input, *OPTIONS))
expect(xmlpp(strip_guid(ret.to_xml)))
.to be_equivalent_to(xmlpp(output))
end

end

0 comments on commit a6e072c

Please sign in to comment.