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

Fix/eref display text #648

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6ac3716
Presentation XML, dates: https://github.com/metanorma/isodoc/issues/642
opoudjis Feb 5, 2025
81ee58c
Presentation XML: stem: https://github.com/metanorma/isodoc/issues/642
opoudjis Feb 6, 2025
0fafe16
presentation XML: concepts: https://github.com/metanorma/isodoc/issue…
opoudjis Feb 6, 2025
2f6eca0
https://github.com/metanorma/metanorma-standoc/issues/952
opoudjis Feb 8, 2025
8e582f3
ignore display-text in Presentation XML: https://github.com/metanorma…
opoudjis Feb 8, 2025
914c531
eref, xref, origin, link Presentation XML: https://github.com/metanor…
opoudjis Feb 8, 2025
f14421a
Merge branch 'fix/fmt-concept' into fix/eref-display-text
opoudjis Feb 8, 2025
e1ad499
https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 8, 2025
32c5cc2
https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 8, 2025
2dbd539
https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 9, 2025
32af619
https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 9, 2025
691a965
https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 9, 2025
3402c62
https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 9, 2025
dae237e
https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 9, 2025
c0b6f82
https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 10, 2025
6df0983
https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 10, 2025
bbfe98e
retain svgmap: https://github.com/metanorma/isodoc/issues/641
opoudjis Feb 11, 2025
d2ce56d
Presentation XML: sourcecode: https://github.com/metanorma/isodoc/iss…
opoudjis Feb 11, 2025
f09f64e
quote/source and amend PresentationXML: https://github.com/metanorma/…
opoudjis Feb 12, 2025
cf41ae1
Merge branch 'fix/fmt-date-number' into fix/eref-display-text
opoudjis Feb 12, 2025
2f1a1f3
Merge branch 'fix/fmt-sourcecode' into fix/eref-display-text
opoudjis Feb 12, 2025
4bba146
Do not generate Presentation XML for sourcecode, stem under Semantic …
opoudjis Feb 13, 2025
ad6ce1b
rspec
opoudjis Feb 13, 2025
29b5e08
Do not generate Presentation XML for sourcecode, stem under Semantic …
opoudjis Feb 13, 2025
87152b4
rspec
opoudjis Feb 13, 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
15 changes: 9 additions & 6 deletions lib/isodoc/function/blocks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def pseudocode_attrs(node)
def pseudocode_parse(node, out)
@in_figure = true
name = node.at(ns("./fmt-name"))
s = node.at(ns("./fmt-figure")) || node
out.div **pseudocode_attrs(node) do |div|
node.children.each { |n| parse(n, div) unless n.name == "fmt-name" }
s.children.each { |n| parse(n, div) unless n.name == "fmt-name" }
sourcecode_name_parse(node, div, name)
end
@in_figure = false
Expand All @@ -58,10 +59,12 @@ def sourcecode_attrs(node)

def sourcecode_parse(node, out)
name = node.at(ns("./fmt-name"))
n = node.at(ns("./fmt-sourcecode"))
s = n || node
out.p **sourcecode_attrs(node) do |div|
sourcecode_parse1(node, div)
sourcecode_parse1(s, div)
end
annotation_parse(node, out)
annotation_parse(s, out)
sourcecode_name_parse(node, out, name)
end

Expand Down Expand Up @@ -92,7 +95,7 @@ def annotation_parse(node, out)
def formula_parse1(node, out)
out.div **attr_code(class: "formula") do |div|
div.p do |_p|
parse(node.at(ns("./stem")), div)
parse(node.at(ns("./fmt-stem")), div)
if lbl = node&.at(ns("./fmt-name"))&.text
insert_tab(div, 1)
div << lbl
Expand All @@ -109,7 +112,7 @@ def formula_parse(node, out)
out.div **formula_attrs(node) do |div|
formula_parse1(node, div)
node.children.each do |n|
%w(stem fmt-name).include? n.name and next
%w(stem fmt-name fmt-stem).include? n.name and next
parse(n, div)
end
end
Expand Down Expand Up @@ -148,7 +151,7 @@ def quote_parse(node, out)
attrs = para_attrs(node)
attrs[:class] = "Quote"
out.div **attr_code(attrs) do |p|
node.children.each { |n| parse(n, p) }
node.children.each { |n| parse(n, p) unless n.name == "source" }
end
end

