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 17 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
8 changes: 8 additions & 0 deletions lib/isodoc/function/blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ def cross_align_parse(node, out)
end

def columnbreak_parse(node, out); end

def fmt_fn_body_parse(node, out)
node.ancestors("table, figure").empty? and
node.at(ns(".//fmt-fn-label"))&.remove
out.aside id: "fn:#{node['reference']}", class: "footnote" do |div|
node.children.each { |n| parse(n, div) }
end
end
end
end
end
14 changes: 3 additions & 11 deletions lib/isodoc/function/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def passthrough_cleanup(docxml)
def cleanup(docxml)
@i18n ||= i18n_init(@lang, @script, @locale)
comment_cleanup(docxml)
footnote_cleanup(docxml)
#footnote_cleanup(docxml)
inline_header_cleanup(docxml)
figure_cleanup(docxml)
table_cleanup(docxml)
Expand Down Expand Up @@ -58,7 +58,7 @@ def inline_header_cleanup(docxml)
docxml
end

# todo PRESENTATION XML
# KILL
def footnote_cleanup(docxml)
docxml.xpath('//a[@class = "FootnoteRef"]/sup')
.each_with_index do |x, i|
Expand All @@ -80,7 +80,7 @@ def table_footnote_cleanup(docxml)
merge_fnref_into_fn_text(a)
a.name = "div"
a["class"] = "TableFootnote"
t << a.remove
t << a.remove # this is redundant
end
end
table_footnote_cleanup_propagate(docxml)
Expand Down Expand Up @@ -142,14 +142,6 @@ def table_cleanup(docxml)
end

def symbols_cleanup(docxml); end

def table_footnote_reference_format(link)
link
end

def footnote_reference_format(link)
link
end
end
end
end
8 changes: 8 additions & 0 deletions lib/isodoc/function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ def fmt_concept_parse(node, out)
def fmt_date_parse(node, out)
children_parse(node, out)
end

def fmt_fn_label_parse(node, out)
children_parse(node, out)
end

def fmt_footnote_container_parse(node, out)
children_parse(node, out)
end
end
end
end
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
2 changes: 2 additions & 0 deletions lib/isodoc/function/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def table_parse_tail(node, out)
(dl = node.at(ns("./dl"))) && parse(dl, out)
node.xpath(ns("./source")).each { |n| parse(n, out) }
node.xpath(ns("./note")).each { |n| parse(n, out) }
node.xpath(ns("./fmt-footnote-container/fmt-fn-body"))
.each { |n| parse(n, out) }
end

def table_parse_core(node, out)
Expand Down
5 changes: 4 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,9 @@ 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)
when "fmt-fn-label" then fmt_fn_label_parse(node, out)
when "fmt-footnote-container" then fmt_footnote_container_parse(node, out)
else error_parse(node, out)
end
end
Expand Down
47 changes: 31 additions & 16 deletions lib/isodoc/html_function/footnotes.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
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)
def make_table_footnote_link(out, fnid, node)
attrs = { href: "##{fnid}", class: "TableFootnoteRef" }
sup = node.at(ns("./sup")) and sup.replace(sup.children)
out.a **attrs do |a|
a << fnref
children_parse(node, a)
end
end

# KILL
def make_table_footnote_target(out, fnid, fnref)
attrs = { id: fnid, class: "TableFootnoteRef" }
out.span do |s|
Expand All @@ -25,6 +21,7 @@ def make_table_footnote_target(out, fnid, fnref)
end

# Move to Presentation XML, as <fmt-footnote>: it's a footnote body
# # KILL
def make_table_footnote_text(node, fnid, fnref)
attrs = { id: "fn:#{fnid}" }
noko do |xml|
Expand All @@ -35,6 +32,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 All @@ -45,40 +43,57 @@ def make_generic_footnote_text(node, fnid)

def get_table_ancestor_id(node)
table = node.ancestors("table") || node.ancestors("figure")
return UUIDTools::UUID.random_create.to_s if table.empty?

table.last["id"]
table.empty? and return [nil, UUIDTools::UUID.random_create.to_s]
[table.last, table.last["id"]]
end

# @seen_footnote:
# do not output footnote text if we have already seen it for this table

def table_footnote_parse(node, out)
fn = node["reference"] || UUIDTools::UUID.random_create.to_s
tid = get_table_ancestor_id(node)
make_table_footnote_link(out, tid + fn, fn)
table, tid = get_table_ancestor_id(node)
make_table_footnote_link(out, tid + fn, node.at(ns("./fmt-fn-label")))
return if @seen_footnote.include?(tid + fn)

update_table_fn_body_ref(node, table, tid + fn)
=begin
@in_footnote = true
out.aside class: "footnote" do |a|
a << make_table_footnote_text(node, tid + fn, fn)
end
@in_footnote = false
=end
@seen_footnote << (tid + fn)
end

def update_table_fn_body_ref(fnote, table, reference)
fnbody = table.at(ns("./fmt-footnote-container/" \
"fmt-fn-body[@id = '#{fnote['target']}']"))
fnbody["reference"] = reference
sup = fnbody.at(ns(".//fmt-fn-label/sup")) and sup.replace(sup.children)
fnbody.xpath(ns(".//fmt-fn-label")).each do |s|
s["class"] = "TableFootnoteRef"
s.name = "span"
d = s.at(ns("./span[@class = 'fmt-caption-delim']")) and
s.next = d
end
end

def footnote_parse(node, out)
return table_footnote_parse(node, out) if (@in_table || @in_figure) &&
!node.ancestors.map(&:name).include?("fmt-name")

fn = node["reference"] || UUIDTools::UUID.random_create.to_s
attrs = { class: "FootnoteRef", href: "#fn:#{fn}" }
f = node.at(ns("./fmt-fn-label"))
out.a **attrs do |a|
a.sup { |sup| sup << fn }
#a.sup { |sup| sup << fn }
children_parse(f, a)
end
make_footnote(node, fn)
#make_footnote(node, fn)
end

# KILL
def make_footnote(node, fnote)
return if @seen_footnote.include?(fnote)

Expand Down
3 changes: 2 additions & 1 deletion lib/isodoc/html_function/postprocess.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def html5(doc)

def html_cleanup(html)
html = term_header(html_footnote_filter(html_preface(htmlstyle(html))))
html = footnote_format(footnote_backlinks(html))
#html = footnote_format(footnote_backlinks(html))
html = (footnote_backlinks(html))
html = mathml(html_list_clean(remove_placeholder_paras(html)))
html_toc(heading_anchors(sourcecode_cleanup(html)))
end
Expand Down
3 changes: 2 additions & 1 deletion lib/isodoc/html_function/postprocess_footnotes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def footnote_backlinks(docxml)
docxml
end

def footnote_format(docxml)
# KILL
def footnote_formatx(docxml)
docxml.xpath("//a[@class = 'FootnoteRef']/sup").each do |x|
footnote_reference_format(x)
end
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
Loading
Loading