Skip to content

Commit

Permalink
Merge pull request #436 from metanorma/feature/presxml-autonum
Browse files Browse the repository at this point in the history
Presentation XML caption refactor: https://github.com/metanorma/isodo…
  • Loading branch information
opoudjis authored Dec 8, 2024
2 parents 77d63af + f23c090 commit 4419112
Show file tree
Hide file tree
Showing 30 changed files with 3,869 additions and 2,552 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: "fix/markup-connectives"
gem "mn-requirements", git: "https://github.com/metanorma/mn-requirements", branch: "feature/presxml-autonum"

18 changes: 13 additions & 5 deletions lib/isodoc/ieee/base_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def top_element_render(elem, out)
def scope(node, out, num)
out.div **attr_code(id: node["id"]) do |div|
num = num + 1
clause_name(node, node&.at(ns("./title")), div, nil)
clause_name(node, node&.at(ns("./fmt-title")), div, nil)
node.elements.each do |e|
parse(e, div) unless e.name == "title"
parse(e, div) unless e.name == "fmt-title"
end
end
num
Expand All @@ -34,8 +34,9 @@ def para_attrs(node)
super.merge(type: node["type"])
end

def note_p_parse(node, div)
name = node&.at(ns("./name"))&.remove
#TODO kill
def note_p_parsex(node, div)
name = node&.at(ns("./fmt-name"))&.remove
div.p do |p|
name and p.span class: "note_label" do |s|
name.children.each { |n| parse(n, s) }
Expand All @@ -45,7 +46,8 @@ def note_p_parse(node, div)
node.element_children[1..-1].each { |n| parse(n, div) }
end

def note_parse1(node, div)
#TODO kill
def note_parse1x(node, div)
name = node&.at(ns("./name"))&.remove
name and div.p do |p|
p.span class: "note_label" do |s|
Expand All @@ -62,6 +64,12 @@ def example_label(_node, div, name)
name.children.each { |n| parse(n, p) }
end
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/ieee/i18n-en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ termsdefsymbols: Definitions, acronyms and abbreviations
termsdefabbrev: Definitions, acronyms and abbreviations
formula: Equation
inequality: Inequality
termnote: NOTE
termnote: "<span class='fmt-element-name'>NOTE</span> %"
example: Example
table_of_contents: Contents
viewed: accessed
Expand Down
15 changes: 7 additions & 8 deletions lib/isodoc/ieee/presentation_terms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module IsoDoc
module Ieee
class PresentationXMLConvert < IsoDoc::PresentationXMLConvert
def multidef(elem)
# require "debug"; binding.b
number_multidef(elem)
collapse_multidef(elem)
end
Expand Down Expand Up @@ -35,9 +36,11 @@ def unwrap_definition(docxml)
docxml.xpath(ns(".//definition/verbal-definition")).each do |v|
v.elements.all? { |e| %w(termsource p).include?(e.name) } or next
p = v.xpath(ns("./p"))
s = v.xpath(ns('./termsource'))
s.empty? or
s = " (#{s.map { |x| to_xml(x) }.join("\n")})"
v.children =
"<p>#{p.map(&:children).map { |x| to_xml(x) }.join("\n")}</p>" \
"#{v.xpath(ns('./termsource')).to_xml}"
"<p>#{p.map(&:children).map { |x| to_xml(x) }.join("\n")}#{s}</p>"
end
super
end
Expand Down Expand Up @@ -241,18 +244,14 @@ def merge_second_preferred(term)
pref << " (#{tail})"
end

def termnote_delim(_elem)
"&#x2014;"
end

def termnote1(elem)
lbl = termnote_label(elem)
prefix_name(elem, block_delim, lower2cap(lbl), "name")
prefix_name(elem, { label: block_delim }, lower2cap(lbl), "name")
end

def termnote_label(elem)
lbl = l10n(@xrefs.anchor(elem["id"], :label)&.strip || "???")
l10n "#{lbl}#{termnote_delim(elem)}"
l10n lbl
end