Expand Down
32 changes: 25 additions & 7 deletions lib/isodoc/function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ def termrefelem_parse(node, out)
end

def stem_parse(node, out)
ret = node.at(ns("./semx[@element = 'stem']")) || node
ooml = case node["type"]
when "AsciiMath" then asciimath_parse(node)
when "MathML" then mathml_parse(node)
when "LaTeX" then latexmath_parse(node)
else HTMLEntities.new.encode(node.text)
when "AsciiMath" then asciimath_parse(ret)
when "MathML" then mathml_parse(ret)
when "LaTeX" then latexmath_parse(ret)
else HTMLEntities.new.encode(ret.text)
end
out.span class: "stem" do |span|
span.parent.add_child ooml
Expand Down Expand Up @@ -188,9 +189,7 @@ def rb_parse(node, out)
end
end

def author_parse(node, out)
children_parse(node, out)
end
def author_parse(node, out); end

def semx_parse(node, out)
children_parse(node, out)
Expand All @@ -204,9 +203,20 @@ def xref_label_parse(node, out); end

def name_parse(node, out); end
def semx_definition_parse(node, out); end
def semx_xref_parse(node, out); end
def semx_eref_parse(node, out); end
def semx_link_parse(node, out); end
def semx_origin_parse(node, out); end
def date_parse(node, out); end
def semx_stem_parse(node, out); end

def floating_title_parse(node, out); end
def identifier_parse(node, out); end
def concept_parse(node, out); end
def erefstack_parse(node, out); end
def svgmap_parse(node, out); end
def amend_parse(node, out); end
def semx_sourcecode_parse(node, out); end

def fmt_name_parse(node, out)
children_parse(node, out)
Expand All @@ -215,6 +225,14 @@ def fmt_name_parse(node, out)
def fmt_identifier_parse(node, out)
children_parse(node, out)
end

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

def fmt_date_parse(node, out)
children_parse(node, out)
end
end
end
end
23 changes: 17 additions & 6 deletions lib/isodoc/function/to_word_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,17 @@ def parse(node, out)
when "bookmark" then bookmark_parse(node, out)
when "pagebreak" then pagebreak_parse(node, out)
when "callout" then callout_parse(node, out)
when "stem" then stem_parse(node, out)
when "fmt-stem" then stem_parse(node, out)
when "stem" then semx_stem_parse(node, out)
when "clause" then clause_parse(node, out)
when "xref" then xref_parse(node, out)
when "eref" then eref_parse(node, out)
when "origin" then origin_parse(node, out)
when "link" then link_parse(node, out)
when "xref" then semx_xref_parse(node, out)
when "fmt-xref" then xref_parse(node, out)
when "eref" then semx_eref_parse(node, out)
when "fmt-eref" then eref_parse(node, out)
when "origin" then semx_origin_parse(node, out)
when "fmt-origin" then origin_parse(node, out)
when "link" then semx_link_parse(node, out)
when "fmt-link" then link_parse(node, out)
when "ul" then ul_parse(node, out)
when "ol" then ol_parse(node, out)
when "li" then li_parse(node, out)
Expand Down Expand Up @@ -245,7 +250,6 @@ def parse(node, out)
when "legal-statement" then legal_parse(node, out)
when "feedback-statement" then feedback_parse(node, out)
when "passthrough" then passthrough_parse(node, out)
when "amend" then amend_parse(node, out)
when "tab" then clausedelimspace(node, out) # in Presentation XML only
when "svg" then svg_parse(node, out) # in Presentation XML only
when "add" then add_parse(node, out)
Expand Down Expand Up @@ -275,6 +279,13 @@ def parse(node, out)
when "floating-title" then floating_title_parse(node, out)
when "fmt-identifier" then fmt_identifier_parse(node, out)
when "identifier" then identifier_parse(node, out)
when "fmt-concept" then fmt_concept_parse(node, out)
when "concept" then concept_parse(node, out)
when "erefstack" then erefstack_parse(node, out)
when "svgmap" then svgmap_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)
else error_parse(node, out)
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/isodoc/html_function/html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ def html_main(docxml)
def sourcecode_parse(node, out)
name = node.at(ns("./fmt-name"))
tag = node.at(ns(".//sourcecode | .//table")) ? "div" : "pre"
n = node.at(ns("./fmt-sourcecode"))
s = n || node
attr = sourcecode_attrs(node).merge(class: "sourcecode")
out.send tag, **attr do |div|
sourcecode_parse1(node, div)
sourcecode_parse1(s, div)
end
annotation_parse(node, out)
annotation_parse(s, out)
sourcecode_name_parse(node, out, name)
end

