Skip to content

Commit

Permalink
Merge pull request #1247 from metanorma/feature/presxml-autonum
Browse files Browse the repository at this point in the history
Feature/presxml autonum
  • Loading branch information
opoudjis authored Dec 8, 2024
2 parents 92ac00d + ba0e0a4 commit 61f947d
Show file tree
Hide file tree
Showing 36 changed files with 9,855 additions and 5,367 deletions.
4 changes: 4 additions & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "feature/presxml-autonum"
gem "isodoc-i18n", git: "https://github.com/metanorma/isodoc-i18n", branch: "main"
gem "mn-requirements", git: "https://github.com/metanorma/mn-requirements", branch: "main"

48 changes: 27 additions & 21 deletions lib/isodoc/iso/base_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,34 @@ def example_span_label(_node, div, name)
end
end

def example_p_class
nil
end

def example_p_parse(node, div)
div.p do |p|
example_span_label(node, p, node&.at(ns("./name"))&.remove)
insert_tab(p, 1)
node.first_element_child.children.each { |n| parse(n, p) }
name = node.at(ns("./fmt-name"))
para = node.at(ns("./p"))
div.p **attr_code(class: example_p_class) do |p|
name and p.span class: "example_label" do |s|
name.children.each { |n| parse(n, s) }
end
insert_tab(p, 1) # TODO to Presentation XML
children_parse(para, p)
end
node.element_children[1..].each { |n| parse(n, div) }
para.xpath("./following-sibling::*").each { |n| parse(n, div) }
end

def example_parse1(node, div)
div.p do |p|
example_span_label(node, p, node.at(ns("./name")))
example_span_label(node, p, node.at(ns("./fmt-name")))
insert_tab(p, 1)
end
node.children.each { |n| parse(n, div) unless n.name == "name" }
end

def node_begins_with_para(node)
node.elements.each do |e|
e.name == "name" and next
e.name == "p" and return true
return false
end
false
node.children.each { |n| parse(n, div) unless n.name == "fmt-name" }
end

def example_parse(node, out)
out.div id: node["id"], class: "example" do |div|
if node_begins_with_para(node)
if starts_with_para?(node)
example_p_parse(node, div)
else
example_parse1(node, div)
Expand Down Expand Up @@ -88,6 +87,7 @@ def admonition_p_parse(node, div)
admonition_name_in_first_para(node, div)
end

# TODO: To Presentation XML
def admonition_name_para_delim(para)
para << " "
end
Expand All @@ -114,9 +114,9 @@ def clause_etc1(clause, out, num)
class: clause.name == "definitions" ? "Symbols" : nil,
) do |div|
num = num + 1
clause_name(clause, clause&.at(ns("./title")), div, nil)
clause_name(clause, clause&.at(ns("./fmt-title")), div, nil)
clause.elements.each do |e|
parse(e, div) unless %w{title source}.include? e.name
parse(e, div) unless %w{fmt-title source}.include? e.name
end
end
end
Expand Down Expand Up @@ -149,9 +149,9 @@ def figure_parse1(node, out)
out.div **figure_attrs(node) do |div|
node.children.each do |n|
n.name == "note" && n["type"] == "units" and next
parse(n, div) unless n.name == "name"
parse(n, div) unless n.name == "fmt-name"
end
figure_name_parse(node, div, node.at(ns("./name")))
figure_name_parse(node, div, node.at(ns("./fmt-name")))
end
end

Expand All @@ -178,6 +178,12 @@ def convert_i18n_init(docxml)
super
update_i18n(docxml)
end

def span_parse(node, out)
node["class"] == "fmt-obligation" and
node["class"] = "obligation"
super
end
end
end
end
2 changes: 1 addition & 1 deletion lib/isodoc/iso/html/isodoc-dis.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4314,7 +4314,7 @@ div.Note table.dl {
margin-left: 1.0cm;
}

