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

preserve Semantic XML in bibitem: https://github.com/metanorma/isodoc… #654

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7092000
preserve Semantic XML in bibitem: https://github.com/metanorma/isodoc…
opoudjis Feb 19, 2025
2334256
Presentation XML refactor: footnotes: https://github.com/metanorma/is…
opoudjis Feb 21, 2025
54f5a52
Presentation refactor, footnotes: https://github.com/metanorma/isodoc…
opoudjis Feb 22, 2025
2ca61bd
Presentation XML refactor: footnotes: https://github.com/metanorma/is…
opoudjis Feb 22, 2025
92564fb
Presentation XML refactor: footnotes: https://github.com/metanorma/is…
opoudjis Feb 22, 2025
ace6185
omission of formatting of repeat footnote in Word: https://github.com…
opoudjis Feb 22, 2025
b663b3b
omission of formatting of repeat footnote in Word: https://github.com…
opoudjis Feb 22, 2025
a9862a5
Presentation XML, footnote: https://github.com/metanorma/isodoc/issue…
opoudjis Feb 24, 2025
9940be8
Presentation XML, footnote: https://github.com/metanorma/isodoc/issue…
opoudjis Feb 24, 2025
b20fdf0
Presentation XML, footnote: https://github.com/metanorma/isodoc/issue…
opoudjis Feb 24, 2025
06aebba
rspec
opoudjis Feb 24, 2025
84fbbfb
https://github.com/metanorma/isodoc/issues/623
opoudjis Feb 24, 2025
33e7200
Presentation XML, footnote: https://github.com/metanorma/isodoc/issue…
opoudjis Feb 24, 2025
2c74862
Presentation XML, footnote: https://github.com/metanorma/isodoc/issue…
opoudjis Feb 24, 2025
f399039
name, title are Semantic XML elements: https://github.com/metanorma/i…
opoudjis Feb 25, 2025
acdd3e6
https://github.com/metanorma/isodoc/issues/623
opoudjis Feb 25, 2025
2d09599
Merge branch 'main' into fix/bibitem-footnote-presxml
opoudjis Feb 25, 2025
882b9d7
Presentation XML, footnote: https://github.com/metanorma/isodoc/issue…
opoudjis Feb 26, 2025
96d7a14
bibdata footnotes in Presentation XML: https://github.com/metanorma/m…
opoudjis Feb 26, 2025
507ffb6
rspec
opoudjis Feb 28, 2025
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
6 changes: 6 additions & 0 deletions lib/isodoc/function/blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ def cross_align_parse(node, out)
end

def columnbreak_parse(node, out); end

def fmt_fn_body_parse(node, out)
out.aside id: "fn:#{node['reference']}", class: "footnote" do |div|
node.children.each { |n| parse(n, div) }
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/isodoc/function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def location_parse(node, out); end
SPAN_UNWRAP_CLASSES =
%w[fmt-caption-label fmt-label-delim fmt-caption-delim fmt-autonum-delim
fmt-element-name fmt-conn fmt-comma fmt-enum-comma fmt-obligation
fmt-xref-container fmt-designation-field].freeze
fmt-xref-container fmt-designation-field fmt-footnote-label].freeze

def span_parse(node, out)
klass = node["style"] || node["class"]
Expand Down
7 changes: 7 additions & 0 deletions lib/isodoc/function/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ def feedback_parse(node, out)
node.children.each { |n| parse(n, div) }
end
end

def footnotes(docxml, div)
docxml.xpath(ns("/*/fmt-footnote-container"))
.each do |fn|
fn.children.each { |n| parse(n, div) }
end
end
end
end
end
3 changes: 2 additions & 1 deletion lib/isodoc/function/to_word_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def make_body3(body, docxml)
body.div class: "main-section" do |div3|
boilerplate docxml, div3
content(div3, docxml, ns(self.class::TOP_ELEMENTS))
footnotes div3
footnotes docxml, div3
comments div3
end
end
Expand Down Expand Up @@ -286,6 +286,7 @@ def parse(node, out)
when "amend" then amend_parse(node, out)
when "date" then date_parse(node, out)
when "fmt-date" then fmt_date_parse(node, out)
when "fmt-fn-body" then fmt_fn_body_parse(node, out)
else error_parse(node, out)
end
end
Expand Down
7 changes: 1 addition & 6 deletions lib/isodoc/html_function/footnotes.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
module IsoDoc
module HtmlFunction
module Footnotes
def footnotes(div)
return if @footnotes.empty?

@footnotes.each { |fn| div.parent << fn }
end

def make_table_footnote_link(out, fnid, fnref)
attrs = { href: "##{fnid}", class: "TableFootnoteRef" }
out.a **attrs do |a|
Expand Down Expand Up @@ -35,6 +29,7 @@ def make_table_footnote_text(node, fnid, fnref)
end.join("\n")
end

