lib/isodoc/presentation_function/block.rb in isodoc-2.12.0 vs lib/isodoc/presentation_function/block.rb in isodoc-2.12.1
- old
+ new
@@ -14,12 +14,10 @@
end
def prefix_name(node, delim, number, elem)
number.nil? || number.empty? and return
unless name = node.at(ns("./#{elem}"))
- #(node.children.empty? and node.add_child("<#{elem}></#{elem}>")) or
- # node.children.first.previous = "<#{elem}></#{elem}>"
node.add_first_child "<#{elem}></#{elem}>"
name = node.children.first
end
if name.children.empty? then name.add_child(cleanup_entities(number.strip))
else (name.children.first.previous = "#{number.strip}#{delim}")
@@ -31,11 +29,11 @@
end
def formula1(elem)
formula_where(elem.at(ns("./dl")))
lbl = @xrefs.anchor(elem["id"], :label, false)
- prefix_name(elem, "", lbl, "name")
+ lbl.nil? || lbl.empty? or prefix_name(elem, "", "(#{lbl})", "name")
end
def formula_where(dlist)
dlist or return
dlist["class"] = "formula_dl"
@@ -58,45 +56,68 @@
def note(docxml)
docxml.xpath(ns("//note")).each { |f| note1(f) }
end
+ def note_delim(_elem)
+ ""
+ end
+
def note1(elem)
%w(bibdata bibitem).include?(elem.parent.name) ||
elem["notag"] == "true" and return
+ lbl = note_label(elem)
+ prefix_name(elem, "", lbl, "name")
+ end
+
+ def note_label(elem)
n = @xrefs.get[elem["id"]]
lbl = @i18n.note
(n.nil? || n[:label].nil? || n[:label].empty?) or
lbl = l10n("#{lbl} #{n[:label]}")
- prefix_name(elem, "", lbl, "name")
+ "#{lbl}#{note_delim(elem)}"
end
def admonition(docxml)
docxml.xpath(ns("//admonition")).each { |f| admonition1(f) }
end
def admonition1(elem)
if elem["type"] == "box"
admonition_numbered1(elem)
+ elsif elem["notag"] == "true" || elem.at(ns("./name"))
else
- elem["notag"] == "true" || elem.at(ns("./name")) and return
- prefix_name(elem, "", @i18n.admonition[elem["type"]]&.upcase, "name")
+ label = admonition_label(elem, nil)
+ prefix_name(elem, "", label, "name")
end
+ n = elem.at(ns("./name")) and n << admonition_delim(elem)
end
def admonition_numbered1(elem)
elem["unnumbered"] && !elem.at(ns("./name")) and return
- n = @xrefs.anchor(elem["id"], :label, false)
- prefix_name(elem, block_delim, l10n("#{@i18n.box} #{n}"), "name")
+ label = admonition_label(elem, @xrefs.anchor(elem["id"], :label, false))
+ prefix_name(elem, 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
+ num and lbl = l10n("#{lbl} #{num}")
+ lbl
+ end
+
+ def admonition_delim(_elem)
+ ""
+ end
+
def table(docxml)
table_long_strings_cleanup(docxml)
docxml.xpath(ns("//table")).each { |f| table1(f) }
end
def table1(elem)
+ table_fn(elem)
labelled_ancestor(elem) and return
elem["unnumbered"] && !elem.at(ns("./name")) and return
n = @xrefs.anchor(elem["id"], :label, false)
prefix_name(elem, block_delim, l10n("#{lower2cap @i18n.table} #{n}"),
"name")
@@ -111,10 +132,19 @@
n.content = ret
end
end
end
+ def table_fn(elem)
+ (elem.xpath(ns(".//fn")) - elem.xpath(ns("./name//fn")))
+ .each_with_index do |f, i|
+ table_fn1(elem, f, i)
+ end
+ end
+
+ 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
@@ -124,10 +154,12 @@
elem.xpath(ns("./newcontent")).each { |a| a.name = "quote" }
elem.xpath(ns("./description")).each { |a| a.replace(a.children) }
elem.replace(elem.children)
end
+ def dl(docxml); end
+
def ol(docxml)
docxml.xpath(ns("//ol")).each { |f| ol1(f) }
@xrefs.list_anchor_names(docxml.xpath(ns(@xrefs.sections_xpath)))
docxml.xpath(ns("//ol/li")).each { |f| ol_label(f) }
end
@@ -179,8 +211,26 @@
elem.children = l10n("[#{@i18n.source}: #{to_xml(elem.children).strip}]")
end
def source_modification(mod)
termsource_modification(mod.parent)
+ end
+
+ def quote(docxml)
+ docxml.xpath(ns("//quote")).each { |f| quote1(f) }
+ end
+
+ def quote1(elem)
+ author = elem.at(ns("./author"))
+ source = elem.at(ns("./source"))
+ author.nil? && source.nil? and return
+ p = "— "
+ p += author.remove.to_xml if author
+ p += ", " if author && source
+ if source
+ source.name = "eref"
+ p += source.remove.to_xml
+ end
+ elem << "<attribution><p>#{l10n p}</p></attribution>"
end
end
end