td.example_label, td.note_label
td.example_label, td.note_label, td.termnote_label
{
font-size: $smallerfontsize;
font-family:$bodyfont;
Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/iso/html/isodoc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,7 @@ div.Note table.dl {
margin-left: 1.0cm;
}

span.note_label, span.example_label, td.example_label, td.note_label
span.note_label, span.example_label, td.example_label, td.note_label, span.termnote_label, td.termnote_label
{
font-size: $smallerfontsize;
font-family:$bodyfont;
Expand Down
29 changes: 0 additions & 29 deletions lib/isodoc/iso/presentation_bibdata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,6 @@ class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
def bibdata(docxml)
super
editorialgroup_identifier(docxml)
warning_for_missing_metadata(docxml)
end

def warning_for_missing_metadata(docxml)
@meta.get[:unpublished] or return
ret = warning_for_missing_metadata_create(docxml)
ret.empty? and return
warning_for_missing_metadata_post(docxml, ret)
end

def warning_for_missing_metadata_create(docxml)
ret = ""
docxml.at(ns("//bibdata/ext//secretariat")) or
ret += "<p>Secretariat is missing.</p>"
docxml.at(ns("//bibdata/ext//editorialgroup")) or
ret += "<p>Editorial groups are missing.</p>"
docxml.at(ns("//bibdata/date[@type = 'published' or @type = 'issued' " \
"or @type = 'created']")) ||
docxml.at(ns("//bibdata/version/revision-date")) or
ret += "<p>Document date is missing.</p>"
ret
end

def warning_for_missing_metadata_post(docxml, ret)
id = UUIDTools::UUID.random_create
ret = "<review date='#{Date.today}' reviewer='Metanorma' id='_#{id}'>" \
"<p><strong>Metadata warnings:<strong></p> #{ret}</review>"
ins = docxml.at(ns("//sections//title")) or return
ins.add_first_child ret
end

def editorialgroup_identifier(docxml)
Expand Down
125 changes: 95 additions & 30 deletions lib/isodoc/iso/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,47 @@ def convert1(docxml, filename, dir)
super
end

def section(docxml)
super
warning_for_missing_metadata(docxml)
end

def warning_for_missing_metadata(docxml)
@meta.get[:unpublished] or return
ret = warning_for_missing_metadata_create(docxml)
ret.empty? and return
warning_for_missing_metadata_post(docxml, ret)
end

def warning_for_missing_metadata_create(docxml)
ret = ""
docxml.at(ns("//bibdata/ext//secretariat")) or
ret += "<p>Secretariat is missing.</p>"
docxml.at(ns("//bibdata/ext//editorialgroup")) or
ret += "<p>Editorial groups are missing.</p>"
docxml.at(ns("//bibdata/date[@type = 'published' or @type = 'issued' " \
"or @type = 'created']")) ||
docxml.at(ns("//bibdata/version/revision-date")) or
ret += "<p>Document date is missing.</p>"
ret
end

def warning_for_missing_metadata_post(docxml, ret)
id = UUIDTools::UUID.random_create
ret = "<review date='#{Date.today}' reviewer='Metanorma' id='_#{id}'>" \
"<p><strong>Metadata warnings:<strong></p> #{ret}</review>"
ins = docxml.at(ns("//sections//fmt-title")) or return
ins.add_first_child ret
end

def block(docxml)
amend docxml
figure docxml
sourcecode docxml
formula docxml
admonition docxml
source docxml
ul docxml
ol docxml
quote docxml
permission docxml
Expand All @@ -38,37 +72,49 @@ def block(docxml)
requirement_render docxml
@xrefs.anchors_previous = @xrefs.anchors.dup # store old xrefs of reqts
@xrefs.parse docxml
# TODO move this dependency around: requirements at root should be processed before everything else
table docxml # have table include requirements newly converted to tables
# table feeds dl
dl docxml
example docxml
note docxml
end

# Redo Amendment annex titles as numbered
def annex(isoxml)
amd?(isoxml) and @suppressheadingnumbers = @oldsuppressheadingnumbers
super
isoxml.xpath(ns("//annex//clause | //annex//appendix")).each do |f|
amd?(isoxml) and @suppressheadingnumbers = true
end

# Redo Amendment annex subclause titles as numbered
def clause(docxml)
super
docxml.xpath(ns("//annex//appendix")).each { |f| clause1(f) }
amd?(docxml) or return
@suppressheadingnumbers = @oldsuppressheadingnumbers
docxml.xpath(ns("//annex//clause | //annex//appendix")).each do |f|
f.xpath(ns("./fmt-title | ./fmt-xref-label")).each(&:remove)
clause1(f)
end
amd?(isoxml) and @suppressheadingnumbers = true
@suppressheadingnumbers = true
end

def subfigure_delim
"<span class='fmt-label-delim'>)</span>"
end

def figure_delim(elem)
elem.parent.name == "figure" ? "&#xa0; " : "&#xa0;&#x2014; "
end

def figure1(node)
figure_fn(node)
figure_key(node.at(ns("./dl")))
lbl = @xrefs.anchor(node["id"], :label, false) or return
figname = node.parent.name == "figure" ? "" : "#{@i18n.figure} "
conn = node.parent.name == "figure" ? "&#xa0; " : "&#xa0;&#x2014; "
prefix_name(node, conn, l10n("#{figname}#{lbl}"), "name")
def figure_name(elem)
elem.parent.name == "figure" and return ""
super
end

def example1(node)
n = @xrefs.get[node["id"]]
lbl = if n.nil? || blank?(n[:label]) then @i18n.example
else l10n("#{@i18n.example} #{n[:label]}")
end
prefix_name(node, block_delim, lbl, "name")
def figure_label?(_elem)
true
end

def example_span_label(_node, div, name)
Expand All @@ -79,27 +125,34 @@ def example_span_label(_node, div, name)
end

def clause1(node)
if !node.at(ns("./title")) &&
!%w(sections preface bibliography).include?(node.parent.name)
!node.at(ns("./title")) &&
!%w(sections preface bibliography).include?(node.parent.name) and
node["inline-header"] = "true"
end
super
if node["type"] == "section"
t = node.at(ns("./title/tab")) and
t.previous = @i18n.l10n(": ").sub(/\p{Zs}$/, "")
end
clause1_section_prefix(node)
end

def clause(docxml)
docxml.xpath(ns("//clause[not(ancestor::annex)] | " \
"//terms | //definitions | //references | " \
"//preface/introduction[clause]")).each do |f|
f.parent.name == "annex" &&
@xrefs.klass.single_term_clause?(f.parent) and next
clause1(f)
def clause1_section_prefix(node)
if node["type"] == "section" &&
c = node.at(ns("./fmt-title//span[@class = 'fmt-caption-delim']"))
c.add_first_child(":")
t = node.at(ns("./fmt-title"))
# French l10n needs tab to be treated as space
t.replace @i18n.l10n(to_xml(t).gsub("<tab/>", "<tab> </tab>"))
.gsub(%r{<tab>[^<]+</tab>}, "<tab/>")
end
end

# def clause(docxml)
# docxml.xpath(ns("//clause[not(ancestor::annex)] | " \
# "//terms | //definitions | //references | " \
# "//preface/introduction[clause]")).each do |f|
# f.parent.name == "annex" &&
# @xrefs.klass.single_term_clause?(f.parent) and next
# clause1(f)
# end
# end

def admonition1(elem)
super
admonition_outside_clauses(elem)
Expand Down Expand Up @@ -153,10 +206,22 @@ def formula_where_one(dlist)
end

def table1(elem)
table1_key(elem)
if elem["class"] == "modspec"
n = elem.at(ns(".//fmt-name")).remove
n.name = "name"
elem.add_first_child(n)
elem.at(ns("./thead"))&.remove
super
elem.at(ns("./name")).remove
else super
end
end

def table1_key(elem)
elem.xpath(ns(".//dl[@key = 'true'][not(./name)]")).each do |dl|
dl.add_first_child "<name>#{@i18n.key}</name>"
end
super
end

def toc_title(docxml)
Expand Down
6 changes: 4 additions & 2 deletions lib/isodoc/iso/presentation_xref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def subclause?(target, type, from)

def locality_span_wrap(ret, type)
type or return ret
m = /^(\s*)(?=\S)(.+?)(\s*)$/.match(ret) or return ret
m = /\A(\s*)(?=\S)(.+?)(\s*)\Z/m.match(ret) or return ret
ret = [m[1], m[2], m[3]]
spanclass = LOCALITY2SPAN[type.to_sym] and
ret[1] = "<span class='#{spanclass}'>#{ret[1]}</span>"
Expand Down Expand Up @@ -115,7 +115,9 @@ def prefix_container(container, linkend, node, target)
prefix_container_template(container, node, target)
container_label = prefix_container(container_container,
container_label, node, target)
l10n(nested_xref.sub("%1", container_label).sub("%2", linkend))
l10n(connectives_spans(nested_xref
.sub("%1", "<span class='fmt-xref-container'>#{container_label}</span>")
.sub("%2", linkend)))
end

def prefix_container_template(container, node, target)
Expand Down
4 changes: 2 additions & 2 deletions lib/isodoc/iso/sections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def foreword(clause, out)
@foreword = true
page_break(out)
out.div **attr_code(id: clause["id"]) do |s|
clause_name(nil, clause.at(ns("./title")), s,
clause_name(nil, clause.at(ns("./fmt-title")), s,
{ class: "ForewordTitle" })
clause.elements.each { |e| parse(e, s) unless e.name == "title" }
clause.elements.each { |e| parse(e, s) unless e.name == "fmt-title" }
end
@foreword = false
end
Expand Down
Loading

0 comments on commit 61f947d

Please sign in to comment.