# KILL
def make_generic_footnote_text(node, fnid)
noko do |xml|
xml.aside id: "fn:#{fnid}", class: "footnote" do |div|
Expand Down
35 changes: 18 additions & 17 deletions lib/isodoc/presentation_function/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class PresentationXMLConvert < ::IsoDoc::Convert
def lower2cap(text)
text.nil? and return text
x = Nokogiri::XML("<a>#{text}</a>")
firsttext = x.at(".//text()[string-length(normalize-space(.))>0]") or return text
firsttext = x.at(".//text()[string-length(normalize-space(.))>0]") or
return text
/^[[:upper:]][[:upper:]]/.match?(firsttext.text) and return text
firsttext.replace(firsttext.text.capitalize)
to_xml(x.root.children)
Expand Down Expand Up @@ -80,16 +81,13 @@ def admonition1(elem)
end

def admonition_numbered1(elem)
# elem["unnumbered"] && !elem.at(ns("./name")) and return
label = admonition_label(elem, @xrefs.anchor(elem["id"], :label, false))
prefix_name(elem, { caption: block_delim }, label, "name")
end

def admonition_label(elem, num)
lbl = if elem["type"] == "box" then @i18n.box
else @i18n.admonition[elem["type"]]&.upcase end
#lbl &&= "<span class='fmt-element-name'>#{lbl}</span>"
#num and lbl = l10n("#{lbl} #{autonum(elem['id'], num)}")
labelled_autonum(lbl, elem["id"], num)
end

Expand All @@ -107,8 +105,6 @@ def table1(elem)
labelled_ancestor(elem) and return
elem["unnumbered"] && !elem.at(ns("./name")) and return
n = @xrefs.anchor(elem["id"], :label, false)
#lbl = "<span class='fmt-element-name'>#{lower2cap @i18n.table}</span> "\
#"#{autonum(elem['id'], n)}"
lbl = labelled_autonum(lower2cap(@i18n.table), elem["id"], n)
prefix_name(elem, { caption: table_delim }, l10n(lbl), "name")
end
Expand All @@ -128,7 +124,8 @@ def table_long_strings_cleanup(docxml)
end
end

def table_fn(elem)
# KILL
def table_fnx(elem)
(elem.xpath(ns(".//fn")) - elem.xpath(ns("./name//fn")))
.each_with_index do |f, i|
table_fn1(elem, f, i)
Expand Down Expand Up @@ -233,19 +230,23 @@ def quote1(elem)
author = elem.at(ns("./author"))
source = elem.at(ns("./source"))
author.nil? && source.nil? and return
p = quote_attribution(author, source, elem)
elem << "<attribution><p>#{l10n p}</p></attribution>"
end

# e["deleteme"]: duplicate of source, will be duplicated in fmt-eref, need to delete after
def quote_attribution(author, source, elem)
p = "&#x2014; "
p += to_xml(semx_fmt_dup(author)) if author
p += ", " if author && source
if source
s = semx_fmt_dup(source)
e = Nokogiri::XML::Node.new("eref", elem.document)
e << s.children
s << e
source.attributes.each_key { |k| e[k] = source[k] }
e["deleteme"] = "true" # duplicate of source, will be duplicated in fmt-eref, need to delete after
p += to_xml(s)
end
elem << "<attribution><p>#{l10n p}</p></attribution>"
source or return p
s = semx_fmt_dup(source)
e = Nokogiri::XML::Node.new("eref", elem.document)
e << s.children
s << e
source.attributes.each_key { |k| e[k] = source[k] }
e["deleteme"] = "true"
p + to_xml(s)
end
end
end
15 changes: 7 additions & 8 deletions lib/isodoc/presentation_function/concepts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def concept1(node)
end

def concept_render(node, defaults)
#require "debug"; binding.b
opts, render, ref, ret = concept_render_init(node, defaults)
ret&.at(ns("./refterm"))&.remove
ref && opts[:ref] != "false" and render&.next = " "
Expand All @@ -31,7 +30,8 @@ def concept_render(node, defaults)
end

