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 8 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
42 changes: 21 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 Down
83 changes: 60 additions & 23 deletions lib/isodoc/iso/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def block(docxml)
formula docxml
admonition docxml
source docxml
ul docxml
ol docxml
quote docxml
permission docxml
Expand All @@ -48,29 +49,53 @@ def block(docxml)
def annex(isoxml)
amd?(isoxml) and @suppressheadingnumbers = @oldsuppressheadingnumbers
super
isoxml.xpath(ns("//annex//clause | //annex//appendix")).each do |f|
isoxml.xpath(ns("//annex//appendix")).each do |f|
clause1(f)
end
amd?(isoxml) and @suppressheadingnumbers = true
end

def figure1(node)
# TODO remove
def figure1x(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} "
lbl = @xrefs.anchor(node["id"], :label, false)
lbl and a = autonum(node["id"], lbl.strip)
if node.parent.name == "figure"
a += "<span class='fmt-label-delim'>)</span>"
else
figname = "<span class='fmt-element-name'>#{i18n.figure}</span> "
end
conn = node.parent.name == "figure" ? "&#xa0; " : "&#xa0;&#x2014; "
prefix_name(node, conn, l10n("#{figname}#{lbl}"), "name")
lbl and s = "#{figname}#{a}"
prefix_name(node, { caption: conn }, l10n(s&.strip), "name")
end

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

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

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 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")
# end

def example_span_label(_node, div, name)
name.nil? and return
div.span class: "example_label" do |_p|
Expand All @@ -85,20 +110,20 @@ def clause1(node)
end
super
if node["type"] == "section"
t = node.at(ns("./title/tab")) and
t.previous = @i18n.l10n(": ").sub(/\p{Zs}$/, "")
t = node.at(ns("./fmt-title//span[@class = 'fmt-caption-delim']")) and
t.add_first_child(@i18n.l10n(": ").sub(/\p{Zs}$/, ""))
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 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
Expand Down Expand Up @@ -153,10 +178,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
2 changes: 1 addition & 1 deletion lib/isodoc/iso/presentation_xref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ 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", container_label).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
24 changes: 11 additions & 13 deletions lib/isodoc/iso/word_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ def indexsect(elem, out)
br(out, "auto")
out.div class: "index" do |div|
elem.children.each do |e|
parse(e, div) unless e.name == "title"
parse(e, div) unless e.name == "fmt-title"
end
end
end

def indexsect_title(clause, out)
br(out, "always")
out.div class: "WordSection3" do |div|
clause_name(clause, clause.at(ns("./title")), div, nil)
clause_name(clause, clause.at(ns("./fmt-title")), div, nil)
end
end

Expand Down Expand Up @@ -145,7 +145,7 @@ def bibliography(node, out)
page_break(out)
out.div do |div|
div.h1 **bibliography_attrs do |h1|
node&.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) }
node&.at(ns("./fmt-title"))&.children&.each { |c2| parse(c2, h1) }
end
biblio_list(node, div, true)
end
Expand All @@ -154,7 +154,7 @@ def bibliography(node, out)
def bibliography_parse(node, out)
node["hidden"] != true or return
out.div do |div|
clause_parse_title(node, div, node.at(ns("./title")), out,
clause_parse_title(node, div, node.at(ns("./fmt-title")), out,
bibliography_attrs)
biblio_list(node, div, true)
end
Expand Down Expand Up @@ -201,30 +201,28 @@ def table_title_attrs(node)
end

def table_title_parse(node, out)
name = node.at(ns("./name")) or return
name = node.at(ns("./fmt-name")) or return
out.p **table_title_attrs(node) do |p|
name&.children&.each { |n| parse(n, p) }
end
end

def annex_name(_annex, name, div)
name.nil? and return
name&.at(ns("./strong"))&.remove # supplied by CSS list numbering
name&.at(ns(".//strong"))&.remove # label supplied by CSS list numbering
div.h1 class: "Annex" do |t|
annex_name1(name, t)
clause_parse_subtitle(name, t)
end
end

def annex_name1(name, out)
name.children.each do |c2|
if c2.name == "span" && c2["class"] == "obligation"
out.span style: "font-weight:normal;" do |s|
c2.children.each { |c3| parse(c3, s) }
end
else parse(c2, out)
end
n = name.dup
n.xpath(ns(".//span[@class = 'obligation']")).each do |s|
s.delete("class")
s["style"] = "font-weight:normal;"
end
children_parse(n, out)
end

def table_attrs(node)
Expand Down
43 changes: 34 additions & 9 deletions lib/isodoc/iso/xref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,42 @@ def hierarchical_formula_names(clause, num)
@anchors[t["id"]] = anchor_struct(
"#{num}#{hiersep}#{c.increment(t).print}", t,
t["inequality"] ? @labels["inequality"] : @labels["formula"],
"formula", t["unnumbered"]
"formula", { unnumb: t["unnumbered"], container: true }
)
end
end

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

def figure_anchor(elem, sublabel, label, klass, container: false)
if sublabel
subfigure_anchor(elem, sublabel, label, klass, container: false)
else
@anchors[elem["id"]] = anchor_struct(
label, elem, @labels[klass] || klass.capitalize, klass,
{ unnumb: elem["unnumbered"], container: }
)
end
end

def subfigure_anchor(elem, sublabel, label, klass, container: false)
figlabel = "#{label} #{sublabel}"
@anchors[elem["id"]] = anchor_struct(
"#{label}#{sublabel}", container ? elem : nil,
@labels[klass] || klass.capitalize, klass, elem["unnumbered"]
figlabel, elem, @labels[klass] || klass.capitalize, klass,
{ unnumb: elem["unnumbered"], container: }
)
!sublabel.empty? && elem["unnumbered"] != "true" and
if elem["unnumbered"] != "true"
@anchors[elem["id"]][:label] = sublabel
@anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] +
" " + semx(elem, sublabel) + subfigure_delim
end
end

def subfigure_label(subfignum)
subfignum.zero? and return ""
" #{(subfignum + 96).chr})"
subfignum.zero? and return
(subfignum + 96).chr
end

def sequential_figure_names(clause, container: false)
Expand Down Expand Up @@ -130,7 +149,8 @@ def list_anchor_names(sections)
c = Counter.new
notes.noblank.each do |n|
@anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n,
@labels["list"], "list", false)
@labels["list"], "list",
{ unnumb: false, container: true })
list_item_anchor_names(n, @anchors[n["id"]], 1, "",
!single_ol_for_xrefs?(notes))
end
Expand Down Expand Up @@ -174,7 +194,11 @@ def xref_to_modspec(id, table_label)
(@anchors[id] && !@anchors[id][:has_modspec]) or return
@anchors[id][:has_modspec] = true
x = @anchors_previous[id][:xref_bare] || @anchors_previous[id][:xref]
@anchors[id][:xref] = l10n("#{table_label}, #{x}")
# @anchors[id][:xref] = l10n("#{table_label}<span class='fmt-comma'>,</span> #{x}")

@anchors[id][:xref] = l10n(@klass.connectives_spans(@i18n.nested_xref
.sub("%1", table_label).sub("%2", x)))

@anchors[id][:modspec] = @anchors_previous[id][:modspec]
@anchors[id][:subtype] = "modspec" # prevents citetbl style from beign applied
true
Expand All @@ -194,7 +218,8 @@ def note_anchor_names1(notes, counter)
countable.each do |n|
@anchors[n["id"]] =
anchor_struct(increment_label(countable, n, counter), n,
@labels["note_xref"], "note", false)
@labels["note_xref"], "note",
{ unnum: false, container: true })
end
end
end
Expand Down
Loading
Loading