def term(docxml); end
Expand Down
30 changes: 22 additions & 8 deletions lib/isodoc/ieee/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ def anchor_linkend1(node)
@xrefs.anchor(node["target"], :type) == "clause" &&
@xrefs.anchor(node["target"], :level) > 1 &&
!start_of_sentence(node) and
linkend = linkend.sub(/^Clause /, "")
linkend = strip_initial_clause(linkend)
container = @xrefs.anchor(node["target"], :container, false)
linkend = prefix_container(container, linkend, node, node["target"])
capitalise_xref(node, linkend, anchor_value(node["target"]))
end

def strip_initial_clause(linkend)
x = Nokogiri::XML("<a>#{linkend}</a>")
x.at(".//span[@class = 'fmt-element-name']")&.remove
to_xml(x.elements.first.children).strip
end

def eref_locality_populate(type, node, number)
type == "page" and return ""
super
Expand All @@ -81,25 +87,33 @@ def annex1(elem)
if @doctype == "whitepaper"
annex1_whitepaper(elem)
else
annex1_default(elem)
super
end
end

def annex1_whitepaper(elem)
lbl = @xrefs.anchor(elem["id"], :label)
if t = elem.at(ns("./title"))
t.name = "variant-title"
t["type"] = "sub"
d = t.dup
# TODO fmt-variant-title
d.name = "variant-title"
d["type"] = "sub"
t.next = d
end
elem.add_first_child "<title>#{lbl}</title>"
elem.add_first_child "<fmt-title>#{lbl}</fmt-title>"
end

def annex_delim(_elem)
"<br/>"
end

# KILL
def annex1_default(elem)
lbl = @xrefs.anchor(elem["id"], :label)
if t = elem.at(ns("./title"))
t.children = "<strong>#{to_xml(t.children)}</strong>"
end
prefix_name(elem, "<br/>", lbl, "title")
prefix_name(elem, { caption: "<br/>" }, lbl, "title")
end

def amend1(elem)
Expand Down Expand Up @@ -214,8 +228,8 @@ def move_abstract(doc)

def example1(elem)
super
n = elem.at(ns("./name")) or return
n << l10n(":")
n = elem.at(ns("./fmt-name")) or return
n << l10n("<span class='fmt-caption-delim'>:</span>")
n.children.wrap("<em></em>")
end

Expand Down
16 changes: 0 additions & 16 deletions lib/isodoc/ieee/word_cleanup_blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,9 @@ def td_style(cell, idx)
end

def caption_cleanup(docxml)
table_caption(docxml)
figure_caption(docxml)
example_caption(docxml)
end