def concept_dup(node, ret)
node.xpath(".//xmlns:semx[xmlns:fmt-xref | xmlns:fmt-eref | xmlns:fmt-origin | xmlns:fmt-link]").each(&:remove)
node.xpath(".//xmlns:semx[xmlns:fmt-xref | xmlns:fmt-eref | " \
"xmlns:fmt-origin | xmlns:fmt-link]").each(&:remove)
ret.xpath(ns(".//xref | .//eref | .//origin | .//link")).each(&:remove)
ret.xpath(ns(".//semx")).each do |s|
s.children.empty? and s.remove
Expand Down Expand Up @@ -66,10 +66,11 @@ def concept1_linkmention(ref, renderterm, opts)
(opts[:linkmention] == "true" && !renderterm.nil? && !ref.nil?) or return
ref2 = ref.clone
r2 = renderterm.clone
#renderterm.replace(ref2).children = r2
ref2.children = r2
if ref.parent.name == "semx"
renderterm.replace("<semx element='#{ref.parent['element']}' source='#{ref.parent['source']}'>#{to_xml(ref2)}</semx>")
renderterm.replace(<<~SEMX)
<semx element='#{ref.parent['element']}' source='#{ref.parent['source']}'>#{to_xml(ref2)}</semx>
SEMX
else
renderterm.replace(ref2)
end
Expand Down Expand Up @@ -103,7 +104,7 @@ def related1(node)
p, ref, orig = related1_prep(node)
label = @i18n.relatedterms[orig["type"]].upcase
if p && ref
node.children =(l10n("<p><strong>#{label}:</strong> " \
node.children = (l10n("<p><strong>#{label}:</strong> " \
"<em>#{to_xml(p)}</em> (#{Common::to_xml(ref)})</p>"))
else
node.children = (l10n("<p><strong>#{label}:</strong> " \
Expand Down Expand Up @@ -198,8 +199,6 @@ def designation1(desgn)
def designation_annotate(desgn, name, orig)
designation_boldface(desgn)
designation_field(desgn, name, orig)
#g = desgn.at(ns("./expression/grammar")) and
#name << ", #{designation_grammar(g).join(', ')}"
designation_grammar(desgn, name)
designation_localization(desgn, name, orig)
designation_pronunciation(desgn, name)
Expand All @@ -213,7 +212,7 @@ def designation_boldface(desgn)
name.children = "<strong>#{name.children}</strong>"
end

def designation_field(desgn, name, orig)
def designation_field(_desgn, name, orig)
f = orig.xpath(ns("./field-of-application | ./usage-info"))
&.map { |u| to_xml(semx_fmt_dup(u)) }&.join(", ")
f&.empty? and return nil
Expand Down
5 changes: 2 additions & 3 deletions lib/isodoc/presentation_function/erefs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class PresentationXMLConvert < ::IsoDoc::Convert
def citeas(xmldoc)
xmldoc.xpath(ns("//fmt-eref | //fmt-origin | //fmt-link"))
.each do |e|
sem_xml_descendant?(e) and next
sem_xml_descendant?(e) and next
e["bibitemid"] && e["citeas"] or next
a = @xrefs.anchor(e["bibitemid"], :xref, false) or next
e["citeas"] = citeas_cleanup(a)
Expand Down Expand Up @@ -35,7 +35,6 @@ def erefstack1(elem)
ret = resolve_eref_connectives(locs)
elem["id"] ||= "_#{UUIDTools::UUID.random_create}"
elem.next = "<semx element='erefstack' source='#{elem['id']}'>#{ret[1]}</semx>"
#elem.replace(ret[1])
end

def eref_localities(refs, target, node)
Expand Down Expand Up @@ -198,7 +197,7 @@ def eref2link(docxml)
docxml.xpath(ns("//display-text")).each { |f| f.replace(f.children) }
docxml.xpath(ns("//fmt-eref | //fmt-origin[not(.//termref)]"))
.each do |e|
sem_xml_descendant?(e) and next
sem_xml_descendant?(e) and next
href = eref_target(e) or next
e.xpath(ns("./locality | ./localityStack")).each(&:remove)
if href[:type] == :anchor then eref2xref(e)
Expand Down
63 changes: 63 additions & 0 deletions lib/isodoc/presentation_function/footnotes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module IsoDoc
class PresentationXMLConvert < ::IsoDoc::Convert
def footnote_collect(fnotes)
seen = {}
ret = fnotes.each_with_object([]) do |x, m|
x["id"] ||= "_#{UUIDTools::UUID.random_create}"
seen[x["reference"]] or m << fnbody(x, seen)
x["target"] = seen[x["reference"]]
end
footnote_container(fnotes, ret)
end

def footnote_container(fnotes, fnbodies)
fnbodies.empty? and return
ctr = Nokogiri::XML::Node.new("fmt-footnote-container",
fnotes.first.document)
fnbodies.each { |x| ctr << x }
ctr
end

def fnbody(fnote, seen)
body = Nokogiri::XML::Node.new("fmt-fn-body", fnote.document)
body["id"] = "_#{UUIDTools::UUID.random_create}"
body["target"] = fnote["id"]
body["reference"] = fnote["reference"]
body << semx_fmt_dup(fnote)
insert_fn_ref(fnote, body)
seen[fnote["reference"]] = body["id"]
body
end

def insert_fn_ref(fnote, body)
ins = body.at(ns(".//p")) ||
body.at(ns("./semx")).children.first.before("<p> </p>").previous
lbl = fn_label(fnote)
ins.children.first.previous = <<~FNOTE
<span class="fmt-footnote-label"><sup>#{lbl}</sup><span class="fmt-caption-delim"><tab/></span>
FNOTE
end

def fn_label(fnote)
<<~FNOTE
<semx element="autonum" source="#{fnote['id']}">#{fnote['reference']}</semx>
FNOTE
end

def table_fn(elem)
fns = footnote_collect((elem.xpath(ns(".//fn")) -
elem.xpath(ns("./name//fn")))) and
elem << fns
end

def document_footnotes(docxml)
fns = docxml.xpath(ns("//fn"))
table_fns = docxml.xpath(ns("//table//fn")) - docxml.xpath(ns("//table/name//fn"))
fig_fns = docxml.xpath(ns("//figure//fn")) - docxml.xpath(ns("//figure/name//fn"))
fns = footnote_collect(fns - table_fns - fig_fns)
if fns
docxml.root << fns
end
end
end
end
21 changes: 8 additions & 13 deletions lib/isodoc/presentation_function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,19 @@ def xref_empty?(node)
def anchor_id_postprocess(node); end

def xref(docxml)
#docxml.xpath(ns("//display-text")).each { |f| f.replace(f.children) }
docxml.xpath(ns("//fmt-xref")).each { |f| xref1(f) }
docxml.xpath(ns("//fmt-xref//fmt-xref")).each { |f| f.replace(f.children) }
docxml.xpath(ns("//fmt-xref//fmt-xref")).each do |f|
f.replace(f.children)
end
docxml.xpath(ns("//fmt-xref//xref")).each { |f| f.replace(f.children) }
end

def eref(docxml)
docxml.xpath(ns("//eref[@deleteme]")).each { |f| redundant_eref(f) }
docxml.xpath(ns("//fmt-eref")).each { |f| xref1(f) }
docxml.xpath(ns("//fmt-eref//fmt-xref")).each { |f| f.replace(f.children) }
docxml.xpath(ns("//fmt-eref//fmt-xref")).each do |f|
f.replace(f.children)
end
docxml.xpath(ns("//erefstack")).each { |f| erefstack1(f) }
end

Expand All @@ -65,14 +68,6 @@ def origin(docxml)
docxml.xpath(ns("//fmt-origin[not(.//termref)]")).each { |f| xref1(f) }
end

# KILL
def quotesourcex(docxml)
docxml.xpath(ns("//quote//source")).each { |f| xref1(f) }
docxml.xpath(ns("//quote//source//xref")).each do |f|
f.replace(f.children)
end
end

# do not change to Presentation XML rendering
def sem_xml_descendant?(node)
!node.ancestors("preferred, admitted, deprecated, related, " \
Expand Down Expand Up @@ -112,8 +107,8 @@ def identifier(docxml)
docxml.xpath(ns("//identifier")).each do |n|
%w(bibdata bibitem requirement recommendation permission)
.include?(n.parent.name) and next
s = semx_fmt_dup(n)
n.next = "<fmt-identifier><tt>#{to_xml(s)}</tt></fmt-identifier>"
s = semx_fmt_dup(n)
n.next = "<fmt-identifier><tt>#{to_xml(s)}</tt></fmt-identifier>"
end
end

Expand Down
11 changes: 8 additions & 3 deletions lib/isodoc/presentation_function/refs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ def bibrender_item(xml, renderings)
def bibrender_formattedref(formattedref, xml); end

def bibrender_relaton(xml, renderings)
f = renderings[xml["id"]][:formattedref]
f = renderings[xml["id"]][:formattedref] or return
f &&= "<formattedref>#{f}</formattedref>"
x = xml.xpath(ns("./docidentifier | ./uri | ./note | ./biblio-tag"))
xml.children = "#{f}#{x.to_xml}"
if x = xml.at(ns("./formattedref"))
x.replace(f)
elsif xml.children.empty?
xml << f
else
xml.children.first.previous = f
end
end

def citestyle
Expand Down
2 changes: 2 additions & 0 deletions lib/isodoc/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
require_relative "presentation_function/index"
require_relative "presentation_function/bibdata"
require_relative "presentation_function/metadata"
require_relative "presentation_function/footnotes"

module IsoDoc
class PresentationXMLConvert < ::IsoDoc::Convert
Expand Down Expand Up @@ -68,6 +69,7 @@ def section(docxml)
index docxml # fed by strip_duplicate_ids
toc docxml
display_order docxml
document_footnotes docxml
end

def block(docxml)
Expand Down
2 changes: 1 addition & 1 deletion lib/isodoc/word_function/body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def make_body2(body, docxml)
def make_body3(body, docxml)
body.div class: "WordSection3" do |div3|
content(div3, docxml, ns(self.class::MAIN_ELEMENTS))
footnotes div3
footnotes docxml, div3
comments div3
end
end
Expand Down
Loading
Loading