Skip to content

Commit

Permalink
Merge pull request #429 from metanorma/fix/refactor-xrefs-oct24
Browse files Browse the repository at this point in the history
Fix/refactor xrefs oct24
  • Loading branch information
opoudjis authored Nov 5, 2024
2 parents d9a30b7 + 762e319 commit d6844db
Show file tree
Hide file tree
Showing 22 changed files with 1,339 additions and 1,148 deletions.
2 changes: 2 additions & 0 deletions Gemfile.devel
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gem "metanorma-standoc", git: "https://github.com/metanorma/metanorma-standoc", branch: "main"
gem "isodoc", git: "https://github.com/metanorma/isodoc", branch: "fix/refactor-xrefs-oct24"
25 changes: 1 addition & 24 deletions lib/isodoc/ieee/base_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,11 @@ def para_attrs(node)
super.merge(type: node["type"])
end

def note_delim
"—"
end

def omit_docid_prefix(prefix)
prefix == "DOI" and return true
super
end

def note_p_parse(node, div)
name = node&.at(ns("./name"))&.remove
div.p do |p|
name and p.span class: "note_label" do |s|
name.children.each { |n| parse(n, s) }
s << note_delim
end
node.first_element_child.children.each { |n| parse(n, p) }
end
Expand All @@ -60,25 +50,12 @@ def note_parse1(node, div)
name and div.p do |p|
p.span class: "note_label" do |s|
name.children.each { |n| parse(n, s) }
s << note_delim
end
end
node.children.each { |n| parse(n, div) }
end

def termnote_delim
"&#x2014;"
end

def bracket_if_num(num)
return nil if num.nil?

num = num.text.sub(/^\[/, "").sub(/\]$/, "")
return "[#{num}]" if /^B?\d+$/.match?(num)

num
end

# TODO ":" to Presentation XML
def example_label(_node, div, name)
return if name.nil?

Expand Down
14 changes: 14 additions & 0 deletions lib/isodoc/ieee/presentation_ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ def availability_note(bib)
id = UUIDTools::UUID.random_create.to_s
"<fn reference='#{id}'><p>#{note.content}</p></fn>"
end

def omit_docid_prefix(prefix)
prefix == "DOI" and return true
super
end

def bracket_if_num(num)
return nil if num.nil?

num = num.text.sub(/^\[/, "").sub(/\]$/, "")
return "[#{num}]" if /^B?\d+$/.match?(num)

num
end
end
end
end
21 changes: 18 additions & 3 deletions lib/isodoc/ieee/presentation_terms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def number_multidef(elem)
c = IsoDoc::XrefGen::Counter.new("@")
elem.xpath(ns("./definition")).each do |d|
c.increment(d)
d.elements.first.children.first.previous =
"<strong>(#{c.print})</strong>&#xa0;"
d.elements.first.add_first_child "<strong>(#{c.print})</strong>&#xa0;"
end
end

Expand Down Expand Up @@ -214,6 +213,13 @@ def termsource_adapt(status)
end
end

# domain is rendered in designation_field instead
def termdomain(elem)
d = elem.at(ns(".//domain")) or return
d["hidden"] = "true"
end

# TODO wrap domain not in <domain>, but <span class="domain"> or equivalent
def designation_field(desgn, name)
if desgn.name == "preferred"
f = desgn.xpath(ns("./../domain | ./../subject")).map(&:remove)
Expand All @@ -235,11 +241,20 @@ def merge_second_preferred(term)
pref << " (#{tail})"
end

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

def termnote1(elem)
lbl = l10n(@xrefs.anchor(elem["id"], :label)&.strip || "???")
lbl = termnote_label(elem)
prefix_name(elem, block_delim, lower2cap(lbl), "name")
end

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

def term(docxml); end

def concept1(node)
Expand Down
14 changes: 5 additions & 9 deletions lib/isodoc/ieee/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ def eref_localities_conflated(refs, target, node)
ret = resolve_eref_connectives(eref_locality_stacks(refs, target,
node))
node["droploc"] = droploc
p = prefix_clause(target, refs.first.at(ns("./locality")))
eref_localities1({ target: target, number: "pl",
type: prefix_clause(target, refs.first.at(ns("./locality"))),
type: p,
from: l10n(ret[1..-1].join), node: node,
lang: @lang })
end
Expand Down Expand Up @@ -72,13 +73,8 @@ def block_delim
"&#x2014;"
end

def note1(elem)
elem.parent.name == "bibitem" || elem["notag"] == "true" and return
n = @xrefs.get[elem["id"]]
lbl = if n.nil? || n[:label].nil? || n[:label].empty? then @i18n.note
else l10n("#{@i18n.note} #{n[:label]}")
end
prefix_name(elem, block_delim, lbl, "name")
def note_delim(_elem)
"&#x2014;"
end

def annex1(elem)
Expand All @@ -95,7 +91,7 @@ def annex1_whitepaper(elem)
t.name = "variant-title"
t["type"] = "sub"
end
elem.children.first.previous = "<title>#{lbl}</title>"
elem.add_first_child "<title>#{lbl}</title>"
end

def annex1_default(elem)
Expand Down
12 changes: 6 additions & 6 deletions lib/isodoc/ieee/word_authority.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ def feedback_style(docxml)
def feedback_style1(div, idx)
div.xpath(".//p").each_with_index do |p, j|
p["class"] = idx == 4 ? "IEEEStdsCRTextItal" : "IEEEStdsCRTextReg"
j.zero? && idx.zero? and
p.children.first.previous =
'<a style="mso-footnote-id:ftn0" href="#_ftnref0" name="_ftn0" title=""/>'
j.zero? && idx.zero? and p.add_first_child <<~XML
<a style="mso-footnote-id:ftn0" href="#_ftnref0" name="_ftn0" title=""/>
XML
end
end

Expand Down Expand Up @@ -203,9 +203,9 @@ def abstract_cleanup1(source, dest)
end

def abstract_header(dest)
dest.elements.first.children.first.previous =
"<span class='IEEEStdsAbstractHeader'><span lang='EN-US'>" \
"Abstract:</span></span> "
dest.elements.first.add_first_child <<~XML
<span class='IEEEStdsAbstractHeader'><span lang='EN-US'>Abstract:</span></span>
XML
end

def introduction_cleanup(docxml)
Expand Down
1 change: 0 additions & 1 deletion lib/isodoc/ieee/word_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ def termnote_parse(node, out)
def termnote_label(para, name)
para.span class: "note_label" do |s|
name.children.each { |n| parse(n, s) }
s << termnote_delim
end
end

Expand Down
1 change: 0 additions & 1 deletion lib/isodoc/ieee/word_wp_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def figure_parse1(node, out)
out.div **figure_attrs(node) do |div|
figure_name_parse(node, div, node.at(ns("./name")))
node.children.each do |n|
figure_key(out) if n.name == "dl"
parse(n, div) unless n.name == "name"
end
end
Expand Down
Loading

0 comments on commit d6844db

Please sign in to comment.