Expand Down
22 changes: 14 additions & 8 deletions lib/isodoc/presentation_function/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,18 @@ def table_fn(elem)

def table_fn1(table, fnote, idx); end

# we use this to eliminate the semantic amend blocks from rendering
def amend(docxml)
docxml.xpath(ns("//amend")).each { |f| amend1(f) }
end

def amend1(elem)
elem.xpath(ns("./locality | ./localityStack | ./autonumber | " \
ret = semx_fmt_dup(elem)
ret.xpath(ns("./locality | ./localityStack | ./autonumber | " \
"./classification | ./contributor")).each(&:remove)
elem.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
elem.xpath(ns("./description")).each { |a| a.replace(a.children) }
elem.replace(elem.children)
ret.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
ret.xpath(ns("./description")).each { |a| a.replace(a.children) }
elem.xpath(ns(".//fmt-name | .//fmt-xref-label")).each(&:remove)
elem.next = ret
end

def dl(docxml)
Expand Down Expand Up @@ -233,11 +234,16 @@ def quote1(elem)
source = elem.at(ns("./source"))
author.nil? && source.nil? and return
p = "&#x2014; "
p += author.remove.to_xml if author
p += to_xml(semx_fmt_dup(author)) if author
p += ", " if author && source
if source
source.name = "eref"
p += source.remove.to_xml
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>"
end
Expand Down
50 changes: 37 additions & 13 deletions lib/isodoc/presentation_function/concepts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def concept(docxml)

def concept1(node)
node.ancestors("definition, termsource, related").empty? or return
xref = node&.at(ns("./xref/@target"))&.text or
xref = node&.at(ns("./semx/fmt-xref/@target"))&.text or
return concept_render(node, ital: "true", ref: "true", bold: "false",
linkref: "true", linkmention: "false")
if @definition_ids[xref]
Expand All @@ -20,13 +20,25 @@ def concept1(node)
end

def concept_render(node, defaults)
opts, render, ref = concept_render_init(node, defaults)
node&.at(ns("./refterm"))&.remove
#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 = " "
concept1_linkmention(ref, render, opts)
concept1_ref(node, ref, opts)
concept1_style(node, opts)
node.replace(node.children)
concept1_ref(ret, ref, opts)
concept1_style(ret, opts)
concept_dup(node, ret)
end

def concept_dup(node, ret)
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
end
f = Nokogiri::XML::Node.new("fmt-concept", node.document)
f << ret
node.next = f
end

def concept1_style(node, opts)
Expand All @@ -38,25 +50,37 @@ def concept1_style(node, opts)
end

def concept_render_init(node, defaults)
opts = %i(bold ital ref linkref linkmention)
opts = concept_render_opts(node, defaults)
ret = semx_fmt_dup(node)
ret.children.each { |x| x.text? and x.remove }
[opts, ret.at(ns("./renderterm")),
ret.at(ns("./semx/fmt-xref | ./semx/fmt-eref | ./termref")), ret]
end

def concept_render_opts(node, defaults)
%i(bold ital ref linkref linkmention)
.each_with_object({}) { |x, m| m[x] = node[x.to_s] || defaults[x] }
[opts, node.at(ns("./renderterm")),
node.at(ns("./xref | ./eref | ./termref"))]
end

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
#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>")
else
renderterm.replace(ref2)
end
end

def concept1_ref(_node, ref, opts)
ref.nil? and return
opts[:ref] == "false" and return ref.remove
concept1_ref_content(ref)
%w(xref eref).include? ref.name and get_linkend(ref)
opts[:linkref] == "false" && %w(xref eref).include?(ref.name) and
%w(fmt-xref fmt-eref).include? ref.name and get_linkend(ref)
opts[:linkref] == "false" && %w(fmt-xref fmt-eref).include?(ref.name) and
ref.replace(ref.children)
end

Expand All @@ -65,7 +89,7 @@ def concept1_ref_content(ref)
foll = "]"
non_locality_elems(ref).select do |c|
!c.text? || /\S/.match(c)
end.empty? and
end.empty? or
(prev, foll = @i18n.term_defined_in.split("%"))
ref.previous = prev
ref.next = foll
Expand Down
19 changes: 11 additions & 8 deletions lib/isodoc/presentation_function/erefs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
module IsoDoc
class PresentationXMLConvert < ::IsoDoc::Convert
def citeas(xmldoc)
xmldoc.xpath(ns("//eref | //origin | //quote//source | //link"))
xmldoc.xpath(ns("//fmt-eref | //fmt-origin | //fmt-link"))
.each do |e|
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)
# link generated in collection postprocessing from eref
e.name == "link" && e.text.empty? and e.children = e["citeas"]
e.name == "fmt-link" && e.text.empty? and e.children = e["citeas"]
end
end

Expand All @@ -29,11 +29,13 @@ def expand_citeas(text)
end

def erefstack1(elem)
locs = elem.xpath(ns("./eref")).map do |e|
[e["connective"], to_xml(e)]
locs = elem.xpath(ns("./semx/fmt-eref")).map do |e|
[e["connective"], to_xml(e.parent.remove)]
end.flatten
ret = resolve_eref_connectives(locs)
elem.replace(ret[1])
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 @@ -193,7 +195,8 @@ def eref_locality_populate(type, node, number)
end

def eref2link(docxml)
docxml.xpath(ns("//eref | //origin[not(termref)] | //quote//source"))
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
href = eref_target(e) or next
Expand All @@ -205,7 +208,7 @@ def eref2link(docxml)
end

def eref2xref(node)
node.name = "xref"
node.name = "fmt-xref"
node["target"] = node["bibitemid"]
node.delete("bibitemid")
node.delete("citeas")
Expand All @@ -215,7 +218,7 @@ def eref2xref(node)
def eref2link1(node, href)
url = href[:link]
att = href[:type] == :attachment ? "attachment='true'" : ""
repl = "<link #{att} target='#{url}'>#{node.children}</link>"
repl = "<fmt-link #{att} target='#{url}'>#{node.children}</link>"
node["type"] == "footnote" and repl = "<sup>#{repl}</sup>"
node.replace(repl)
end
Expand Down
7 changes: 5 additions & 2 deletions lib/isodoc/presentation_function/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ def svg_wrap(elem)
end

def svgmap_extract(elem)
if f = elem.at(ns("./figure")) then elem.replace(f)
else elem.remove
if elem.at(ns("./figure"))# then elem.replace(f)
n = semx_fmt_dup(elem)
n.xpath(ns("./target")).each(&:remove)
elem.next = n
#else elem.remove
end
end

Expand Down
Loading
Loading