def table_caption(docxml)
docxml.xpath("//p[@class = 'TableTitle']").each do |s|
s.children = to_xml(s.children)
.sub(/^#{@i18n.table}(\s+[A-Z0-9.]+)?/, "")
end
end

def figure_caption(docxml)
docxml.xpath("//p[@class = 'FigureTitle']").each do |s|
s.children = to_xml(s.children)
.sub(/^#{@i18n.figure}(\s+[A-Z0-9.]+)?/, "")
end
end

def example_caption(docxml)
docxml.xpath("//p[@class = 'example-title']").each do |s|
s["class"] = stylesmap[:MsoNormal]
Expand Down
62 changes: 40 additions & 22 deletions lib/isodoc/ieee/word_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def default_file_locations(_options)
def abstract(clause, out)
page_break(out)
out.div **attr_code(id: clause["id"], class: "abstract") do |s|
clause_name(clause, clause.at(ns("./title")), s,
clause_name(clause, clause.at(ns("./fmt-title")), s,
{ class: stylesmap[:AbstractTitle] })
clause.elements.each { |e| parse(e, s) unless e.name == "title" }
clause.elements.each { |e| parse(e, s) unless e.name == "fmt-title" }
end
end

Expand Down Expand Up @@ -120,8 +120,7 @@ def formula_parse(node, out)
formula_parse1(node, div)
formula_where(node.at(ns("./dl")), div)
node.children.each do |n|
next if %w(stem dl name).include? n.name

%w(stem dl fmt-name).include? n.name and next
parse(n, div)
end
end
Expand All @@ -132,8 +131,7 @@ def dt_dd?(node)
end

def formula_where(dlist, out)
return unless dlist

dlist or return
dlist.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
formula_where1(out, dt, dd)
end
Expand All @@ -158,33 +156,32 @@ def annex_attrs(node)
end

def annex_name(_annex, name, div)
return if name.nil?

name&.at(ns("./strong"))&.remove # supplied by CSS list numbering
name.nil? and return
name&.at(ns(".//strong"))&.remove # supplied by CSS list numbering
div.h1 class: "Annex" do |t|
annex_name1(name, t)
# annex_name1(name, t)
children_parse(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
def span_parse(node, out)
if node["class"] == "fmt-obligation"
node.delete("class")
node["style"] = "font-weight:normal;"
end
super
end

def termnote_parse(node, out)
name = node&.at(ns("./name"))&.remove
name = node.at(ns("./fmt-name"))
para = node.at(ns("./p"))
out.div **note_attrs(node) do |div|
div.p do |p|
name and termnote_label(p, name)
para_then_remainder(node.first_element_child, node, p, div)
children_parse(para, p)
end
para.xpath("./following-sibling::*").each { |n| parse(n, div) }
end
end

Expand All @@ -197,14 +194,35 @@ def termnote_label(para, name)
# STYLE
def table_of_contents(clause, out)
out.div class: "WordSectionContents" do |div|
clause_name(clause, clause.at(ns("./title")), div,
clause_name(clause, clause.at(ns("./fmt-title")), div,
{ class: "IEEEStdsLevel1frontmatter" })
clause.elements.each do |e|
parse(e, div) unless e.name == "title"
parse(e, div) unless e.name == "fmt-title"
end
end
end

# Figure 1— remove each of these
def figure_name_parse(_node, div, name)
name.nil? and return
name.at(".//xmlns:semx[@element = 'autonum']/"\
"preceding-sibling::*[normalize-space() = '']")&.remove
name.xpath(ns(".//span[@class = 'fmt-element-name'] | "\
".//span[@class = 'fmt-caption-delim'] | "\
".//semx[@element = 'autonum']")).each(&:remove)
super
end

def table_title_parse(node, out)
name = node.at(ns("./fmt-name")) or return
name.at(".//xmlns:semx[@element = 'autonum']/"\
"preceding-sibling::*[normalize-space() = '']")&.remove
name.xpath(ns(".//span[@class = 'fmt-element-name'] | "\
".//span[@class = 'fmt-caption-delim'] | "\
".//semx[@element = 'autonum']")).each(&:remove)
super
end

include BaseConvert
include Init
end
Expand Down
8 changes: 4 additions & 4 deletions lib/isodoc/ieee/word_wp_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def abstract(clause, out)
end

def abstract_body(clause, out)
clause_name(clause, clause.at(ns("./title")), out,
clause_name(clause, clause.at(ns("./fmt-title")), out,
{ class: stylesmap[:AbstractTitle],
style: ABSTRACT_MARGIN })
clause.elements.each { |e| parse(e, out) unless e.name == "title" }
clause.elements.each { |e| parse(e, out) unless e.name == "fmt-title" }
end

def clause(node, out)
Expand All @@ -98,9 +98,9 @@ def clause(node, out)

def figure_parse1(node, out)
out.div **figure_attrs(node) do |div|
figure_name_parse(node, div, node.at(ns("./name")))
figure_name_parse(node, div, node.at(ns("./fmt-name")))
node.children.each do |n|
parse(n, div) unless n.name == "name"
parse(n, div) unless n.name == "fmt-name"
end
end
end
Expand Down
Loading

0 comments on commit 4419112

Please sign in to comment.