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

Feature/presxml autonum #1247

Merged
merged 34 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ad158d8
https://github.com/metanorma/isodoc/issues/617
opoudjis Nov 17, 2024
93d44d5
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 18, 2024
3f72f8f
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 18, 2024
089296a
modspec update for Presentation XML caption refactoring: https://gith…
opoudjis Nov 19, 2024
0ba54da
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 20, 2024
390bee2
refactor figure captioning: https://github.com/metanorma/isodoc/issue…
opoudjis Nov 20, 2024
0d6d185
refactor examples rendering: https://github.com/metanorma/isodoc/issu…
opoudjis Nov 20, 2024
32ed90d
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 20, 2024
46f58d4
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 20, 2024
9ac412c
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 20, 2024
f857799
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 20, 2024
f09d5a7
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 21, 2024
cba8305
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 21, 2024
7605499
mark up annex obligation in title: https://github.com/metanorma/isodo…
opoudjis Nov 21, 2024
060fa7f
insert spacing delimiter for note in fmt-name, to simplify downstream…
opoudjis Nov 21, 2024
722db89
Presentation XML caption refactor: https://github.com/metanorma/isodo…
opoudjis Nov 24, 2024
c97925d
hierarchically annotate clause numbers: https://github.com/metanorma/…
opoudjis Nov 24, 2024
47c2421
semantically annotate hierarchically formed labels of bloocks: https:…
opoudjis Nov 24, 2024
e3f5e5f
fmt-caption-label update: https://github.com/metanorma/isodoc/issues/617
opoudjis Nov 26, 2024
bd379bf
mark up containers in xref, add container instance of fmt-xref-label:…
opoudjis Nov 29, 2024
336c679
put anchors on ordered list items if missing, for consistency with re…
opoudjis Nov 30, 2024
fee2fab
https://github.com/metanorma/isodoc/issues/617
opoudjis Nov 30, 2024
84edaae
configurable figure + subfigure label: https://github.com/metanorma/i…
opoudjis Nov 30, 2024
9ec4efd
cope with multiline xrefs for span annotation with ISO class name: ht…
opoudjis Nov 30, 2024
e66c86b
cope with multiline xrefs for span annotation with ISO class name: ht…
opoudjis Nov 30, 2024
92ebcf8
https://github.com/metanorma/isodoc/issues/617
opoudjis Nov 30, 2024
c9648b3
inherit container status of parent in subfigure xrefs: https://github…
opoudjis Nov 30, 2024
cedacae
https://github.com/metanorma/isodoc/issues/617
opoudjis Dec 1, 2024
25a3d38
rspec
opoudjis Dec 1, 2024
11725f2
https://github.com/metanorma/isodoc/issues/617
opoudjis Dec 3, 2024
53c23e4
rspec
opoudjis Dec 4, 2024
f2251e1
grammar
opoudjis Dec 8, 2024
74b0fc9
gemfile
opoudjis Dec 8, 2024
ba0e0a4
rspec
opoudjis Dec 8, 2024
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
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid qualifying class selectors with an element.
Each selector in a comma sequence should be on its own single line
Selector example_label should be written in lowercase with hyphens
Selector note_label should be written in lowercase with hyphens
Selector termnote_label should be written in lowercase with hyphens

{
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 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

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'a' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'a' and with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings with many repetitions of ' '.
This
regular expression
that depends on a
library input
may run slow on strings starting with 'a' and with many repetitions of ' '.
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 @@
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
Loading