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 15 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
11 changes: 11 additions & 0 deletions lib/isodoc/function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,16 @@ 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 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 fmt_name_parse(node, out)
children_parse(node, out)
Expand All @@ -215,6 +222,10 @@ 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
end
end
end
16 changes: 12 additions & 4 deletions lib/isodoc/function/to_word_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,14 @@ def parse(node, out)
when "callout" then callout_parse(node, out)
when "stem" then 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 @@ -275,6 +279,10 @@ 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)
else error_parse(node, out)
end
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
23 changes: 12 additions & 11 deletions lib/isodoc/presentation_function/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def get_linkend(node)
# <locality type="section"><reference>3.1</reference></locality></origin>

def unnest_linkend(node)
node.at(ns("./xref[@nested]")) or return
node.xpath(ns("./xref[@nested]")).each { |x| x.delete("nested") }
node.at(ns("./fmt-xref[@nested]")) or return
node.xpath(ns("./fmt-xref[@nested]")).each { |x| x.delete("nested") }
node.xpath(ns("./location | ./locationStack")).each(&:remove)
node.replace(node.children)
end
Expand All @@ -39,21 +39,24 @@ def xref_empty?(node)
def anchor_id_postprocess(node); end

def xref(docxml)
docxml.xpath(ns("//xref")).each { |f| xref1(f) }
docxml.xpath(ns("//xref//xref")).each { |f| f.replace(f.children) }
#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//xref")).each { |f| f.replace(f.children) }
end

def eref(docxml)
docxml.xpath(ns("//eref")).each { |f| xref1(f) }
docxml.xpath(ns("//eref//xref")).each { |f| f.replace(f.children) }
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("//erefstack")).each { |f| erefstack1(f) }
end

def origin(docxml)
docxml.xpath(ns("//origin[not(termref)]")).each { |f| xref1(f) }
docxml.xpath(ns("//fmt-origin[not(.//termref)]")).each { |f| xref1(f) }
end

def quotesource(docxml)
# 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)
Expand All @@ -63,16 +66,14 @@ def quotesource(docxml)
# do not change to Presentation XML rendering
def sem_xml_descendant?(node)
!node.ancestors("related, definition, termsource").empty? and return true
!node.ancestors("xref, eref, origin, link").empty? and return true
!node.ancestors("requirement, recommendation, permission").empty? &&
node.ancestors("fmt-provision").empty? and return true
false
end

def xref1(node)
sem_xml_descendant?(node) and return
node.ancestors("related, definition, termsource").empty? or return
!node.ancestors("requirement, recommendation, permission").empty? &&
node.ancestors("fmt-provision").empty? and return
get_linkend(node)
end

Expand Down
15 changes: 14 additions & 1 deletion lib/isodoc/presentation_function/xrefs.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
module IsoDoc
class PresentationXMLConvert < ::IsoDoc::Convert
def fmt_ref(docxml)
docxml.xpath(ns("//xref | //eref | //origin | //link")).each do |x|
sem_xml_descendant?(x) and next
tag = x.name
y = Nokogiri::XML::Node.new("fmt-#{tag}", x.document)
x.attributes.each_key { |a| y[a] = x[a] }
n = semx_fmt_dup(x) # semx/fmt-xref for ease of processing
n.children.each { |c| y << c }
n << y
x.next = n
end
end

def prefix_container(container, linkend, node, target)
prefix_container?(container, node) or return linkend
container_container = @xrefs.anchor(container, :container, false)
Expand Down Expand Up @@ -126,7 +139,7 @@ def gather_xref_locations(node)

def loc2xref(entry)
if entry[:target]
"<xref nested='true' target='#{entry[:target]}'>#{entry[:label]}</xref>"
"<fmt-xref nested='true' target='#{entry[:target]}'>#{entry[:label]}</fmt-xref>"
else
entry[:label]
end
Expand Down
8 changes: 5 additions & 3 deletions lib/isodoc/presentation_xml_convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,13 @@ def block(docxml)

def inline(docxml)
bibitem_lookup(docxml) # feeds citeas
citeas docxml # feeds xref, eref, origin, quotesource
fmt_ref docxml # feeds citeas, xref, eref, origin, concept
citeas docxml # feeds xref, eref, origin, concept
xref docxml
eref docxml # feeds eref2link
origin docxml # feeds eref2link
quotesource docxml # feeds eref2link
#quotesource docxml # feeds eref2link
concept docxml
eref2link docxml
mathml docxml
ruby docxml
Expand All @@ -114,7 +116,7 @@ def terms(docxml)
termdefinition docxml
designation docxml
termsource docxml
concept docxml
#concept docxml
related docxml
termcleanup docxml
end
Expand Down
Loading
Loading