diff --git a/Gemfile.devel b/Gemfile.devel new file mode 100644 index 00000000..5f372fa8 --- /dev/null +++ b/Gemfile.devel @@ -0,0 +1,2 @@ +gem "mn-requirements", git: "https://github.com/metanorma/mn-requirements", branch: "feature/presxml-autonum" +gem "isodoc-i18n", git: "https://github.com/metanorma/isodoc-i18n", branch: "fix/markup-connectives" diff --git a/lib/isodoc-yaml/i18n-ar.yaml b/lib/isodoc-yaml/i18n-ar.yaml index ea242eec..75561774 100644 --- a/lib/isodoc-yaml/i18n-ar.yaml +++ b/lib/isodoc-yaml/i18n-ar.yaml @@ -33,15 +33,15 @@ internal_external_terms_boilerplate: | لأغراض هذه الوثيقة ،تنطبق المصطلحات والتعاريف الواردة في % وما يلي. no_information_available: "[لا توجد معلومات متاحة]" term_defined_in: "(%)" -binary_and: "%1 و %2" -multiple_and: "%1, و %2" -binary_or: "%1 او %2" -multiple_or: "%1, او %2" -chain_and: "%1 و %2" -chain_or: "%1 او %2" -chain_from: "%1 %من 2" -chain_to: "من %1 إلى %2" -nested_xref: "%1, %2" +binary_and: "%1 %2" +multiple_and: "%1, %2" +binary_or: "%1 ﺍﻭ %2" +multiple_or: "%1, ﺍﻭ %2" +chain_and: "%1 %2" +chain_or: "%1 ﺍﻭ %2" +chain_from: "%1 %ﻢﻧ 2" +chain_to: "ﻢﻧ %1 ﺈﻟﻯ %2" +nested_xref: "%1, %2" list_nested_xref: "%1 %2" ordinal_keys: [gender] SpelloutRules: diff --git a/lib/isodoc-yaml/i18n-de.yaml b/lib/isodoc-yaml/i18n-de.yaml index 60c1339e..3bc5a596 100644 --- a/lib/isodoc-yaml/i18n-de.yaml +++ b/lib/isodoc-yaml/i18n-de.yaml @@ -35,15 +35,15 @@ internal_external_terms_boilerplate: | Für die Zwecke dieses Dokuments gelten die in % und im Folgenden aufgeführten Begriffe und Definitionen. no_information_available: "[KEINE INFORMATION VERFÜGBAR]" term_defined_in: "(%)" -binary_and: "%1 und %2" -multiple_and: "%1, und %2" -binary_or: "%1 oder %2" -multiple_or: "%1, oder %2" -chain_and: "%1 und %2" -chain_or: "%1 oder %2" -chain_from: "%1 von %2" -chain_to: "%1 bis %2" -nested_xref: "%1, %2" +binary_and: "%1 und %2" +multiple_and: "%1, und %2" +binary_or: "%1 oder %2" +multiple_or: "%1, oder %2" +chain_and: "%1 und %2" +chain_or: "%1 oder %2" +chain_from: "%1 von %2" +chain_to: "%1 bis %2" +nested_xref: "%1, %2" list_nested_xref: "%1 %2" ordinal_keys: [gender,number] SpelloutRules: diff --git a/lib/isodoc-yaml/i18n-en.yaml b/lib/isodoc-yaml/i18n-en.yaml index c9b25975..c8edd54a 100644 --- a/lib/isodoc-yaml/i18n-en.yaml +++ b/lib/isodoc-yaml/i18n-en.yaml @@ -38,15 +38,15 @@ internal_external_terms_boilerplate: | For the purposes of this document, the terms and definitions given in % and the following apply. no_information_available: "[NO INFORMATION AVAILABLE]" term_defined_in: "(%)" -binary_and: "%1 and %2" -multiple_and: "%1, and %2" -binary_or: "%1 or %2" -multiple_or: "%1, or %2" -chain_and: "%1 and %2" -chain_or: "%1 or %2" -chain_from: "%1 from %2" -chain_to: "%1 to %2" -nested_xref: "%1, %2" +binary_and: "%1 and %2" +multiple_and: "%1, and %2" +binary_or: "%1 or %2" +multiple_or: "%1, or %2" +chain_and: "%1 and %2" +chain_or: "%1 or %2" +chain_from: "%1 from %2" +chain_to: "%1 to %2" +nested_xref: "%1, %2" list_nested_xref: "%1 %2" ordinal_keys: [] SpelloutRules: spellout-ordinal diff --git a/lib/isodoc-yaml/i18n-es.yaml b/lib/isodoc-yaml/i18n-es.yaml index ed7965f4..98467dae 100755 --- a/lib/isodoc-yaml/i18n-es.yaml +++ b/lib/isodoc-yaml/i18n-es.yaml @@ -37,15 +37,15 @@ internal_external_terms_boilerplate: | Para los propósitos de este documento, se aplican los términos y definiciones dados en % y los siguientes. no_information_available: "[NO HAY INFORMACIÓN DISPONIBLE]" term_defined_in: "(%)" -binary_and: "%1 y %2" -multiple_and: "%1, y %2" -binary_or: "%1 o %2" -multiple_or: "%1, o %2" -chain_and: "%1 y %2" -chain_or: "%1 o %2" -chain_from: "%1 del %2" -chain_to: "%1 al %2" -nested_xref: "%1, %2" +binary_and: "%1 y %2" +multiple_and: "%1, y %2" +binary_or: "%1 o %2" +multiple_or: "%1, o %2" +chain_and: "%1 y %2" +chain_or: "%1 o %2" +chain_from: "%1 del %2" +chain_to: "%1 al %2" +nested_xref: "%1, %2" list_nested_xref: "%1 %2" ordinal_keys: [gender,number] SpelloutRules: diff --git a/lib/isodoc-yaml/i18n-fr.yaml b/lib/isodoc-yaml/i18n-fr.yaml index 1d82812e..d780df3d 100644 --- a/lib/isodoc-yaml/i18n-fr.yaml +++ b/lib/isodoc-yaml/i18n-fr.yaml @@ -34,15 +34,15 @@ internal_external_terms_boilerplate: | Pour les besoins du présent document, les termes et définitions de % ainsi que les suivants, s’appliquent. no_information_available: "[PAS D’INFORMATION DISPONIBLE]" term_defined_in: "(%)" -binary_and: "%1 et %2" -multiple_and: "%1, et %2" -binary_or: "%1 ou %2" -multiple_or: "%1, ou %2" -chain_and: "%1 et %2" -chain_or: "%1 ou %2" -chain_from: "%1 de %2" -chain_to: "%1 à %2" -nested_xref: "%1, %2" +binary_and: "%1 et %2" +multiple_and: "%1, et %2" +binary_or: "%1 ou %2" +multiple_or: "%1, ou %2" +chain_and: "%1 et %2" +chain_or: "%1 ou %2" +chain_from: "%1 de %2" +chain_to: "%1 à %2" +nested_xref: "%1, %2" list_nested_xref: "%1 %2" ordinal_keys: [gender,number] SpelloutRules: diff --git a/lib/isodoc-yaml/i18n-ja.yaml b/lib/isodoc-yaml/i18n-ja.yaml index b7f72971..126923ab 100644 --- a/lib/isodoc-yaml/i18n-ja.yaml +++ b/lib/isodoc-yaml/i18n-ja.yaml @@ -34,16 +34,16 @@ internal_external_terms_boilerplate: | この規格で用いる主な用語及び定義は,次によるほか,% による。 no_information_available: "[情報はありません]" term_defined_in: "(%)" -binary_and: "%1 and %2" -multiple_and: "%1, and %2" -binary_or: "%1 or %2" -multiple_or: "%1, or %2" -chain_and: "%1 and %2" -chain_or: "%1 or %2" -chain_from: "%1 from %2" -chain_to: "%1~%2" -nested_xref: "%1の%2" -list_nested_xref: "%1の%2" +binary_and: "%1 及び %2" +multiple_and: "%1%2" +binary_or: "%1 または %2" +multiple_or: "%1 または %2" +chain_and: "%1 及び %2" +chain_or: "%1 または %2" +chain_from: "%1 から %2" +chain_to: "%1%2" +nested_xref: "%1%2" +list_nested_xref: "%1%2" no_conflate_xref_locations: true ordinal_keys: [] SpelloutRules: spellout-ordinal diff --git a/lib/isodoc-yaml/i18n-ru.yaml b/lib/isodoc-yaml/i18n-ru.yaml index b4e43d81..33d6f1ba 100755 --- a/lib/isodoc-yaml/i18n-ru.yaml +++ b/lib/isodoc-yaml/i18n-ru.yaml @@ -37,15 +37,15 @@ internal_external_terms_boilerplate: | Для целей этого документа применяются термины и определения, данные в % и следующие. no_information_available: "[ИНФОРМАЦИЯ ОТСУТСТВУЕТ]" term_defined_in: "(%)" -binary_and: "%1 и %2" -multiple_and: "%1, и %2" -binary_or: "%1 или %2" -multiple_or: "%1, или %2" -chain_and: "%1 и %2" -chain_or: "%1 или %2" -chain_from: "%1 от %2" -chain_to: "%1 до %2" -nested_xref: "%1, %2" +binary_and: "%1 и %2" +multiple_and: "%1, и %2" +binary_or: "%1 или %2" +multiple_or: "%1, или %2" +chain_and: "%1 и %2" +chain_or: "%1 или %2" +chain_from: "%1 от %2" +chain_to: "%1 до %2" +nested_xref: "%1, %2" list_nested_xref: "%1 %2" ordinal_keys: [gender,number,case] SpelloutRules: diff --git a/lib/isodoc-yaml/i18n-zh-Hans.yaml b/lib/isodoc-yaml/i18n-zh-Hans.yaml index f47fbb74..7d8f3118 100644 --- a/lib/isodoc-yaml/i18n-zh-Hans.yaml +++ b/lib/isodoc-yaml/i18n-zh-Hans.yaml @@ -36,15 +36,15 @@ internal_external_terms_boilerplate: | % 界定的以及下列术语和定义适用于本文件。 no_information_available: "[无资料]" term_defined_in: "(%)" -binary_and: "%1和%2" -multiple_and: "%1、和%2" -binary_or: "%1或%2" -multiple_or: "%1、或%2" -chain_and: "%1和%2" -chain_or: "%1或%2" -chain_from: "%1从%2" -chain_to: "%1到%2" -nested_xref: "%1, %2" +binary_and: "%1%2" +multiple_and: "%1%2" +binary_or: "%1%2" +multiple_or: "%1%2" +chain_and: "%1%2" +chain_or: "%1%2" +chain_from: "%1%2" +chain_to: "%1%2" +nested_xref: "%1, %2" list_nested_xref: "%1 %2" ordinal_keys: [] SpelloutRules: spellout-ordinal diff --git a/lib/isodoc/function/blocks.rb b/lib/isodoc/function/blocks.rb index d6ff41c2..eff94292 100644 --- a/lib/isodoc/function/blocks.rb +++ b/lib/isodoc/function/blocks.rb @@ -25,9 +25,9 @@ def figure_parse(node, out) def figure_parse1(node, out) out.div **figure_attrs(node) do |div| node.children.each do |n| - parse(n, div) unless n.name == "name" + parse(n, div) unless n.name == "fmt-name" end - figure_name_parse(node, div, node.at(ns("./name"))) + figure_name_parse(node, div, node.at(ns("./fmt-name"))) end end @@ -37,9 +37,9 @@ def pseudocode_attrs(node) def pseudocode_parse(node, out) @in_figure = true - name = node.at(ns("./name")) + name = node.at(ns("./fmt-name")) out.div **pseudocode_attrs(node) do |div| - node.children.each { |n| parse(n, div) unless n.name == "name" } + node.children.each { |n| parse(n, div) unless n.name == "fmt-name" } sourcecode_name_parse(node, div, name) end @in_figure = false @@ -57,7 +57,7 @@ def sourcecode_attrs(node) end def sourcecode_parse(node, out) - name = node.at(ns("./name")) + name = node.at(ns("./fmt-name")) out.p **sourcecode_attrs(node) do |div| sourcecode_parse1(node, div) end @@ -71,7 +71,7 @@ def sourcecode_parse1(node, div) node.at("./ancestor::xmlns:table[@class = 'rouge-line-table']") and @sourcecode = "table" node.children.each do |n| - %w(name dl).include?(n.name) and next + %w(fmt-name dl).include?(n.name) and next parse(n, div) end @sourcecode = false @@ -93,7 +93,7 @@ def formula_parse1(node, out) out.div **attr_code(class: "formula") do |div| div.p do |_p| parse(node.at(ns("./stem")), div) - if lbl = node&.at(ns("./name"))&.text + if lbl = node&.at(ns("./fmt-name"))&.text insert_tab(div, 1) div << lbl end @@ -109,7 +109,7 @@ def formula_parse(node, out) out.div **formula_attrs(node) do |div| formula_parse1(node, div) node.children.each do |n| - %w(stem name).include? n.name and next + %w(stem fmt-name).include? n.name and next parse(n, div) end end diff --git a/lib/isodoc/function/blocks_example_note.rb b/lib/isodoc/function/blocks_example_note.rb index bae0b76f..f518edf2 100644 --- a/lib/isodoc/function/blocks_example_note.rb +++ b/lib/isodoc/function/blocks_example_note.rb @@ -19,9 +19,9 @@ def example_div_attr(node) # used if we are boxing examples def example_div_parse(node, out) out.div **example_div_attr(node) do |div| - example_label(node, div, node.at(ns("./name"))) + example_label(node, div, node.at(ns("./fmt-name"))) node.children.each do |n| - parse(n, div) unless n.name == "name" + parse(n, div) unless n.name == "fmt-name" end end end @@ -39,10 +39,12 @@ def example_table_parse(node, out) out.table **example_table_attr(node) do |t| t.tr do |tr| tr.td **EXAMPLE_TBL_ATTR do |td| - example_label(node, td, node.at(ns("./name"))) + example_label(node, td, node.at(ns("./fmt-name"))) end tr.td **EXAMPLE_TD_ATTR do |td| - node.children.each { |n| parse(n, td) unless n.name == "name" } + node.children.each do |n| + parse(n, td) unless n.name == "fmt-name" + end end end end @@ -52,26 +54,45 @@ def example_parse(node, out) example_div_parse(node, out) end + def block_body_first_elem(node) + node.elements.each do |n| + %w(title fmt-title fmt-xref-label fmt-name name) + .include?(n.name) and next + return n + end + nil + end + + def starts_with_para?(node) + block_body_first_elem(node)&.name == "p" + end + + def note_p_class + nil + end + def note_p_parse(node, div) - name = node.at(ns("./name"))&.remove - div.p do |p| + name = node.at(ns("./fmt-name")) + para = node.at(ns("./p")) + div.p **attr_code(class: note_p_class) do |p| name and p.span class: "note_label" do |s| name.children.each { |n| parse(n, s) } end - insert_tab(p, 1) - node.first_element_child.children.each { |n| parse(n, p) } + #insert_tab(p, 1) # TODO to Presentation XML + children_parse(para, p) end - node.element_children[1..].each { |n| parse(n, div) } + para.xpath("./following-sibling::*").each { |n| parse(n, div) } end def note_parse1(node, div) - name = node.at(ns("./name")) and div.p do |p| - p.span class: "note_label" do |s| - name.remove.children.each { |n| parse(n, s) } + name = node.at(ns("./fmt-name")) and + div.p **attr_code(class: note_p_class) do |p| + p.span class: "note_label" do |s| + name.remove.children.each { |n| parse(n, s) } + end + #insert_tab(p, 1) # TODO to Presentation XML end - insert_tab(p, 1) - end - node.children.each { |n| parse(n, div) } + children_parse(node, div) end def keep_style(node) @@ -94,7 +115,7 @@ def note_attrs(node) def note_parse(node, out) @note = true out.div **note_attrs(node) do |div| - if node&.at(ns("./*[local-name() != 'name'][1]"))&.name == "p" + if starts_with_para?(node) note_p_parse(node, div) else note_parse1(node, div) @@ -105,7 +126,7 @@ def note_parse(node, out) def admonition_name_parse(_node, div, name) div.p class: "AdmonitionTitle", style: "text-align:center;" do |p| - name.children.each { |n| parse(n, p) } + children_parse(name, p) end end @@ -114,7 +135,7 @@ def admonition_class(_node) end def admonition_name(node, _type) - node&.at(ns("./name")) + node&.at(ns("./fmt-name")) end def admonition_attrs(node) @@ -124,7 +145,7 @@ def admonition_attrs(node) def admonition_parse(node, out) out.div **admonition_attrs(node) do |div| - if node&.at(ns("./*[local-name() != 'name'][1]"))&.name == "p" + if starts_with_para?(node) admonition_p_parse(node, div) else admonition_parse1(node, div) @@ -139,14 +160,16 @@ def admonition_p_parse(node, div) # code to allow name and first paragraph to be rendered in same block def admonition_name_in_first_para(node, div) + name = node.at(ns("./fmt-name")) + para = node.at(ns("./p")) div.p do |p| if name = admonition_name(node, node["type"])&.remove name.children.each { |n| parse(n, p) } - admonition_name_para_delim(p) + admonition_name_para_delim(p) # TODO to Presentation XML end - node.first_element_child.children.each { |n| parse(n, p) } + para.children.each { |n| parse(n, p) } end - node.element_children[1..].each { |n| parse(n, div) } + para.xpath("./following-sibling::*").each { |n| parse(n, div) } end def admonition_name_para_delim(para) @@ -158,7 +181,7 @@ def admonition_parse1(node, div) if name admonition_name_parse(node, div, name) end - node.children.each { |n| parse(n, div) unless n.name == "name" } + node.children.each { |n| parse(n, div) unless n.name == "fmt-name" } end end end diff --git a/lib/isodoc/function/inline.rb b/lib/isodoc/function/inline.rb index aedb28ba..6d299a5f 100644 --- a/lib/isodoc/function/inline.rb +++ b/lib/isodoc/function/inline.rb @@ -17,13 +17,20 @@ def link_parse(node, out) def location_parse(node, out); end + # Presentation XML classes which we need not pass on to HTML or DOC + 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].freeze + def span_parse(node, out) - if node["style"] || node["class"] + klass = node["style"] || node["class"] + if klass && !SPAN_UNWRAP_CLASSES.include?(klass) out.span **attr_code(style: node["style"], class: node["class"]) do |s| - node.children.each { |n| parse(n, s) } + children_parse(node, s) end - else node.children.each { |n| parse(n, out) } + else children_parse(node, out) end end @@ -48,9 +55,8 @@ def xref_parse(node, out) end def suffix_url(url) - return url if url.nil? || %r{^https?://|^#}.match?(url) - return url unless File.extname(url).empty? - + url.nil? || %r{^https?://|^#}.match?(url) and return url + File.extname(url).empty? or return url url.sub(/#{File.extname(url)}$/, ".html") end @@ -136,8 +142,7 @@ def smallcap_parse(node, xml) end def text_parse(node, out) - return if node.nil? || node.text.nil? - + node.nil? || node.text.nil? and return text = node.to_s @sourcecode == "pre" and text = text.gsub("\n", "
").gsub("
", "
 ") @@ -184,8 +189,26 @@ def rb_parse(node, out) end def author_parse(node, out) + children_parse(node, out) + end + + def semx_parse(node, out) + children_parse(node, out) + end + + def children_parse(node, out) node.children.each { |n| parse(n, out) } end + + def xref_label_parse(node, out); end + + def name_parse(node, out); end + + def floating_title_parse(node, out); end + + def fmt_name_parse(node, out) + children_parse(node, out) + end end end end diff --git a/lib/isodoc/function/lists.rb b/lib/isodoc/function/lists.rb index 823a1e61..b23d43fc 100644 --- a/lib/isodoc/function/lists.rb +++ b/lib/isodoc/function/lists.rb @@ -2,7 +2,7 @@ module IsoDoc module Function module Lists def list_title_parse(node, out) - name = node.at(ns("./name")) or return + name = node.at(ns("./fmt-name")) or return out.p class: "ListTitle" do |p| name.children&.each { |n| parse(n, p) } end @@ -16,7 +16,7 @@ def ul_parse(node, out) out.div **attr_code(class: "ul_wrap") do |div| list_title_parse(node, div) div.ul **attr_code(ul_attrs(node)) do |ul| - node.children.each { |n| n.name == "name" or parse(n, ul) } + node.children.each { |n| n.name == "fmt-name" or parse(n, ul) } end end end @@ -57,7 +57,7 @@ def ol_parse(node, out) out.div **attr_code(class: "ol_wrap") do |div| list_title_parse(node, div) div.ol **attr_code(ol_attrs(node)) do |ol| - node.children.each { |n| n.name == "name" or parse(n, ol) } + node.children.each { |n| n.name == "fmt-name" or parse(n, ol) } end end end @@ -106,7 +106,7 @@ def dl_parse(node, out) end def dl_parse_notes(node, out) - node.elements.reject { |n| dt_dd?(n) || n.name == "name" } + node.elements.reject { |n| dt_dd?(n) || n.name == "fmt-name" } .each { |n| parse(n, out) } end diff --git a/lib/isodoc/function/references.rb b/lib/isodoc/function/references.rb index 12042dc0..c547eb7f 100644 --- a/lib/isodoc/function/references.rb +++ b/lib/isodoc/function/references.rb @@ -26,7 +26,7 @@ def biblio_list(refs, div, biblio) i += 1 bibitem_entry(div, b, i, biblio) else - parse(b, div) unless %w(title).include? b.name + parse(b, div) unless %w(fmt-title).include? b.name end end end @@ -41,9 +41,9 @@ def norm_ref_xpath def norm_ref(node, out) node["hidden"] != "true" or return out.div do |div| - clause_name(node, node.at(ns("./title")), div, nil) + clause_name(node, node.at(ns("./fmt-title")), div, nil) if node.name == "clause" - node.elements.each { |e| parse(e, div) unless e.name == "title" } + node.elements.each { |e| parse(e, div) unless e.name == "fmt-title" } else biblio_list(node, div, false) end end @@ -60,7 +60,7 @@ def bibliography(node, out) page_break(out) out.div do |div| div.h1 class: "Section3" do |h1| - node.at(ns("./title"))&.children&.each { |c2| parse(c2, h1) } + node.at(ns("./fmt-title"))&.children&.each { |c2| parse(c2, h1) } end biblio_list(node, div, true) end @@ -69,7 +69,7 @@ def bibliography(node, out) def bibliography_parse(node, out) node["hidden"] != true or return out.div do |div| - clause_parse_title(node, div, node.at(ns("./title")), out, + clause_parse_title(node, div, node.at(ns("./fmt-title")), out, { class: "Section3" }) biblio_list(node, div, true) end diff --git a/lib/isodoc/function/reqt.rb b/lib/isodoc/function/reqt.rb index d4563e4b..5688a034 100644 --- a/lib/isodoc/function/reqt.rb +++ b/lib/isodoc/function/reqt.rb @@ -20,9 +20,9 @@ def recommendation_parse(node, out) end def recommendation_parse1(node, out) - recommendation_name(node.at(ns("./name")), out) + recommendation_name(node.at(ns("./fmt-name")), out) node.children.each do |n| - parse(n, out) unless n.name == "name" + parse(n, out) unless n.name == "fmt-name" end end diff --git a/lib/isodoc/function/section.rb b/lib/isodoc/function/section.rb index a35f386f..08095a6a 100644 --- a/lib/isodoc/function/section.rb +++ b/lib/isodoc/function/section.rb @@ -10,8 +10,8 @@ def clause_attrs(node) # used for subclauses def clause_parse(node, out) out.div **attr_code(clause_attrs(node)) do |div| - clause_parse_title(node, div, node.at(ns("./title")), out) - node.children.reject { |c1| c1.name == "title" }.each do |c1| + clause_parse_title(node, div, node.at(ns("./fmt-title")), out) + node.children.reject { |c1| c1.name == "fmt-title" }.each do |c1| parse(c1, div) end end @@ -19,8 +19,8 @@ def clause_parse(node, out) def clause(node, out) out.div **attr_code(clause_attrs(node)) do |s| - clause_name(node, node.at(ns("./title")), s, nil) - node.elements.reject { |c1| c1.name == "title" }.each do |c1| + clause_name(node, node.at(ns("./fmt-title")), s, nil) + node.elements.reject { |c1| c1.name == "fmt-title" }.each do |c1| parse(c1, s) end end @@ -34,7 +34,7 @@ def annex(node, out) page_break(out) out.div **attr_code(annex_attrs(node)) do |s| node.elements.each do |c1| - if c1.name == "title" then annex_name(node, c1, s) + if c1.name == "fmt-title" then annex_name(node, c1, s) else parse(c1, s) end end @@ -47,9 +47,9 @@ def indexsect(node, out) def scope(node, out) out.div **attr_code(id: node["id"]) do |div| - clause_name(node, node.at(ns("./title")), div, nil) + clause_name(node, node.at(ns("./fmt-title")), div, nil) node.elements.each do |e| - parse(e, div) unless e.name == "title" + parse(e, div) unless e.name == "fmt-title" end end end @@ -59,9 +59,9 @@ def scope(node, out) def terms_defs(node, out) out.div **attr_code(id: node["id"]) do |div| - clause_name(node, node.at(ns("./title")), div, nil) + clause_name(node, node.at(ns("./fmt-title")), div, nil) node.elements.each do |e| - parse(e, div) unless %w{title source}.include? e.name + parse(e, div) unless %w{fmt-title source}.include? e.name end end end @@ -73,9 +73,9 @@ def terms_parse(isoxml, out) def symbols_abbrevs(node, out) out.div **attr_code(id: node["id"], class: "Symbols") do |div| - clause_name(node, node.at(ns("./title")), div, nil) + clause_name(node, node.at(ns("./fmt-title")), div, nil) node.elements.each do |e| - parse(e, div) unless e.name == "title" + parse(e, div) unless e.name == "fmt-title" end end end @@ -88,10 +88,10 @@ def symbols_parse(isoxml, out) def introduction(clause, out) page_break(out) out.div class: "Section3", id: clause["id"] do |div| - clause_name(clause, clause.at(ns("./title")), div, + clause_name(clause, clause.at(ns("./fmt-title")), div, { class: "IntroTitle" }) clause.elements.each do |e| - parse(e, div) unless e.name == "title" + parse(e, div) unless e.name == "fmt-title" end end end @@ -99,9 +99,9 @@ def introduction(clause, out) def foreword(clause, out) page_break(out) out.div **attr_code(id: clause["id"]) do |s| - clause_name(clause, clause.at(ns("./title")), s, + clause_name(clause, clause.at(ns("./fmt-title")), s, { class: "ForewordTitle" }) - clause.elements.each { |e| parse(e, s) unless e.name == "title" } + clause.elements.each { |e| parse(e, s) unless e.name == "fmt-title" } end end @@ -109,9 +109,9 @@ def acknowledgements(clause, out) title_attr = { class: "IntroTitle" } page_break(out) out.div class: "Section3", id: clause["id"] do |div| - clause_name(clause, clause.at(ns("./title")), div, title_attr) + clause_name(clause, clause.at(ns("./fmt-title")), div, title_attr) clause.elements.each do |e| - parse(e, div) unless e.name == "title" + parse(e, div) unless e.name == "fmt-title" end end end @@ -119,9 +119,9 @@ def acknowledgements(clause, out) def abstract(clause, out) page_break(out) out.div **attr_code(id: clause["id"]) do |s| - clause_name(clause, clause.at(ns("./title")), s, + clause_name(clause, clause.at(ns("./fmt-title")), s, { class: "AbstractTitle" }) - clause.elements.each { |e| parse(e, s) unless e.name == "title" } + clause.elements.each { |e| parse(e, s) unless e.name == "fmt-title" } end end @@ -141,10 +141,10 @@ def preface(clause, out) def preface_normal(clause, out) page_break(out) out.div **attr_code(preface_attrs(clause)) do |div| - clause_name(clause, clause.at(ns("./title")), div, + clause_name(clause, clause.at(ns("./fmt-title")), div, { class: "IntroTitle" }) clause.elements.each do |e| - parse(e, div) unless e.name == "title" + parse(e, div) unless e.name == "fmt-title" end end end @@ -153,10 +153,10 @@ def table_of_contents(clause, out) @bare and return page_break(out) out.div **attr_code(preface_attrs(clause)) do |div| - clause_name(clause, clause.at(ns("./title")), div, + clause_name(clause, clause.at(ns("./fmt-title")), div, { class: "IntroTitle" }) clause.elements.each do |e| - parse(e, div) unless e.name == "title" + parse(e, div) unless e.name == "fmt-title" end end end @@ -165,10 +165,10 @@ def colophon(node, out) @seen_colophon or page_break(out) @seen_colophon = true out.div class: "Section3", id: node["id"] do |div| - clause_name(node, node.at(ns("./title")), div, + clause_name(node, node.at(ns("./fmt-title")), div, { class: "IntroTitle" }) node.elements.each do |e| - parse(e, div) unless e.name == "title" + parse(e, div) unless e.name == "fmt-title" end end end diff --git a/lib/isodoc/function/section_titles.rb b/lib/isodoc/function/section_titles.rb index 3b99f5a3..d09c8300 100644 --- a/lib/isodoc/function/section_titles.rb +++ b/lib/isodoc/function/section_titles.rb @@ -18,18 +18,24 @@ def inline_header_title(out, node, title) end end + def sections_names + %w[clause annex terms references definitions + acknowledgements introduction abstract foreword appendix] + end + def freestanding_title(node, out) - parents = node.ancestors("clause, annex, terms, references, " \ - "definitions, acknowledgements, introduction, " \ - "foreword") + # node.parent.at(ns("./fmt-title[@source = '#{node['id']}']")) and + # return # this title is already being rendered as fmt-title + # For testing convenience, let's just go by parent + sections_names.include?(node.parent.name) and return + parents = node.ancestors(sections_names.join(", ")) clause_parse_title(parents.empty? ? node : parents.first, out, node, out) end # used for subclauses def clause_parse_title(node, div, title, out, header_class = {}) - return if title.nil? - + title.nil? and return if node["inline-header"] == "true" inline_header_title(out, node, title) else @@ -46,9 +52,7 @@ def clause_parse_title1(node, div, title, _out, header_class = {}) end def clause_title_depth(node, title) - depth = node.ancestors("clause, annex, terms, references, " \ - "definitions, acknowledgements, introduction, " \ - "foreword").size + 1 + depth = node.ancestors(sections_names.join(", ")).size + 1 depth = title["depth"] if title && title["depth"] depth end @@ -67,8 +71,8 @@ def clause_name(_node, title, div, header_class) header_class = {} if header_class.nil? div.h1 **attr_code(header_class) do |h1| if title.is_a?(String) then h1 << title - else - title&.children&.each { |c2| parse(c2, h1) } + elsif title + children_parse(title, h1) clause_parse_subtitle(title, h1) end end @@ -76,8 +80,7 @@ def clause_name(_node, title, div, header_class) end def annex_name(_annex, name, div) - return if name.nil? - + name.nil? and return div.h1 class: "Annex" do |t| name.children.each { |c2| parse(c2, t) } clause_parse_subtitle(name, t) diff --git a/lib/isodoc/function/table.rb b/lib/isodoc/function/table.rb index 74df4cbc..8e75bcf2 100644 --- a/lib/isodoc/function/table.rb +++ b/lib/isodoc/function/table.rb @@ -2,7 +2,7 @@ module IsoDoc module Function module Table def table_title_parse(node, out) - name = node.at(ns("./name")) or return + name = node.at(ns("./fmt-name")) or return out.p class: "TableTitle", style: "text-align:center;" do |p| name&.children&.each { |n| parse(n, p) } end diff --git a/lib/isodoc/function/terms.rb b/lib/isodoc/function/terms.rb index c5fc2c07..fbb1e352 100644 --- a/lib/isodoc/function/terms.rb +++ b/lib/isodoc/function/terms.rb @@ -28,24 +28,27 @@ def term_parse(node, out) end end - def para_then_remainder(first, node, para, div) - if first.name == "p" - first.children.each { |n| parse(n, para) } - node.elements.drop(1).each { |n| parse(n, div) } - else - node.elements.each { |n| parse(n, div) } - end + def termnote_p_class + nil end def termnote_parse(node, out) - name = node&.at(ns("./name"))&.remove + para = block_body_first_elem(node) out.div **note_attrs(node) do |div| - div.p do |p| - name&.children&.each { |n| parse(n, p) } - p << " " - para_then_remainder(node.first_element_child, node, p, div) - end + termnote_parse1(node, para, div) + para&.xpath("./following-sibling::*")&.each { |n| parse(n, div) } + end + end + + def termnote_parse1(node, para, div) + div.p **attr_code(class: termnote_p_class) do |p| + name = node.at(ns("./fmt-name")) and + p.span class: "termnote_label" do |s| + children_parse(name, s) + end + para&.name == "p" and children_parse(para, p) end + para&.name != "p" and parse(para, div) end def termref_parse(node, out) @@ -60,7 +63,7 @@ def termdomain_parse(node, out) end def termdef_parse(node, out) - name = node.at(ns("./name"))&.remove + name = node.at(ns("./fmt-name"))&.remove out.p class: "TermNum", id: node["id"] do |p| name&.children&.each { |n| parse(n, p) } end diff --git a/lib/isodoc/function/to_word_html.rb b/lib/isodoc/function/to_word_html.rb index 5ae1bb4c..c2f63d13 100644 --- a/lib/isodoc/function/to_word_html.rb +++ b/lib/isodoc/function/to_word_html.rb @@ -262,6 +262,11 @@ def parse(node, out) when "ruby" then ruby_parse(node, out) when "rt" then rt_parse(node, out) when "rb" then rb_parse(node, out) + when "semx" then semx_parse(node, out) + when "name" then name_parse(node, out) + when "fmt-xref-label" then xref_label_parse(node, out) + when "fmt-name" then fmt_name_parse(node, out) + when "floating-title" then floating_title_parse(node, out) else error_parse(node, out) end end diff --git a/lib/isodoc/html_function/footnotes.rb b/lib/isodoc/html_function/footnotes.rb index 5977396b..14c18b6d 100644 --- a/lib/isodoc/html_function/footnotes.rb +++ b/lib/isodoc/html_function/footnotes.rb @@ -24,6 +24,7 @@ def make_table_footnote_target(out, fnid, fnref) end end + # Move to Presentation XML, as : it's a footnote body def make_table_footnote_text(node, fnid, fnref) attrs = { id: "fn:#{fnid}" } noko do |xml| @@ -68,7 +69,7 @@ def table_footnote_parse(node, out) def footnote_parse(node, out) return table_footnote_parse(node, out) if (@in_table || @in_figure) && - !node.ancestors.map(&:name).include?("name") + !node.ancestors.map(&:name).include?("fmt-name") fn = node["reference"] || UUIDTools::UUID.random_create.to_s attrs = { class: "FootnoteRef", href: "#fn:#{fn}" } diff --git a/lib/isodoc/html_function/html.rb b/lib/isodoc/html_function/html.rb index 78d92ece..23a77d96 100644 --- a/lib/isodoc/html_function/html.rb +++ b/lib/isodoc/html_function/html.rb @@ -15,10 +15,6 @@ def convert1(docxml, filename, dir) end.join("\n") end - def preprocess_xslt(docxml) - super - end - def make_body1(body, _docxml) return if @bare @@ -78,7 +74,7 @@ def html_main(docxml) end def sourcecode_parse(node, out) - name = node.at(ns("./name")) + name = node.at(ns("./fmt-name")) tag = node.at(ns(".//sourcecode | .//table")) ? "div" : "pre" attr = sourcecode_attrs(node).merge(class: "sourcecode") out.send tag, **attr do |div| diff --git a/lib/isodoc/init.rb b/lib/isodoc/init.rb index 1f3f1768..be0600c0 100644 --- a/lib/isodoc/init.rb +++ b/lib/isodoc/init.rb @@ -162,5 +162,14 @@ def omit_docid_prefix(prefix) %w(ISO IEC IEV ITU W3C BIPM csd metanorma repository metanorma-ordinal) .include? prefix end + + def connectives_spans(text) + text.gsub("", "") + .gsub("", "") + .gsub("", "") + .gsub("", "") + .gsub("", "") + .gsub("", "") + end end end diff --git a/lib/isodoc/metadata.rb b/lib/isodoc/metadata.rb index f36a882a..7fa72ddd 100644 --- a/lib/isodoc/metadata.rb +++ b/lib/isodoc/metadata.rb @@ -13,6 +13,15 @@ def l10n(expr, lang = @lang, script = @script, locale = @locale) @i18n.l10n(expr, lang, script, locale) end + def connectives_strip(text) + text.gsub("", "") + .gsub("", "") + .gsub("", "") + .gsub("", "") + .gsub("", "") + .gsub("", "") + end + def initialize(lang, script, locale, i18n, fonts_options = {}) @metadata = { lang:, script: } DATETYPES.each { |w| @metadata["#{w.tr('-', '_')}date".to_sym] = "XXX" } diff --git a/lib/isodoc/metadata_contributor.rb b/lib/isodoc/metadata_contributor.rb index 7ae357f1..452dbf3f 100644 --- a/lib/isodoc/metadata_contributor.rb +++ b/lib/isodoc/metadata_contributor.rb @@ -79,7 +79,7 @@ def agency1(xml) def agency(xml) agency, publisher = agency1(xml) set(:agency, agency.sub(%r{/$}, "")) - set(:publisher, @i18n.boolean_conj(publisher, "and")) + set(:publisher, connectives_strip(@i18n.boolean_conj(publisher, "and"))) agency_addr(xml) end diff --git a/lib/isodoc/metadata_date.rb b/lib/isodoc/metadata_date.rb index 1cfdfb8d..ef146959 100644 --- a/lib/isodoc/metadata_date.rb +++ b/lib/isodoc/metadata_date.rb @@ -42,7 +42,7 @@ def MMMddyyyy(isodate) def bibdate(isoxml, _out) isoxml.xpath(ns("//bibdata/date")).each do |d| - set("#{d['type'].gsub(/-/, '_')}date".to_sym, Common::date_range(d)) + set("#{d['type'].tr('-', '_')}date".to_sym, Common::date_range(d)) end end end diff --git a/lib/isodoc/presentation_function/autonum.rb b/lib/isodoc/presentation_function/autonum.rb new file mode 100644 index 00000000..afdc8032 --- /dev/null +++ b/lib/isodoc/presentation_function/autonum.rb @@ -0,0 +1,139 @@ +module IsoDoc + class PresentationXMLConvert < ::IsoDoc::Convert + def prefix_name(node, delims, label, elem) + label, delims = prefix_name_defaults(node, delims, label) + name, ins, ids, number = prefix_name_prep(node, elem) + ins.next = fmt_xref_label(label, number, ids) + # autonum can be empty, e.g single note in clause: "NOTE []" + number and node["autonum"] = number.gsub(/<[^>]+>/, "") + !node.at(ns("./fmt-#{elem}")) && + (c = fmt_caption(label, elem, name, ids, delims)) and ins.next = c + prefix_name_postprocess(node, elem) + end + + def prefix_name_defaults(node, delims, label) + label&.empty? and label = nil + delims.nil? and delims = {} + [label, delims] + end + + def prefix_name_prep(node, elem) + lbls = prefix_name_labels(node) + name = node.at(ns("./#{elem}")) and name["id"] = lbls[:name] + ins = name || node.add_first_child("").elements.first + node["unnumbered"] or + number = @xrefs.anchor(node["id"], :value, false)&.strip + [name, ins, lbls, number] + end + + def prefix_name_labels(node) + { elem: node["id"], + name: "_#{UUIDTools::UUID.random_create}" } + end + + def prefix_name_postprocess(node, elem) + node.at(ns("./sentinel"))&.remove + strip_duplicate_ids(node, node.at(ns("./#{elem}")), + node.at(ns("./fmt-#{elem}"))) + end + + def transfer_id(old, new) + old["id"] or return + new["id"] = old["id"] + old["original-id"] = old["id"] + old.delete("id") + end + + def gather_all_ids(elem) + elem.xpath(".//*[@id]").each_with_object([]) do |i, m| + m << i["id"] + end + end + + # remove ids duplicated between title and fmt-title + # index terms are assumed transferred to fmt-title from title + def strip_duplicate_ids(_node, sem_title, pres_title) + sem_title && pres_title or return + ids = gather_all_ids(pres_title) + sem_title.xpath(".//*[@id]").each do |x| + ids.include?(x["id"]) or next + x["original-id"] = x["id"] + x.delete("id") + end + sem_title.xpath(ns(".//index")).each(&:remove) + end + + def semx(node, label, element = "autonum") + id = node["id"] || node[:id] + /#{l}) + end + + def autonum(id, num) + /#{num}" + end + + def labelled_autonum(label, id, num) + elem = "#{label}" + num.blank? and return elem + l10n("#{elem} #{autonum(id, num)}") + end + + def fmt_xref_label(label, _number, ids) + label or return "" + x = @xrefs.anchor(ids[:elem], :xref, false) or return "" + ret = "#{x}" + container = @xrefs.anchor(ids[:elem], :container, false) + y = prefix_container_fmt_xref_label(container, x) + y != x and + ret += "#{y}" + ret + end + + def prefix_container_fmt_xref_label(container, xref) + container or return xref + container_container = @xrefs.anchor(container, :container, false) + container_label = + prefix_container_fmt_xref_label(container_container, + @xrefs.anchor(container, :xref, false)) + l10n(connectives_spans(@i18n.nested_xref + .sub("%1", "#{container_label}") + .sub("%2", xref))) + end + + # detect whether string which may contain XML markup is empty + def empty_xml?(str) + str.blank? and return true + x = Nokogiri::XML::DocumentFragment.parse(str) + x.to_str.strip.empty? + end + + # Remove ".blank?" tests if want empty delim placeholders for manipulation + def fmt_caption(label, elem, name, ids, delims) + label = fmt_caption_label_wrap(label) + c = fmt_caption2(label, elem, name, ids, delims) + empty_xml?(c) and return + !delims[:label].blank? and + f = "#{delims[:label]}" + "#{c}#{f}" + end + + def fmt_caption_label_wrap(label) + empty_xml?(label) || %r{#{to_xml(name.children)}" + elsif label then label + end + end + end +end diff --git a/lib/isodoc/presentation_function/block.rb b/lib/isodoc/presentation_function/block.rb index 25898fad..aac2a0a8 100644 --- a/lib/isodoc/presentation_function/block.rb +++ b/lib/isodoc/presentation_function/block.rb @@ -1,29 +1,23 @@ require_relative "image" require_relative "sourcecode" +require_relative "autonum" require "rouge" module IsoDoc class PresentationXMLConvert < ::IsoDoc::Convert def lower2cap(text) - /^[[:upper:]][[:upper:]]/.match?(text) and return text - text&.capitalize + text.nil? and return text + x = Nokogiri::XML("#{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) end def block_delim " — " end - def prefix_name(node, delim, number, elem) - number.nil? || number.empty? and return - unless name = node.at(ns("./#{elem}")) - node.add_first_child "<#{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}") - end - end - def formula(docxml) docxml.xpath(ns("//formula")).each { |f| formula1(f) } end @@ -31,7 +25,7 @@ def formula(docxml) def formula1(elem) formula_where(elem.at(ns("./dl"))) lbl = @xrefs.anchor(elem["id"], :label, false) - lbl.nil? || lbl.empty? or prefix_name(elem, "", "(#{lbl})", "name") + lbl.nil? || lbl.empty? or prefix_name(elem, {}, lbl, "name") end def formula_where(dlist) @@ -47,11 +41,8 @@ def example(docxml) def example1(elem) n = @xrefs.get[elem["id"]] - lbl = if n.nil? || n[:label].nil? || n[:label].empty? - @i18n.example - else l10n("#{@i18n.example} #{n[:label]}") - end - prefix_name(elem, block_delim, lbl, "name") + lbl = labelled_autonum(@i18n.example, elem["id"], n&.dig(:label)) + prefix_name(elem, { caption: block_delim }, lbl, "name") end def note(docxml) @@ -59,22 +50,18 @@ def note(docxml) 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") + elem["notag"] == "true" or lbl = note_label(elem) + prefix_name(elem, { label: note_delim(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]}") - "#{lbl}#{note_delim(elem)}" + labelled_autonum(@i18n.note, elem["id"], n&.dig(:label)) end def admonition(docxml) @@ -85,24 +72,25 @@ def admonition1(elem) if elem["type"] == "box" admonition_numbered1(elem) elsif elem["notag"] == "true" || elem.at(ns("./name")) + prefix_name(elem, { label: admonition_delim(elem) }, nil, "name") else label = admonition_label(elem, nil) - prefix_name(elem, "", label, "name") + prefix_name(elem, { label: admonition_delim(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 + # elem["unnumbered"] && !elem.at(ns("./name")) and return label = admonition_label(elem, @xrefs.anchor(elem["id"], :label, false)) - prefix_name(elem, block_delim, label, "name") + 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 - num and lbl = l10n("#{lbl} #{num}") - lbl + #lbl &&= "#{lbl}" + #num and lbl = l10n("#{lbl} #{autonum(elem['id'], num)}") + labelled_autonum(lbl, elem["id"], num) end def admonition_delim(_elem) @@ -119,8 +107,14 @@ def table1(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") + #lbl = "#{lower2cap @i18n.table} "\ + #"#{autonum(elem['id'], n)}" + lbl = labelled_autonum(lower2cap(@i18n.table), elem["id"], n) + prefix_name(elem, { caption: table_delim }, l10n(lbl), "name") + end + + def table_delim + block_delim end def table_long_strings_cleanup(docxml) @@ -156,7 +150,23 @@ def amend1(elem) elem.replace(elem.children) end - def dl(docxml); end + def dl(docxml) + docxml.xpath(ns("//dl")).each { |f| dl1(f) } + end + + def dl1(elem) + elem.at(ns("./name")) and + prefix_name(elem, {}, "", "name") # copy name to fmt-name + end + + def ul(docxml) + docxml.xpath(ns("//ul")).each { |f| ul1(f) } + end + + def ul1(elem) + elem.at(ns("./name")) and + prefix_name(elem, {}, "", "name") # copy name to fmt-name + end def ol(docxml) docxml.xpath(ns("//ol")).each { |f| ol1(f) } @@ -179,9 +189,8 @@ def ol_depth(node) def ol1(elem) elem["type"] ||= ol_depth(elem).to_s - elem.xpath(ns("./li")).each do |li| - li["id"] ||= "_#{UUIDTools::UUID.random_create}" - end + elem.at(ns("./name")) and + prefix_name(elem, {}, "", "name") # copy name to fmt-name end def ol_label(elem) diff --git a/lib/isodoc/presentation_function/docid.rb b/lib/isodoc/presentation_function/docid.rb index ed052f69..29ab41ed 100644 --- a/lib/isodoc/presentation_function/docid.rb +++ b/lib/isodoc/presentation_function/docid.rb @@ -6,29 +6,6 @@ def docid_prefixes(docxml) end end -=begin - # This is highly specific to ISO, but it's not a bad precedent for - # references anyway; keeping here instead of in IsoDoc::Iso for now - def docid_l10n(text) - text.nil? and return text - @i18n.all_parts and text.gsub!(/All Parts/i, @i18n.all_parts.downcase) - text.size < 20 and text.gsub!(/ /, " ") - text - end - - def docid_prefix(prefix, docid) - docid = "#{prefix} #{docid}" if prefix && !omit_docid_prefix(prefix) && - !/^#{prefix}\b/.match(docid) - docid_l10n(docid) - end - - def omit_docid_prefix(prefix) - prefix.nil? || prefix.empty? and return true - %w(ISO IEC IEV ITU W3C BIPM csd metanorma repository metanorma-ordinal) - .include? prefix - end -=end - def pref_ref_code(bib) bib["suppress_identifier"] == "true" and return nil ret = bib.xpath(ns("./docidentifier[@scope = 'biblio-tag']")) diff --git a/lib/isodoc/presentation_function/erefs.rb b/lib/isodoc/presentation_function/erefs.rb index 7e54aeef..d60b54d4 100644 --- a/lib/isodoc/presentation_function/erefs.rb +++ b/lib/isodoc/presentation_function/erefs.rb @@ -5,7 +5,8 @@ class PresentationXMLConvert < ::IsoDoc::Convert def citeas(xmldoc) xmldoc.xpath(ns("//eref | //origin | //quote//source")).each do |e| e["bibitemid"] && e["citeas"] or next - a = @xrefs.anchor(e["bibitemid"], :xref, false) and e["citeas"] = a + a = @xrefs.anchor(e["bibitemid"], :xref, false) and + e["citeas"] = a.gsub(%r{]+>}, "") end end @@ -87,7 +88,8 @@ def resolve_to_connectives(locs) locs1 = [] until locs.empty? if locs[1] == "to" - locs1 << @i18n.chain_to.sub("%1", locs[0]).sub("%2", locs[2]) + locs1 << connectives_spans(@i18n.chain_to.sub("%1", locs[0]) + .sub("%2", locs[2])) locs.shift(3) else locs1 << locs.shift end diff --git a/lib/isodoc/presentation_function/image.rb b/lib/isodoc/presentation_function/image.rb index 022ff482..30d741d0 100644 --- a/lib/isodoc/presentation_function/image.rb +++ b/lib/isodoc/presentation_function/image.rb @@ -43,16 +43,32 @@ def svg_extract(elem) elem.children = x end + def subfigure_delim + "" + # ")" + end + + def figure_delim(_elem) + block_delim + end + + def figure_name(elem) + "#{figure_label(elem)} " + end + def figure1(elem) elem["class"] == "pseudocode" || elem["type"] == "pseudocode" and return sourcecode1(elem) figure_fn(elem) figure_key(elem.at(ns("./dl"))) - figure_label?(elem) or return nil - lbl = @xrefs.anchor(elem["id"], :label, false) or return - # no xref, no label: this can be set in xref - prefix_name(elem, block_delim, - l10n("#{figure_label(elem)} #{lbl}"), "name") + lbl = @xrefs.anchor(elem["id"], :label, false) + lbl and a = autonum(elem["id"], lbl) + figname = figure_name(elem) + if elem.parent.name == "figure" + a += subfigure_delim + end + lbl && figure_label?(elem) and s = "#{figname}#{a}" + prefix_name(elem, { caption: figure_delim(elem) }, l10n(s&.strip), "name") end # move footnotes into key, and get rid of footnote reference diff --git a/lib/isodoc/presentation_function/reqt.rb b/lib/isodoc/presentation_function/reqt.rb index 804d7fe8..3853a527 100644 --- a/lib/isodoc/presentation_function/reqt.rb +++ b/lib/isodoc/presentation_function/reqt.rb @@ -24,7 +24,7 @@ def permission(docxml) def recommendation1(elem, type) lbl = @reqt_models.model(elem["model"]) .recommendation_label(elem, type, xrefs) - prefix_name(elem, "", l10n(lbl), "name") + prefix_name(elem, {}, l10n(lbl), "name") end def requirement_render_preprocessing(docxml); end diff --git a/lib/isodoc/presentation_function/section.rb b/lib/isodoc/presentation_function/section.rb index 69307433..7eee462a 100644 --- a/lib/isodoc/presentation_function/section.rb +++ b/lib/isodoc/presentation_function/section.rb @@ -1,26 +1,12 @@ require_relative "refs" +require_relative "title" module IsoDoc class PresentationXMLConvert < ::IsoDoc::Convert - def middle_title(docxml) - s = docxml.at(ns("//sections")) or return - t = @meta.get[:doctitle] - t.nil? || t.empty? and return - s.add_first_child "

#{t}

" - end - - def missing_title(docxml) - docxml.xpath(ns("//definitions[not(./title)]")).each do |d| - # should only be happening for subclauses - d.add_first_child "#{@i18n.symbols}" - end - docxml.xpath(ns("//foreword[not(./title)]")).each do |d| - d.add_first_child "#{@i18n.foreword}" - end - end - def clause(docxml) - docxml.xpath(ns("//clause | //terms | //definitions | //references")) + docxml.xpath(ns("//clause | //terms | //definitions | //references | " \ + "//introduction | //foreword | //preface/abstract | " \ + "//acknowledgements | //colophon | //indexsect ")) .each do |f| f.parent.name == "annex" && @xrefs.klass.single_term_clause?(f.parent) and next @@ -34,32 +20,23 @@ def unnumbered_clause?(elem) elem.at("./ancestor::*[@unnumbered = 'true']") end + def clausedelim + ret = super + ret && !ret.empty? or return ret + "#{ret}" + end + def clause1(elem) level = @xrefs.anchor(elem["id"], :level, false) || (elem.ancestors("clause, annex").size + 1) - t = elem.at(ns("./title")) and t["depth"] = level - unnumbered_clause?(elem) and return - lbl = @xrefs.anchor(elem["id"], :label, - elem.parent.name != "sections") or return - prefix_name(elem, "", "#{lbl}#{clausedelim}", "title") - end - - def floattitle(docxml) - p = "//clause | //annex | //appendix | //introduction | //foreword | " \ - "//preface/abstract | //acknowledgements | //terms | " \ - "//definitions | //references | //colophon | //indexsect" - docxml.xpath(ns(p)).each { |f| floattitle1(f) } - # top-level - docxml.xpath(ns("//sections | //preface | //colophon")) - .each { |f| floattitle1(f) } - end - - # TODO not currently doing anything with the @depth attribute of floating-title - def floattitle1(elem) - elem.xpath(ns(".//floating-title")).each do |p| - p.name = "p" - p["type"] = "floating-title" + lbl = @xrefs.anchor(elem["id"], :label, elem.parent.name != "sections") + if unnumbered_clause?(elem) || !lbl + prefix_name(elem, {}, nil, "title") + else + prefix_name(elem, { caption: "" }, "#{lbl}#{clausedelim}", + "title") end + t = elem.at(ns("./fmt-title")) and t["depth"] = level end def annex(docxml) @@ -73,10 +50,18 @@ def annex(docxml) def annex1(elem) lbl = @xrefs.anchor(elem["id"], :label) + # TODO: do not alter title, alter semx/@element = title t = elem.at(ns("./title")) and t.children = "#{to_xml(t.children)}" - unnumbered_clause?(elem) and return - prefix_name(elem, "

", lbl, "title") + if unnumbered_clause?(elem) + prefix_name(elem, {}, nil, "title") + else + prefix_name(elem, { caption: annex_delim(elem) }, lbl, "title") + end + end + + def annex_delim(_elem) + "

" end def single_term_clause_retitle(elem) @@ -91,7 +76,7 @@ def single_term_clause_unnest(elem) t = elem.at(ns("./terms | ./definitions | ./references")) t.xpath(ns(".//clause | .//terms | .//definitions | .//references")) .each do |c| - tit = c.at(ns("./title")) or return + tit = c.at(ns("./fmt-title")) or next tit["depth"] = tit["depth"].to_i - 1 unless tit["depth"] == "1" end end @@ -100,8 +85,13 @@ def index(docxml) docxml.xpath(ns("//index | //index-xref | //indexsect")).each(&:remove) end + def skip_display_order?(node) + node.name == "floating-title" + end + def display_order_at(docxml, xpath, idx) c = docxml.at(ns(xpath)) or return idx + skip_display_order?(c) and return idx idx += 1 idx = preceding_floating_titles(c, idx) c["displayorder"] = idx @@ -110,6 +100,7 @@ def display_order_at(docxml, xpath, idx) def display_order_xpath(docxml, xpath, idx) docxml.xpath(ns(xpath)).each do |c| + skip_display_order?(c) and next idx += 1 idx = preceding_floating_titles(c, idx) c["displayorder"] = idx @@ -117,19 +108,6 @@ def display_order_xpath(docxml, xpath, idx) idx end - def preceding_floating_titles(node, idx) - out = node.xpath("./preceding-sibling::*") - .reverse.each_with_object([]) do |p, m| - %w(note admonition p).include?(p.name) or break m - m << p - end - out.reject { |c| c["displayorder"] }.reverse_each do |c| - c["displayorder"] = idx - idx += 1 - end - idx - end - def display_order(docxml) i = 0 d = @xrefs.clause_order(docxml) @@ -143,46 +121,26 @@ def display_order(docxml) end end - def clausetitle(docxml) - cjk_extended_title(docxml) - end - - def cjk_search - lang = %w(zh ja ko).map { |x| "@language = '#{x}'" }.join(" or ") - %(Hans Hant Jpan Hang Kore).include?(@script) and - lang += " or not(@language)" - lang - end - - def cjk_extended_title(docxml) - l = cjk_search - docxml.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \ - "//title[@depth = '1' or not(@depth)][#{l}]")).each do |t| - t.text.size < 4 or next - t.elements.empty? or next # can't be bothered - t.children = @i18n.cjk_extend(t.text) - end - end - def preface_rearrange(doc) - preface_move(doc.at(ns("//preface/abstract")), + preface_move(doc.xpath(ns("//preface/abstract")), %w(foreword introduction clause acknowledgements), doc) - preface_move(doc.at(ns("//preface/foreword")), + preface_move(doc.xpath(ns("//preface/foreword")), %w(introduction clause acknowledgements), doc) - preface_move(doc.at(ns("//preface/introduction")), + preface_move(doc.xpath(ns("//preface/introduction")), %w(clause acknowledgements), doc) - preface_move(doc.at(ns("//preface/acknowledgements")), + preface_move(doc.xpath(ns("//preface/acknowledgements")), %w(), doc) end - def preface_move(clause, after, _doc) - clause or return - preface = clause.parent + def preface_move(clauses, after, _doc) + clauses.empty? and return + preface = clauses.first.parent + clauses.each do |clause| float = preceding_floats(clause) - prev = nil xpath = after.map { |n| "./self::xmlns:#{n}" }.join(" | ") xpath.empty? and xpath = "./self::*[not(following-sibling::*)]" - preface_move1(clause, preface, float, prev, xpath) + preface_move1(clause, preface, float, nil, xpath) + end end def preface_move1(clause, preface, float, prev, xpath) @@ -192,47 +150,17 @@ def preface_move1(clause, preface, float, prev, xpath) x.at(xpath) or next clause == prev and break prev ||= preface.children.first - float << clause + prev.next = clause float.each { |n| prev.next = n } break end end - def preceding_floats(clause) - ret = [] - p = clause - while prev = p.previous_element - if prev.name == "floating-title" - ret << prev - p = prev - else break end - end - ret - end - def rearrange_clauses(docxml) preface_rearrange(docxml) # feeds toc_title toc_title(docxml) end - def toc_title(docxml) - docxml.at(ns("//preface/clause[@type = 'toc']")) and return - ins = toc_title_insert_pt(docxml) or return - id = UUIDTools::UUID.random_create.to_s - ins.previous = <<~CLAUSE - #{@i18n.table_of_contents} - CLAUSE - end - - def toc_title_insert_pt(docxml) - ins = docxml.at(ns("//preface")) || - docxml.at(ns("//sections | //annex | //bibliography")) - &.before(" ") - &.previous_element or return nil - ins.children.empty? and ins << " " - ins.children.first - end - def toc(docxml) toc_refs(docxml) end @@ -240,7 +168,7 @@ def toc(docxml) def toc_refs(docxml) docxml.xpath(ns("//toc//xref[text()]")).each do |x| lbl = @xrefs.anchor(x["target"], :label) or next - x.add_first_child "#{lbl}" + x.add_first_child "#{lbl}" end end end diff --git a/lib/isodoc/presentation_function/sourcecode.rb b/lib/isodoc/presentation_function/sourcecode.rb index e91032fd..3c74fba2 100644 --- a/lib/isodoc/presentation_function/sourcecode.rb +++ b/lib/isodoc/presentation_function/sourcecode.rb @@ -150,10 +150,13 @@ def source_lex(elem) end def source_label(elem) - labelled_ancestor(elem) and return - lbl = @xrefs.anchor(elem["id"], :label, false) or return - prefix_name(elem, block_delim, - l10n("#{lower2cap @i18n.figure} #{lbl}"), "name") + if !labelled_ancestor(elem) && # do not number if labelled_ancestor + lbl = @xrefs.anchor(elem["id"], :label, false) + #a = autonum(elem["id"], lbl) + #s = "#{lower2cap @i18n.figure} #{a}" + s = labelled_autonum(lower2cap(@i18n.figure), elem["id"], lbl)&.strip + end + prefix_name(elem, { caption: block_delim }, s, "name") end end end diff --git a/lib/isodoc/presentation_function/terms.rb b/lib/isodoc/presentation_function/terms.rb index f795b910..1a439962 100644 --- a/lib/isodoc/presentation_function/terms.rb +++ b/lib/isodoc/presentation_function/terms.rb @@ -115,12 +115,11 @@ def termnote_delim(_elem) def termnote1(elem) lbl = termnote_label(elem) - prefix_name(elem, "", lower2cap(lbl), "name") + prefix_name(elem, { label: termnote_delim(elem) }, lower2cap(lbl), "name") end def termnote_label(elem) - lbl = @xrefs.anchor(elem["id"], :label) || "???" - l10n "#{lbl}#{termnote_delim(elem)}" + @xrefs.anchor(elem["id"], :label) || "???" end def termdefinition(docxml) @@ -200,7 +199,7 @@ def term(docxml) def term1(elem) lbl = @xrefs.anchor(elem["id"], :label) or return - prefix_name(elem, "", "#{lbl}#{clausedelim}", "name") + prefix_name(elem, {}, "#{lbl}#{clausedelim}", "name") end end end diff --git a/lib/isodoc/presentation_function/title.rb b/lib/isodoc/presentation_function/title.rb new file mode 100644 index 00000000..7a996204 --- /dev/null +++ b/lib/isodoc/presentation_function/title.rb @@ -0,0 +1,107 @@ +require_relative "refs" + +module IsoDoc + class PresentationXMLConvert < ::IsoDoc::Convert + def middle_title(docxml) + s = docxml.at(ns("//sections")) or return + t = @meta.get[:doctitle] + t.nil? || t.empty? and return + s.add_first_child "

#{t}

" + end + + def missing_title(docxml) + docxml.xpath(ns("//definitions[not(./title)]")).each do |d| + # should only be happening for subclauses + d.add_first_child "#{@i18n.symbols}" + end + docxml.xpath(ns("//foreword[not(./title)]")).each do |d| + d.add_first_child "#{@i18n.foreword}" + end + end + + def floattitle(docxml) + docxml.xpath(ns(".//floating-title")).each { |f| floattitle1(f) } + end + + # TODO not currently doing anything with the @depth attribute of floating-title + def floattitle1(elem) + elem["id"] ||= "_#{UUIDTools::UUID.random_create}" + p = elem.dup + p.children = "" \ + "#{to_xml(p.children)}" + elem.next = p + p.name = "p" + p["type"] = "floating-title" + transfer_id(elem, p) + end + + def preceding_floating_titles(node, idx) + out = node.xpath("./preceding-sibling::*") + .reverse.each_with_object([]) do |p, m| + %w(note admonition p floating-title).include?(p.name) or break m + m << p + end + #require 'debug'; out.empty? or binding.b + out.reject { |c| c["displayorder"] }.reverse_each do |c| + skip_display_order?(c) and next + c["displayorder"] = idx + idx += 1 + end + idx + end + + def clausetitle(docxml) + cjk_extended_title(docxml) + end + + def cjk_search + lang = %w(zh ja ko).map { |x| "@language = '#{x}'" }.join(" or ") + %(Hans Hant Jpan Hang Kore).include?(@script) and + lang += " or not(@language)" + lang + end + + def cjk_extended_title(doc) + l = cjk_search + doc.xpath(ns("//bibdata/title[#{l}] | //floating-title[#{l}] | " \ + "//fmt-title[@depth = '1' or not(@depth)][#{l}]")) + .each do |t| + t.text.size < 4 or next + t.traverse do |n| + n.text? or next + n.replace(@i18n.cjk_extend(n.text)) + end + end + end + + def preceding_floats(clause) + ret = [] + p = clause + while prev = p.previous_element + if prev.name == "floating-title" + ret << prev + p = prev + else break end + end + ret + end + + def toc_title(docxml) + docxml.at(ns("//preface/clause[@type = 'toc']")) and return + ins = toc_title_insert_pt(docxml) or return + id = UUIDTools::UUID.random_create.to_s + ins.previous = <<~CLAUSE + #{@i18n.table_of_contents} + CLAUSE + end + + def toc_title_insert_pt(docxml) + ins = docxml.at(ns("//preface")) || + docxml.at(ns("//sections | //annex | //bibliography")) + &.before(" ") + &.previous_element or return nil + ins.children.empty? and ins << " " + ins.children.first + end + end +end diff --git a/lib/isodoc/presentation_function/xrefs.rb b/lib/isodoc/presentation_function/xrefs.rb index b09dbd15..9d66f01e 100644 --- a/lib/isodoc/presentation_function/xrefs.rb +++ b/lib/isodoc/presentation_function/xrefs.rb @@ -7,13 +7,14 @@ def prefix_container(container, linkend, node, target) prefix_container(container_container, anchor_xref(node, container, container: true), node, target) - l10n(@i18n.nested_xref.sub("%1", container_label) - .sub("%2", linkend)) + l10n(connectives_spans(@i18n.nested_xref + .sub("%1", "#{container_label}") + .sub("%2", linkend))) end def anchor_value(id) - @xrefs.anchor(id, :bare_xref) || @xrefs.anchor(id, :value) || - @xrefs.anchor(id, :label) || @xrefs.anchor(id, :xref) + @xrefs.anchor(id, :bare_xref) || @xrefs.anchor(id, :label) || + @xrefs.anchor(id, :value) || @xrefs.anchor(id, :xref) end def anchor_linkend(node, linkend) @@ -55,14 +56,15 @@ def anchor_xref(node, target, container: false) def anchor_xref_short(node, target, container) if (l = node["label"]) && !container - @i18n.l10n("#{l} #{anchor_value(target)}") + v = anchor_value(target) + @i18n.l10n(%[#{l} #{v}]) else @xrefs.anchor(target, :xref) end end def anchor_xref_full(num, title) (!title.nil? && !title.empty?) or return nil - l10n("#{num}, #{title}") + l10n("#{num}, #{title}") end def prefix_container?(container, node) @@ -133,9 +135,13 @@ def loc2xref(entry) def combine_conn(list) list.size == 1 and list.first[:label] if list[1..].all? { |l| l[:conn] == "and" } - @i18n.boolean_conj(list.map { |l| loc2xref(l) }, "and") + connectives_spans(@i18n.boolean_conj(list.map do |l| + loc2xref(l) + end, "and")) elsif list[1..].all? { |l| l[:conn] == "or" } - @i18n.boolean_conj(list.map { |l| loc2xref(l) }, "or") + connectives_spans(@i18n.boolean_conj(list.map do |l| + loc2xref(l) + end, "or")) else ret = loc2xref(list[0]) list[1..].each { |l| ret = i18n_chain_boolean(ret, l) } @@ -144,8 +150,9 @@ def combine_conn(list) end def i18n_chain_boolean(value, entry) - @i18n.send("chain_#{entry[:conn]}").sub("%1", value) - .sub("%2", loc2xref(entry)) + connectives_spans(@i18n.send("chain_#{entry[:conn]}") + .sub("%1", value) + .sub("%2", loc2xref(entry))) end def can_conflate_xref_rendering?(locs) diff --git a/lib/isodoc/presentation_xml_convert.rb b/lib/isodoc/presentation_xml_convert.rb index 3f81acb0..902a5031 100644 --- a/lib/isodoc/presentation_xml_convert.rb +++ b/lib/isodoc/presentation_xml_convert.rb @@ -62,9 +62,9 @@ def section(docxml) annex docxml clause docxml # feeds clausetitle term docxml - index docxml clausetitle docxml # feeds floattitle floattitle docxml # feeds rearrange_clauses + index docxml # fed by strip_duplicate_ids toc docxml display_order docxml end @@ -79,6 +79,7 @@ def block(docxml) note docxml admonition docxml source docxml + ul docxml ol docxml dl docxml quote docxml diff --git a/lib/isodoc/word_function/body.rb b/lib/isodoc/word_function/body.rb index 2c337c4b..43effad7 100644 --- a/lib/isodoc/word_function/body.rb +++ b/lib/isodoc/word_function/body.rb @@ -102,40 +102,12 @@ def figure_aside_process(fig, aside, key) end end - def note_p_parse(node, div) - name = node.at(ns("./name"))&.remove - div.p class: "Note" do |p| - p.span class: "note_label" do |s| - name&.children&.each { |n| parse(n, s) } - end - insert_tab(p, 1) - node.first_element_child.children.each { |n| parse(n, p) } - end - node.element_children[1..].each { |n| parse(n, div) } + def note_p_class + "Note" end - def note_parse1(node, div) - name = node.at(ns("./name"))&.remove - div.p class: "Note" do |p| - p.span class: "note_label" do |s| - name&.children&.each { |n| parse(n, s) } - end - insert_tab(p, 1) - end - node.children.each { |n| parse(n, div) } - end - - def termnote_parse(node, out) - name = node&.at(ns("./name"))&.remove - out.div **note_attrs(node) do |div| - div.p class: "Note" do |p| - if name - name.children.each { |n| parse(n, p) } - p << " " - end - para_then_remainder(node.first_element_child, node, p, div) - end - end + def termnote_p_class + "Note" end def para_attrs(node) @@ -164,7 +136,7 @@ def formula_parse1(node, out) div.p do |_p| parse(node.at(ns("./stem")), div) insert_tab(div, 1) - if lbl = node&.at(ns("./name"))&.text + if lbl = node&.at(ns("./fmt-name"))&.text div << lbl end end @@ -185,10 +157,10 @@ def table_of_contents(clause, out) page_break(out) out.div **attr_code(preface_attrs(clause)) do |div| div.p class: "zzContents" do |p| - clause.at(ns("./title"))&.children&.each { |c| parse(c, p) } + clause.at(ns("./fmt-title"))&.children&.each { |c| parse(c, p) } end clause.elements.each do |e| - parse(e, div) unless e.name == "title" + parse(e, div) unless e.name == "fmt-title" end end end diff --git a/lib/isodoc/word_function/footnotes.rb b/lib/isodoc/word_function/footnotes.rb index 5e42d991..3479a236 100644 --- a/lib/isodoc/word_function/footnotes.rb +++ b/lib/isodoc/word_function/footnotes.rb @@ -83,7 +83,7 @@ def seen_footnote_parse(_node, out, footnote) def footnote_parse(node, out) return table_footnote_parse(node, out) if (@in_table || @in_figure) && - !node.ancestors.map(&:name).include?("name") + !node.ancestors.map(&:name).include?("fmt-name") fn = node["reference"] || UUIDTools::UUID.random_create.to_s return seen_footnote_parse(node, out, fn) if @seen_footnote.include?(fn) diff --git a/lib/isodoc/word_function/lists.rb b/lib/isodoc/word_function/lists.rb index b01540a0..4891abc4 100644 --- a/lib/isodoc/word_function/lists.rb +++ b/lib/isodoc/word_function/lists.rb @@ -25,13 +25,13 @@ def dl_parse(node, out) def dl_parse_nontable(node, out) out.div **attr_code(class: "figdl") do |div| - node["id"] and bookmark_parse(node, div) - list_title_parse(node, div) - node.elements.select { |n| dt_dd?(n) } - .each_slice(2) do |dt, dd| - dl_parse_nontable1(div, dt, dd) - end - dl_parse_notes(node, div) + node["id"] and bookmark_parse(node, div) + list_title_parse(node, div) + node.elements.select { |n| dt_dd?(n) } + .each_slice(2) do |dt, dd| + dl_parse_nontable1(div, dt, dd) + end + dl_parse_notes(node, div) end end @@ -58,13 +58,13 @@ def ddef_first_para(out, ddef) def ddef_other_paras(out, ddef) ddef.elements&.first&.name == "p" or return - ddef.children[1..-1].each { |n| parse(n, out) } + ddef.children[1..].each { |n| parse(n, out) } end def dl_parse_table(node, out) list_title_parse(node, out) out.table **attr_code(id: node["id"], - class: (node["class"] || "dl")) do |v| + class: node["class"] || "dl") do |v| node.elements.select { |n| dt_dd?(n) } .each_slice(2) do |dt, dd| dl_parse_table1(v, dt, dd) @@ -85,7 +85,9 @@ def dl_parse_table1(table, dterm, ddefn) end def dl_parse_table_notes(node, out) - remainder = node.elements.reject { |n| dt_dd?(n) || n.name == "name" } + remainder = node.elements.reject do |n| + dt_dd?(n) || n.name == "fmt-name" + end remainder.empty? and return out.tr do |tr| tr.td colspan: 2 do |td| diff --git a/lib/isodoc/word_function/postprocess_cover.rb b/lib/isodoc/word_function/postprocess_cover.rb index 112bcc46..fba8fc79 100644 --- a/lib/isodoc/word_function/postprocess_cover.rb +++ b/lib/isodoc/word_function/postprocess_cover.rb @@ -22,7 +22,6 @@ def word_cover(docxml) cover = File.read(@wordcoverpage, encoding: "UTF-8") cover = populate_template(cover, :word) coverxml = to_word_xhtml_fragment(cover) - #ins.children.first.previous = coverxml.to_xml(encoding: "US-ASCII") ins.add_first_child coverxml.to_xml(encoding: "US-ASCII") end @@ -32,7 +31,6 @@ def word_intro(docxml, level) docxml, level) intro = populate_template(intro, :word) introxml = to_word_xhtml_fragment(intro) - #ins.children.first.previous = introxml.to_xml(encoding: "US-ASCII") ins.add_first_child introxml.to_xml(encoding: "US-ASCII") end diff --git a/lib/isodoc/word_function/postprocess_table.rb b/lib/isodoc/word_function/postprocess_table.rb index 6966d59d..4b6ced7a 100644 --- a/lib/isodoc/word_function/postprocess_table.rb +++ b/lib/isodoc/word_function/postprocess_table.rb @@ -44,7 +44,7 @@ def colgroup_widths(table) def word_nested_tables(docxml) docxml.xpath("//table").each do |t| - t.xpath(".//table").reverse.each do |tt| + t.xpath(".//table").reverse_each do |tt| t.next = tt.remove end end diff --git a/lib/isodoc/word_function/table.rb b/lib/isodoc/word_function/table.rb index c5892237..0da24ee3 100644 --- a/lib/isodoc/word_function/table.rb +++ b/lib/isodoc/word_function/table.rb @@ -34,7 +34,7 @@ def make_tr_attr(cell, row, totalrows, header, bordered) def make_tr_attr_style(cell, row, rowmax, totalrows, opt) top = row.zero? ? "#{SW1} 1.5pt;" : "none;" bottom = "#{SW1} #{rowmax >= totalrows ? '1.5' : '1.0'}pt;" - ret = <<~STYLE.gsub(/\n/, "") + ret = <<~STYLE.delete("\n") border-top:#{top}mso-border-top-alt:#{top} border-bottom:#{bottom}mso-border-bottom-alt:#{bottom} STYLE @@ -46,7 +46,7 @@ def make_tr_attr_style(cell, row, rowmax, totalrows, opt) def keep_rows_together(_cell, rowmax, totalrows, opt) opt[:header] and return true @table_line_count > 15 and return false - (totalrows <= 10 && rowmax < totalrows) + totalrows <= 10 && rowmax < totalrows end def tbody_parse(node, table) diff --git a/lib/isodoc/xref.rb b/lib/isodoc/xref.rb index 506e752c..aebb612e 100644 --- a/lib/isodoc/xref.rb +++ b/lib/isodoc/xref.rb @@ -4,6 +4,7 @@ require_relative "xref/xref_gen_seq" require_relative "xref/xref_gen" require_relative "xref/xref_sect_gen" +require_relative "xref/xref_util" require_relative "class_utils" require_relative "function/utils" @@ -92,5 +93,7 @@ def ns(xpath) def l10n(text, lang = @lang, script = @script, locale = @locale) @i18n.l10n(text, lang, script, locale) end + + include ::IsoDoc::XrefGen::Util end end diff --git a/lib/isodoc/xref/xref_anchor.rb b/lib/isodoc/xref/xref_anchor.rb index 1406e5ce..c2a2dc8c 100644 --- a/lib/isodoc/xref/xref_anchor.rb +++ b/lib/isodoc/xref/xref_anchor.rb @@ -1,4 +1,5 @@ require "singleton" +require_relative "xref_util" module IsoDoc module XrefGen @@ -29,37 +30,51 @@ def get_anchors @anchors end - def anchor_struct_label(lbl, elem) + def anchor_struct_label(lbl, node, elem) case elem - when @labels["appendix"] then "#{elem} #{lbl}" + when @labels["appendix"] + s = "" \ + "#{lbl}" + "#{elem} #{s}" else - lbl.to_s + anchor_struct_value(lbl, elem) end end - def anchor_struct_xref(lbl, elem) - l10n("#{elem} #{anchor_struct_value(lbl, elem)}") + def anchor_struct_xref(lbl, node, elem) + unless lbl.blank? + lbl = semx(node, lbl) + s = " #{anchor_struct_value(lbl, elem)}" + end + l10n("#{elem}#{s}") + .gsub(/ $/, "") end def anchor_struct_value(lbl, elem) case elem - when @labels["formula"], @labels["inequality"] then "(#{lbl})" + # TODO hardcoded ( ) ? + when @labels["formula"], @labels["inequality"] then <<~SPAN.strip + #{delim_wrap('(')}#{lbl}#{delim_wrap(')')} + SPAN else - lbl + lbl.to_s end end - def anchor_struct(lbl, container, elem, type, unnumb = false) - ret = {} - ret[:label] = unnumb == "true" ? nil : anchor_struct_label(lbl, elem) - ret[:xref] = anchor_struct_xref(unnumb == "true" ? "(??)" : lbl, elem) - ret[:xref].gsub!(/ $/, "") - ret[:container] = @klass.get_clause_id(container) unless container.nil? - ret[:type] = type - ret[:elem] = elem - ret[:value] = anchor_struct_value(lbl, elem) + # def anchor_struct(lbl, container, elem, type, unnumb = false) + def anchor_struct(lbl, node, elem_name, type, opt = {}) + ret = { type: type, elem: elem_name, label: nil } + opt[:unnumb] != "true" and + ret[:label] = anchor_struct_label(lbl, node, elem_name) + ret[:xref] = + anchor_struct_xref(opt[:unnumb] == "true" ? "(??)" : lbl, node, + elem_name) + ret[:container] = @klass.get_clause_id(node) if opt[:container] + ret[:value] = stripsemx(lbl) ret end + + include ::IsoDoc::XrefGen::Util end end end diff --git a/lib/isodoc/xref/xref_counter_types.rb b/lib/isodoc/xref/xref_counter_types.rb index f358bdd3..755c8aaa 100644 --- a/lib/isodoc/xref/xref_counter_types.rb +++ b/lib/isodoc/xref/xref_counter_types.rb @@ -2,11 +2,12 @@ module IsoDoc class Xref - def clause_counter(num = 0, opts = { numerals: :arabic }) + def clause_counter(num = 0, opts = {}) + opts[:numerals] ||= :arabic ::IsoDoc::XrefGen::Counter.new(num, opts) end - def list_counter(num = 0, opts = { numerals: :arabic }) + def list_counter(num = 0, opts = {}) ::IsoDoc::XrefGen::Counter.new(num, opts) end end diff --git a/lib/isodoc/xref/xref_gen.rb b/lib/isodoc/xref/xref_gen.rb index 06ded319..6a8135f6 100644 --- a/lib/isodoc/xref/xref_gen.rb +++ b/lib/isodoc/xref/xref_gen.rb @@ -28,14 +28,18 @@ def amend_autonums(amend) autonum end - def termnote_label(note) - @labels["termnote"].gsub("%", note.to_s) + def termnote_label(node, label) + if label.blank? + @labels["termnote"].gsub(/%\s?/, "") + else + @labels["termnote"].gsub("%", semx(node, label.to_s)) + end end def increment_label(elems, node, counter, increment: true) elems.size == 1 && !node["number"] and return "" counter.increment(node) if increment - " #{counter.print}" + counter.print end def termnote_anchor_names(docxml) @@ -44,10 +48,10 @@ def termnote_anchor_names(docxml) t.xpath(ns("./termnote")).noblank.each do |n| c.increment(n) @anchors[n["id"]] = - { label: termnote_label(c.print), type: "termnote", + { label: termnote_label(n, c.print), type: "termnote", value: c.print, elem: @labels["termnote"], container: t["id"], - xref: "#{@labels['note_xref']} #{c.print}" } + xref: anchor_struct_xref(c.print, n, @labels["note_xref"]) } end end end @@ -63,7 +67,7 @@ def termexample_anchor_names(docxml) { label: idx, type: "termexample", value: idx, elem: @labels["example_xref"], container: t["id"], - xref: "#{@labels['example_xref']} #{idx}" } + xref: anchor_struct_xref(idx, n, @labels["example_xref"]) } end end end @@ -73,7 +77,7 @@ def note_anchor_names(sections) notes = s.xpath(child_asset_path("note")) - s.xpath(ns(".//figure//note | .//table//note")) note_anchor_names1(notes, Counter.new) - note_anchor_names(s.xpath(ns(CHILD_SECTIONS))) + note_anchor_names(s.xpath(ns(child_sections))) end end @@ -81,7 +85,8 @@ def note_anchor_names1(notes, counter) notes.noblank.each do |n| @anchors[n["id"]] = anchor_struct(increment_label(notes, n, counter), n, - @labels["note_xref"], "note", false) + @labels["note_xref"], "note", + { container: true, unnumb: false }) end end @@ -90,7 +95,7 @@ def admonition_anchor_names(sections) s.at(ns(".//admonition[@type = 'box']")) or next notes = s.xpath(child_asset_path("admonition[@type = 'box']")) admonition_anchor_names1(notes, Counter.new) - admonition_anchor_names(s.xpath(ns(CHILD_SECTIONS))) + admonition_anchor_names(s.xpath(ns(child_sections))) end end @@ -98,7 +103,8 @@ def admonition_anchor_names1(notes, counter) notes.noblank.each do |n| @anchors[n["id"]] ||= anchor_struct(increment_label(notes, n, counter), n, - @labels["box"], "admonition", n["unnumbered"]) + @labels["box"], "admonition", + { container: true, unnumb: n["unnumbered"] }) end end @@ -106,7 +112,7 @@ def example_anchor_names(sections) sections.each do |s| notes = s.xpath(child_asset_path("example")) example_anchor_names1(notes, Counter.new) - example_anchor_names(s.xpath(ns(CHILD_SECTIONS))) + example_anchor_names(s.xpath(ns(child_sections))) end end @@ -114,7 +120,8 @@ def example_anchor_names1(notes, counter) notes.noblank.each do |n| @anchors[n["id"]] ||= anchor_struct(increment_label(notes, n, counter), n, - @labels["example_xref"], "example", n["unnumbered"]) + @labels["example_xref"], "example", + { unnumb: n["unnumbered"], container: true }) end end @@ -122,27 +129,35 @@ def list_anchor_names(sections) sections.each do |s| notes = s.xpath(ns(".//ol")) - s.xpath(ns(".//clause//ol")) - s.xpath(ns(".//appendix//ol")) - s.xpath(ns(".//ol//ol")) - c = list_counter + c = list_counter(0, {}) notes.noblank.each do |n| - @anchors[n["id"]] = anchor_struct(increment_label(notes, n, c), n, - @labels["list"], "list", false) + @anchors[n["id"]] = + anchor_struct(increment_label(notes, n, c), n, + @labels["list"], "list", + { unnumb: false, container: true }) list_item_anchor_names(n, @anchors[n["id"]], 1, "", notes.size != 1) end - list_anchor_names(s.xpath(ns(CHILD_SECTIONS))) + list_anchor_names(s.xpath(ns(child_sections))) end end - def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list) - c = list_counter(list["start"] ? list["start"].to_i - 1 : 0) + def list_item_delim + ")" + end + + def list_item_anchor_names(list, list_anchor, depth, prev_label, +refer_list) + c = list_counter(list["start"] ? list["start"].to_i - 1 : 0, {}) list.xpath(ns("./li")).each do |li| bare_label, label = - list_item_value(li, c, depth, { list_anchor:, prev_label:, - refer_list: depth == 1 ? refer_list : nil }) - li["id"] and @anchors[li["id"]] = - { label: bare_label, bare_xref: "#{label})", - xref: "#{label})", - type: "listitem", refer_list:, - container: list_anchor[:container] } + list_item_value(li, c, depth, + { list_anchor:, prev_label:, + refer_list: depth == 1 ? refer_list : nil }) + li["id"] ||= "_#{UUIDTools::UUID.random_create}" + @anchors[li["id"]] = + { label: bare_label, bare_xref: "#{label})", type: "listitem", + xref: %[#{label}#{delim_wrap(list_item_delim)}], refer_list:, + container: list_anchor[:container] } (li.xpath(ns(".//ol")) - li.xpath(ns(".//ol//ol"))).each do |ol| list_item_anchor_names(ol, list_anchor, depth + 1, label, refer_list) @@ -152,18 +167,21 @@ def list_item_anchor_names(list, list_anchor, depth, prev_label, refer_list) def list_item_value(entry, counter, depth, opts) label = counter.increment(entry).listlabel(entry.parent, depth) + s = semx(entry, label) [label, - list_item_anchor_label(label, opts[:list_anchor], opts[:prev_label], + list_item_anchor_label(s, opts[:list_anchor], opts[:prev_label], opts[:refer_list])] end def list_item_anchor_label(label, list_anchor, prev_label, refer_list) prev_label.empty? or - label = @i18n.list_nested_xref.sub("%1", "#{prev_label})") - .sub("%2", label) + label = @klass.connectives_spans(@i18n.list_nested_xref + .sub("%1", %[#{prev_label}#{delim_wrap(list_item_delim)}]) + .sub("%2", label)) refer_list and - label = @i18n.list_nested_xref.sub("%1", list_anchor[:xref]) - .sub("%2", label) + label = @klass.connectives_spans(@i18n.list_nested_xref + .sub("%1", list_anchor[:xref]) + .sub("%2", label)) label end @@ -172,7 +190,7 @@ def deflist_anchor_names(sections) notes = s.xpath(ns(".//dl")) - s.xpath(ns(".//clause//dl")) - s.xpath(ns(".//appendix//dl")) - s.xpath(ns(".//dl//dl")) deflist_anchor_names1(notes, Counter.new) - deflist_anchor_names(s.xpath(ns(CHILD_SECTIONS))) + deflist_anchor_names(s.xpath(ns(child_sections))) end end @@ -180,14 +198,15 @@ def deflist_anchor_names1(notes, counter) notes.noblank.each do |n| @anchors[n["id"]] = anchor_struct(increment_label(notes, n, counter), n, - @labels["deflist"], "deflist", false) + @labels["deflist"], "deflist", + { unnumb: false, container: true }) deflist_term_anchor_names(n, @anchors[n["id"]]) end end def deflist_term_anchor_names(list, list_anchor) list.xpath(ns("./dt")).each do |li| - label = "#{list_anchor[:xref]}: #{dt2xreflabel(li)}" + label = deflist_term_anchor_lbl(li, list_anchor) li["id"] and @anchors[li["id"]] = { xref: label, type: "deflistitem", container: list_anchor[:container] } @@ -197,6 +216,11 @@ def deflist_term_anchor_names(list, list_anchor) end end + def deflist_term_anchor_lbl(listitem, list_anchor) + s = semx(listitem, dt2xreflabel(listitem)) + %(#{list_anchor[:xref]}#{delim_wrap(":")} #{s}) + end + def dt2xreflabel(dterm) label = dterm.dup label.xpath(ns(".//p")).each { |x| x.replace(x.children) } diff --git a/lib/isodoc/xref/xref_gen_seq.rb b/lib/isodoc/xref/xref_gen_seq.rb index 4a4d17df..5205dfb5 100644 --- a/lib/isodoc/xref/xref_gen_seq.rb +++ b/lib/isodoc/xref/xref_gen_seq.rb @@ -11,6 +11,10 @@ def hierfigsep "-" end + def hierreqtsep + "-" + end + def subfigure_increment(idx, counter, elem) if elem.parent.name == "figure" then idx += 1 else @@ -30,7 +34,8 @@ def sequential_figure_names(clause, container: false) clause.xpath(ns(self.class::FIGURE_NO_CLASS)).noblank.each do |t| # labelled_ancestor(t, %w(figure)) and next # disable nested figure labelling j = subfigure_increment(j, c, t) - sequential_figure_body(j, c, t, "figure", container:) + sublabel = subfigure_label(j) + figure_anchor(t, sublabel, c.print, "figure", container: container) end sequential_figure_class_names(clause, container:) end @@ -43,24 +48,69 @@ def sequential_figure_class_names(clause, container: false) c[t["class"]] ||= Counter.new # labelled_ancestor(t, %w(figure)) and next j = subfigure_increment(j, c[t["class"]], t) - sequential_figure_body(j, c[t["class"]], t, t["class"], - container:) + sublabel = subfigure_label(j) + figure_anchor(t, sublabel, c[t["class"]].print, t["class"], + container: container) end end + def hier_separator(markup: false) + h = hiersep + h.blank? || !markup or h = delim_wrap(h) + h + end + def subfigure_label(subfignum) - subfignum.zero? and return "" - "#{hierfigsep}#{subfignum}" + subfignum.zero? and return + subfignum.to_s + end + + def subfigure_separator(markup: false) + h = hierfigsep + h.blank? || !markup or h = delim_wrap(h) + h + end + + def subreqt_separator(markup: false) + h = hierreqtsep + h.blank? || !markup or h = delim_wrap(h) + h + end + + def subfigure_delim + "" + end + + def figure_anchor(elem, sublabel, label, klass, container: false) + if sublabel + /#{label}
#{@anchors[elem["id"]][:semx]}" + @anchors[elem["id"]][:xref] = "#{label} #{@anchors[elem["id"]][:semx]}" + end model.permission_parts(elem, id, label, klass).each do |n| @anchors[n[:id]] = anchor_struct(n[:number], n[:elem], n[:label], - n[:klass], false) + n[:klass], { unnumb: false, container: }) end end @@ -156,44 +216,61 @@ def sequential_asset_names(clause, container: false) sequential_permission_names(clause, container:) end - def hierarchical_figure_names(clause, num) + def nodeSet(clauses) + case clauses + when Nokogiri::XML::Node + [clauses] + when Nokogiri::XML::NodeSet + clauses + end + end + + # these can take a NodeSet as argument; semx will point to members of the NodeSet, + # but numbering will be consecutive + def hierarchical_figure_names(clauses, num) c = Counter.new j = 0 + nodeSet(clauses).each do |clause| clause.xpath(ns(self.class::FIGURE_NO_CLASS)).noblank.each do |t| # labelled_ancestor(t, %w(figure)) and next j = subfigure_increment(j, c, t) - hierarchical_figure_body(num, j, c, t, "figure") + sublabel = subfigure_label(j) + # hierarchical_figure_body(num, j, c, t, "figure") + #figure_anchor(t, sublabel, "#{num}#{hier_separator}#{c.print}", "figure") + #require "debug"; binding.b + figure_anchor(t, sublabel, hiersemx(clause, num, c, t), "figure") end hierarchical_figure_class_names(clause, num) + end end - def hierarchical_figure_class_names(clause, num) + def hierarchical_figure_class_names(clauses, num) c = {} j = 0 + nodeSet(clauses).each do |clause| clause.xpath(ns(".//figure[@class][not(@class = 'pseudocode')]")) .noblank.each do |t| # labelled_ancestor(t, %w(figure)) and next c[t["class"]] ||= Counter.new j = subfigure_increment(j, c[t["class"]], t) - hierarchical_figure_body(num, j, c[t["class"]], t, t["class"]) + sublabel = subfigure_label(j) + # hierarchical_figure_body(num, j, c[t["class"]], t, t["class"]) + #figure_anchor(t, sublabel, "#{num}#{hier_separator}#{c[t['class']].print}", t["class"]) + figure_anchor(t, sublabel, hiersemx(clause, num, c[t["class"]], t), t["class"]) + end end end - def hierarchical_figure_body(num, subfignum, counter, block, klass) - label = "#{num}#{hiersep}#{counter.print}" + - subfigure_label(subfignum) - @anchors[block["id"]] = - anchor_struct(label, nil, @labels[klass] || klass.capitalize, - klass, block["unnumbered"]) - end - - def hierarchical_table_names(clause, num) + def hierarchical_table_names(clauses, num) c = Counter.new + nodeSet(clauses).each do |clause| clause.xpath(ns(".//table")).noblank.each do |t| # labelled_ancestor(t) and next @anchors[t["id"]] = - anchor_struct("#{num}#{hiersep}#{c.increment(t).print}", - nil, @labels["table"], "table", t["unnumbered"]) + #anchor_struct("#{num}#{hier_separator}#{c.increment(t).print}", + anchor_struct(hiersemx(clause, num, c.increment(t), t), + t, @labels["table"], "table", { unnumb: t["unnumbered"], container: false }) + end end end @@ -204,47 +281,59 @@ def hierarchical_asset_names(clause, num) hierarchical_permission_names(clause, num) end - def hierarchical_formula_names(clause, num) + def hierarchical_formula_names(clauses, num) c = Counter.new + nodeSet(clauses).each do |clause| clause.xpath(ns(".//formula")).noblank.each do |t| @anchors[t["id"]] = anchor_struct( - "#{num}#{hiersep}#{c.increment(t).print}", nil, + #"#{num}#{hier_separator}#{c.increment(t).print}", t, + hiersemx(clause, num, c.increment(t), t), t, t["inequality"] ? @labels["inequality"] : @labels["formula"], - "formula", t["unnumbered"] + "formula", { unnumb: t["unnumbered"], container: false } ) end + end end - def hierarchical_permission_names(clause, num) + def hierarchical_permission_names(clauses, num) c = ReqCounter.new + nodeSet(clauses).each do |clause| clause.xpath(ns(FIRST_LVL_REQ)).noblank.each do |t| m = @reqt_models.model(t["model"]) klass, label = reqt2class_label(t, m) - id = "#{num}#{hiersep}#{c.increment(label, t).print}" - hierarchical_permission_body(id, t, label, klass, m) - hierarchical_permission_children(t, id) + #id = "#{num}#{hier_separator}#{c.increment(label, t).print}" + id = hiersemx(clause, num, c.increment(label, t), t) + sequential_permission_body(id, nil, t, label, klass, m, container: false) + sequential_permission_children(t, id, klass, container: false) end + end end + # TODO remove def hierarchical_permission_children(block, lbl) c = ReqCounter.new block.xpath(ns(REQ_CHILDREN)).noblank.each do |t| m = @reqt_models.model(t["model"]) klass, label = reqt2class_nested_label(t, m) - id = "#{lbl}#{hierfigsep}#{c.increment(label, t).print}" - hierarchical_permission_body(id, t, label, klass, m) + id = "#{lbl}#{subreqt_separator}#{c.increment(label, t).print}" + sequential_permission_body(c.print, lbl, t, label, klass, m) hierarchical_permission_children(t, id) end end - def hierarchical_permission_body(id, block, label, klass, model) - @anchors[block["id"]] = model.postprocess_anchor_struct( - block, anchor_struct(id, nil, - label, klass, block["unnumbered"]) + # TODO remove + def hierarchical_permission_body(id, parent_id, elem, label, klass, model) + @anchors[elem["id"]] = model.postprocess_anchor_struct( + elem, anchor_struct(id, elem, + label, klass, { unnumb: elem["unnumbered"], container: false }) ) - model.permission_parts(block, id, label, klass).each do |n| - @anchors[n[:id]] = anchor_struct(n[:number], nil, n[:label], - n[:klass], false) + x = "#{subreqt_separator(markup: true)}#{semx(elem, id)}" + @anchors[elem["id"]][:label] = "#{semx(elem.parent, parent_id)}#{x}" + @anchors[elem["id"]][:xref] = @anchors[elem.parent["id"]][:xref] + x + model.permission_parts(elem, id, label, klass).each do |n| + # we don't have an n["id"], so we allow n[:id] in anchor_struct + @anchors[n[:id]] = anchor_struct(n[:number], n, n[:label], + n[:klass], { unnumb: false, container: false }) end end end diff --git a/lib/isodoc/xref/xref_sect_gen.rb b/lib/isodoc/xref/xref_sect_gen.rb index 60686692..536f5e7b 100644 --- a/lib/isodoc/xref/xref_sect_gen.rb +++ b/lib/isodoc/xref/xref_sect_gen.rb @@ -104,8 +104,10 @@ def unnumbered_names(clause) title = clause_title(clause, use_elem_name: true) preface_name_anchors(clause, 1, title) clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i| - preface_names1(c, c.at(ns("./title"))&.text, - "#{title}, #{i + 1}", 2) + t = c.at(ns("./title")) + tt = "#{semx(clause, title, clause.name)}" \ + ", #{semx(c, i + 1)}" + preface_names1(c, t ? semx(c, t.text, c.name) : nil, tt, 2) end end @@ -113,15 +115,18 @@ def preface_names1(clause, title, parent_title, level) label = title || parent_title preface_name_anchors(clause, level, title || parent_title) clause.xpath(ns(SUBCLAUSES)).each_with_index do |c, i| - preface_names1(c, c.at(ns("./title"))&.text, "#{label} #{i + 1}", + t = c.at(ns("./title")) + preface_names1(c, t ? semx(c, t.text, c.name) : nil, + "#{label} #{semx(c, i + 1)}", level + 1) end end def preface_name_anchors(clause, level, title) + xref = semx(clause, title, clause.name) @anchors[clause["id"]] = { label: nil, level:, - xref: title, title: nil, + xref:, title: nil, type: "clause", elem: @labels["clause"] } end @@ -136,20 +141,32 @@ def middle_section_asset_names(doc) def section_names(clause, num, lvl) unnumbered_section_name?(clause) and return num num.increment(clause) - section_name_anchors(clause, num.print, lvl) + lbl = semx(clause, num.print) + section_name_anchors(clause, lbl, lvl) clause.xpath(ns(SUBCLAUSES)) - .each_with_object(clause_counter(0, prefix: num.print)) do |c, i| - section_names1(c, i.increment(c).print, lvl + 1) + .each_with_object(clause_counter(0)) do |c, i| + section_names1(c, lbl, i.increment(c).print, lvl + 1) end num end - def section_names1(clause, num, level) + def clause_number_semx(parentnum, clause, num) + if clause["branch-number"] + semx(clause, clause["branch-number"]) + elsif parentnum.nil? + semx(clause, num) + else + "#{parentnum}#{delim_wrap(clausesep)}#{semx(clause, num)}" + end + end + + def section_names1(clause, parentnum, num, level) unnumbered_section_name?(clause) and return num - section_name_anchors(clause, num, level) - i = clause_counter(0, prefix: num) + lbl = clause_number_semx(parentnum, clause, num) + section_name_anchors(clause, lbl, level) + i = clause_counter(0) clause.xpath(ns(SUBCLAUSES)).each do |c| - section_names1(c, i.increment(c).print, level + 1) + section_names1(c, lbl, i.increment(c).print, level + 1) end end @@ -162,10 +179,16 @@ def unnumbered_section_name?(clause) false end + def clausesep + "." + end + def section_name_anchors(clause, num, level) + xref = labelled_autonum(@labels["clause"], num) + label = num + c = clause_title(clause) and title = semx(clause, c, "title") @anchors[clause["id"]] = - { label: num, xref: "#{@labels['clause']} #{num}", - title: clause_title(clause), level:, type: "clause", + { label:, xref:, title:, level:, type: "clause", elem: @labels["clause"] } end @@ -173,44 +196,53 @@ def annex_name_lbl(clause, num) obl = "(#{@labels['inform_annex']})" clause["obligation"] == "normative" and obl = "(#{@labels['norm_annex']})" + obl = "#{l10n obl}" title = Common::case_with_markup(@labels["annex"], "capital", @script) - "#{title} #{num}
#{obl}" + s = labelled_autonum(title, num) + "#{s}
#{obl}" end def annex_name_anchors(clause, num, level) label = num level == 1 && clause.name == "annex" and - label = annex_name_lbl(clause, num) + label = annex_name_lbl(clause, label) + xref = labelled_autonum(@labels["annex"], num) + c = clause_title(clause) and title = semx(clause, c, "title") @anchors[clause["id"]] = - { label:, + { label:, xref:, title:, elem: @labels["annex"], type: "clause", - subtype: "annex", value: num.to_s, level:, - title: clause_title(clause), - xref: "#{@labels['annex']} #{num}" } + subtype: "annex", value: num.to_s, level: } end def annex_names(clause, num) - annex_name_anchors(clause, num, 1) + label = semx(clause, num) + annex_name_anchors(clause, label, 1) if @klass.single_term_clause?(clause) annex_names1(clause.at(ns("./references | ./terms | ./definitions")), - num.to_s, 1) + nil, num.to_s, 1) else clause.xpath(ns(SUBCLAUSES)) - .each_with_object(clause_counter(0, prefix: num)) do |c, i| - annex_names1(c, i.increment(c).print, 2) + .each_with_object(clause_counter(0)) do |c, i| + annex_names1(c, label, i.increment(c).print, 2) end end - hierarchical_asset_names(clause, num) + hierarchical_asset_names(clause, label) end - def annex_names1(clause, num, level) - annex_name_anchors(clause, num, level) - i = clause_counter(0, prefix: num) + def annex_names1(clause, parentnum, num, level) + lbl = clause_number_semx(parentnum, clause, num) + annex_name_anchors1(clause, lbl, level) + i = clause_counter(0) clause.xpath(ns(SUBCLAUSES)).each do |c| - annex_names1(c, i.increment(c).print, level + 1) + annex_names1(c, lbl, i.increment(c).print, level + 1) end end + + # subclauses of Annexes + def annex_name_anchors1(clause, num, level) + annex_name_anchors(clause, num, level) + end end end end diff --git a/lib/isodoc/xref/xref_util.rb b/lib/isodoc/xref/xref_util.rb index f0e6d1e2..93942787 100644 --- a/lib/isodoc/xref/xref_util.rb +++ b/lib/isodoc/xref/xref_util.rb @@ -14,7 +14,7 @@ def blank? module IsoDoc module XrefGen - module Blocks + module Util def blank?(text) text.nil? || text.empty? end @@ -43,6 +43,48 @@ def child_asset_path(asset) CHILD_SECTIONS = "./clause | ./appendix | ./terms | ./definitions | " \ "./references".freeze + + def child_sections + CHILD_SECTIONS + end + + # if hierarchically marked up node in label already, + # leave alone, else wrap in semx + def semx(node, label, element = "autonum") + label = label.to_s + id = node["id"] || node[:id] + /#{l}) + end + + # assume parent is already semantically annotated with semx + def hiersemx(parent, parentlabel, counter, element, sep: nil) + sep ||= hier_separator(markup: true) + "#{semx(parent, parentlabel)}#{sep}#{semx(element, counter.print)}" + end + + def delim_wrap(delim, klass = "fmt-autonum-delim") + delim.blank? and return "" + "#{delim}" + end + + def stripsemx(elem) + elem.nil? and return elem + xml = Nokogiri::XML::DocumentFragment.parse(elem) + xml.traverse do |x| + x.name == "semx" || + (x.name == "span" && /^fmt-/.match?(x["class"])) and + x.replace(x.children) + end + xml.to_xml(indent: 0, encoding: "UTF-8", + save_with: Nokogiri::XML::Node::SaveOptions::AS_XML) + end + + def labelled_autonum(label, autonum) + label.blank? and return autonum + l10n("#{label} #{autonum}") + end end end end diff --git a/lib/nokogiri/xml/node.rb b/lib/nokogiri/xml/node.rb index 95b5985e..b0ec45d9 100644 --- a/lib/nokogiri/xml/node.rb +++ b/lib/nokogiri/xml/node.rb @@ -7,6 +7,7 @@ def add_first_child(content) else children.first.previous = content end + self end end end diff --git a/spec/assets/i18n.yaml b/spec/assets/i18n.yaml index fd1cbee0..1ecba3a4 100644 --- a/spec/assets/i18n.yaml +++ b/spec/assets/i18n.yaml @@ -15,6 +15,7 @@ norm_annex: normative figure: figur-etikedo duvorta example: Ekzempl-etikedo Duvorta note: NOTO +note_xref: noto locality: { table: Tabelo, prelude: preludo @@ -41,3 +42,4 @@ SpelloutRules: edition_ordinal: "eldono {{ var1 | ordinal_word: edition, '' }}" edition: eldono no_identifier: null +nested_xref: "%1%2" diff --git a/spec/isodoc/blocks_notes_spec.rb b/spec/isodoc/blocks_notes_spec.rb index 582b3c97..0cd1b9ba 100644 --- a/spec/isodoc/blocks_notes_spec.rb +++ b/spec/isodoc/blocks_notes_spec.rb @@ -4,7 +4,7 @@ it "processes unlabelled notes" do input = <<~INPUT - +

These results are based on a study carried out on three different types of kernel.

@@ -15,45 +15,62 @@
INPUT presxml = <<~OUTPUT - - - - - Table of contents - - Foreword - - NOTE 1 -

- These results are based on a study carried out on three different - types of kernel. -

-
- -

- These results are based on a study carried out on three different - types of kernel. -

-
-
-
-
+ + + + Table of contents + + + Foreword + + Foreword + + + + + NOTE + 1 + + + + + + + Note + 1 + + + + Foreword + + , + Note + 1 + +

These results are based on a study carried out on three different types of kernel.

+
+ +

These results are based on a study carried out on three different types of kernel.

+
+
+
+
OUTPUT html = <<~OUTPUT #{HTML_HDR}
-
+

Foreword

- NOTE 1 -   These results are based on a study carried out on three + NOTE 1  + These results are based on a study carried out on three different types of kernel.

-   These results are based on a study carried out on three + These results are based on a study carried out on three different types of kernel.

@@ -63,35 +80,22 @@ OUTPUT doc = <<~OUTPUT - - - - -
-

 

-
-

-
-

-
-

-
-

-
-

Table of contents

-
-

-
-

-
+ word = <<~OUTPUT + #{WORD_HDR} +

+
+

+

Foreword

EXAMPLE — Title

Hello

-

-
-           -
-         -

+

+
+   +
+   +

Sample

@@ -352,18 +412,23 @@ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(html) - expect(Xml::C14n.format(IsoDoc::WordConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(doc) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output))) + .to be_equivalent_to Xml::C14n.format(presxml) + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(html) + expect(Xml::C14n.format(strip_guid(IsoDoc::WordConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(word) end it "processes sequences of examples" do input = <<~INPUT - +

Hello

@@ -378,37 +443,95 @@
INPUT output = <<~OUTPUT - - - - - Table of contents - - Foreword - - EXAMPLE 1 -

Hello

-
- - EXAMPLE 2 — Title -

Hello

-
- - EXAMPLE -

Hello

-
-
-
-
+ + + + Table of contents + + + Foreword + + Foreword + + + + + EXAMPLE + 1 + + + + Example + 1 + + + + Foreword + + , + Example + 1 + +

Hello

+
+ + Title + + + EXAMPLE + 2 + +  — + Title + + + Example + 2 + + + + Foreword + + , + Example + 2 + +

Hello

+
+ + + + EXAMPLE + + + + Example + (??) + + + + Foreword + + , + Example + (??) + +

Hello

+
+
+
+
OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(output) + expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true)))) + .to be_equivalent_to Xml::C14n.format(output) end it "processes formulae" do input = <<~INPUT - + r = 1 %
@@ -427,41 +550,127 @@ r = 1 % + + + r = 1 % + + INPUT presxml = <<~INPUT - - - - Table of contents - - Foreword - - r = 1 % -

where

-
-
- r -
-
-

is the repeatability limit.

-
-
- - NOTE -

[durationUnits] is essentially a duration statement without the "P" prefix. "P" is unnecessary because between "G" and "U" duration is always expressed.

-
-
- (1) - r = 1 % - -
-
+ + + + Table of contents + + + Foreword + + Foreword + + + r = 1 % +

where

+
+
+ r +
+
+

is the repeatability limit.

+
+
+ + + + NOTE + + + + + + + Note + + + + Foreword + + , + Note + +

[durationUnits] is essentially a duration statement without the "P" prefix. "P" is unnecessary because between "G" and "U" duration is always expressed.

+
+
+ + + + ( + 1 + ) + + + + Formula + ( + 1 + ) + + + + Foreword + + , + Formula + ( + 1 + ) + + r = 1 % + +
+
+ + + + + Annex + A + + +
+ (informative) +
+ + Annex + A + + + + + ( + A + . + 1 + ) + + + + Formula + ( + A + . + 1 + ) + + r = 1 % + +
+
INPUT html = <<~OUTPUT #{HTML_HDR}
-
+

Foreword

(#(r = 1 %)#)

where

@@ -473,39 +682,37 @@
-

NOTE  [durationUnits] is essentially a duration statement without the "P" prefix. "P" is unnecessary because between "G" and "U" duration is always expressed.

+

NOTE  [durationUnits] is essentially a duration statement without the "P" prefix. "P" is unnecessary because between "G" and "U" duration is always expressed.

(#(r = 1 %)#)  (1)

+
+
+

+ Annex A +
+ (informative) +

+
+
+

+ (#(r = 1 %)#) +   (A.1) +

+
+
+
OUTPUT word = <<~OUTPUT - - - - - -
-

 

-
-

-
-

-
-

-
-

-
-

Table of contents

-
+ #{WORD_HDR}


-
+

Foreword

@@ -528,8 +735,7 @@

- NOTE -   + NOTE  [durationUnits] is essentially a duration statement without the "P" prefix. "P" is unnecessary because between "G" and "U" duration is always expressed. @@ -551,16 +757,41 @@

-
+

+
+

+
+

+ Annex A +
+ (informative) +

+
+
+

+ (#(r = 1 %)#) +   + (A.1) +

+
+
+
+
+
OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(html) - expect(Xml::C14n.format(IsoDoc::WordConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(word) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output))) + .to be_equivalent_to Xml::C14n.format(presxml) + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(html) + expect(Xml::C14n.format(strip_guid(IsoDoc::WordConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(word) end it "processes paragraph attributes" do @@ -568,9 +799,9 @@ - Table of contents + Table of contents - Foreword + Foreword

Vache Equipment
Fictitious
World

@@ -595,18 +826,7 @@ OUTPUT word = <<~OUTPUT - - - - -
-

 

-
-

-
-

-
-

-
-

-
-

Table of contents

-
+ #{WORD_HDR}


-
+

Foreword

@@ -407,14 +564,17 @@ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true).gsub(/</, "<")))) + pres_output = IsoDoc::PresentationXMLConvert.new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output + .gsub(/</, "<")))) .to be_equivalent_to Xml::C14n.format(presxml) expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true)))).to be_equivalent_to Xml::C14n.format(html) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(html) FileUtils.rm_rf "spec/assets/odf1.emf" expect(Xml::C14n.format(strip_guid(IsoDoc::WordConvert.new({}) - .convert("test", presxml, true) + .convert("test", pres_output, true) .gsub(/['"][^'".]+\.(gif|xml)['"]/, "'_.\\1'") .gsub(/mso-bookmark:_Ref\d+/, "mso-bookmark:_Ref")))) .to be_equivalent_to Xml::C14n.format(word) @@ -423,7 +583,7 @@ it "processes figure classes, existing figure keys" do input = <<~INPUT - +
Split-it-right sample divider

X

alttext @@ -453,24 +613,50 @@ - Table of contents - - Foreword -
- - Diagram 1 — Split-it-right - sample - divider - -

X

-
-
+ Table of contents + + + Foreword + + Foreword + +
+ + Split-it-right + sample + divider + +

X

+
+
+ + + Diagram + 1 + +  — + + Split-it-right + sample + divider + +

X

+
+
+
+ + Diagram + 1 + alttext
- Key of figure + Key of figure + + Key of figure +

a

@@ -485,8 +671,17 @@

-
- Plate 1 +
+ + + Plate + 1 + + + + Plate + 1 +
A < B
@@ -520,11 +715,24 @@ - Table of contents + Table of contents - Foreword -
- Figure 1 + + Foreword + + Foreword + +
+ + + Figure + 1 + + + + Figure + 1 + @@ -556,15 +764,27 @@ INPUT presxml = <<~OUTPUT - - Table of contents + Table of contents - Foreword -
- Figure 1 + + Foreword + + Foreword + +
+ +
+ Figure + 1 + + + + Figure + 1 + @@ -597,25 +817,7 @@ HTML doc = <<~DOC - - - - - -
-

 

-
-

-
-

-
-

-
-

-
-

Table of contents

-
+ #{WORD_HDR}


@@ -673,11 +875,24 @@ - Table of contents + Table of contents - Foreword -
- Figure 1 + + Foreword + + Foreword + +
+ + + Figure + 1 + + + + Figure + 1 + @@ -698,25 +913,7 @@ OUTPUT word = <<~OUTPUT - - - - - -
-

 

-
-

-
-

-
-

-
-

-
-

Table of contents

-
+ #{WORD_HDR}


@@ -765,12 +962,12 @@ - Table of contents + Table of contents - Foreword + Foreword LabelA B C -
Label

  A

+
Label

  A

A B C

  A

@@ -782,10 +979,7 @@

Foreword

-
-                         A B C
-                       
-

Label

+
A B C

   @@ -848,28 +1042,34 @@ INPUT output = <<~OUTPUT - - Table of contents - -

- - -
-
- Workmap - -
- - - - - + + + + Table of contents + + + +
+ +
+
+ Workmap +
+
+ + + +
OUTPUT FileUtils.rm_rf("spec/assets/action_schemaexpg1.emf") FileUtils.rm_rf("spec/assets/action_schemaexpg2.emf") diff --git a/spec/isodoc/footnotes_spec.rb b/spec/isodoc/footnotes_spec.rb index 74a4444a..1aed0444 100644 --- a/spec/isodoc/footnotes_spec.rb +++ b/spec/isodoc/footnotes_spec.rb @@ -4,12 +4,9 @@ RSpec.describe IsoDoc do it "processes IsoXML footnotes" do input = <<~INPUT - + - - Table of contents - - Foreword + Foreword

A.

Formerly denoted as 15 % (m/m).

@@ -23,6 +20,39 @@
INPUT + presxml = <<~INPUT + + + + Table of contents + + + Foreword + + Foreword + +

+ A. + +

Formerly denoted as 15 % (m/m).

+ +

+

+ B. + +

Formerly denoted as 15 % (m/m).

+ +

+

+ C. + +

Hello! denoted as 15 % (m/m).

+ +

+
+
+
+ INPUT html = <<~OUTPUT #{HTML_HDR}
@@ -57,26 +87,8 @@ OUTPUT - word = <<~OUTPUT - - - - - -
-

 

-
-

-
-

-
-

-
-

-
-

Table of contents

-
+ doc = <<~OUTPUT + #{WORD_HDR}


@@ -114,20 +126,26 @@

OUTPUT - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}).convert("test", input, true))) - .to be_equivalent_to Xml::C14n.format(html) - expect(Xml::C14n.format(IsoDoc::WordConvert.new({}).convert("test", input, true) - .gsub(/_Ref\d+/, "_Ref"))) - .to be_equivalent_to Xml::C14n.format(word) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output))) + .to be_equivalent_to Xml::C14n.format(presxml) + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(strip_guid(html)) + expect(Xml::C14n.format(strip_guid(IsoDoc::WordConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(strip_guid(doc)) end it "processes IsoXML reviewer notes" do @@ -149,9 +167,53 @@ INPUT + presxml = <<~INPUT + + + + Table of contents + + + Foreword + + Foreword + +

A.

+

B.

+ +

A Foreword shall appear in each document. The generic text is shown here. It does not contain requirements, recommendations or permissions.

+

+ For further information on the Foreword, see + ISO/IEC Directives, Part 2, 2016, Clause 12. +

+
+

C.

+ +

Second note.

+
+
+ + Introduction + + Introduction + + +

Second note.

+
+
+
+
+ INPUT html = <<~OUTPUT

+ +
OUTPUT + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output))) + .to be_equivalent_to Xml::C14n.format(presxml) IsoDoc::HtmlConvert.new({ wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss" }) - .convert("test", input, false) + .convert("test", pres_output, false) out = File.read("test.html").sub(/^.*
.*$}m, "
" ) - expect(Xml::C14n.format(out)).to be_equivalent_to Xml::C14n.format(html) + expect(Xml::C14n.format(strip_guid(out))) + .to be_equivalent_to Xml::C14n.format(html) FileUtils.rm_f "test.doc" IsoDoc::WordConvert.new({ wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss" }) - .convert("test", input, false) + .convert("test", pres_output, false) out = File.read("test.doc").sub(/^.*.*$}m, "") - expect(Xml::C14n.format(out)).to be_equivalent_to Xml::C14n.format(word) + expect(Xml::C14n.format(strip_guid(out))) + .to be_equivalent_to Xml::C14n.format(word) end it "processes IsoXML reviewer notes spanning list" do @@ -283,9 +352,54 @@ INPUT + presxml = <<~INPUT + + + + Table of contents + + + Foreword + + Foreword + +
    +
  1. +

    A.

    +

    A1

    +
  2. +
  3. B.
  4. +
      +
    • +

      C.

      +

      C1

      +
    • +
    • D.
    • +
    +
+
+ + Introduction + + Introduction + + +

Second note.

+
+
+
+
+ INPUT html = <<~OUTPUT

+
+

Foreword

@@ -314,7 +428,7 @@
OUTPUT word = <<~OUTPUT - +
OUTPUT + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output))) + .to be_equivalent_to Xml::C14n.format(presxml) IsoDoc::HtmlConvert.new({ wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss" }) - .convert("test", input, false) + .convert("test", pres_output, false) out = File.read("test.html").sub(/^.*
.*$}m, "
" ) - expect(Xml::C14n.format(out)).to be_equivalent_to Xml::C14n.format(html) + expect(Xml::C14n.format(strip_guid(out))) + .to be_equivalent_to Xml::C14n.format(html) FileUtils.rm_f "test.doc" IsoDoc::WordConvert.new({ wordstylesheet: "spec/assets/word.css", htmlstylesheet: "spec/assets/html.scss" }) - .convert("test", input, false) - out = File.read("test.doc").sub(/^.*.*$}m, - "") - expect(Xml::C14n.format(out)).to be_equivalent_to Xml::C14n.format(word) + .convert("test", pres_output, false) + out = File.read("test.doc") + .sub(/^.*.*$}m, "") + expect(Xml::C14n.format(strip_guid(out))) + .to be_equivalent_to Xml::C14n.format(word) end end diff --git a/spec/isodoc/form_spec.rb b/spec/isodoc/form_spec.rb index 0f79c052..0a5f801f 100644 --- a/spec/isodoc/form_spec.rb +++ b/spec/isodoc/form_spec.rb @@ -3,11 +3,11 @@ RSpec.describe IsoDoc do it "renders form" do input = <<~INPUT - + - Table of contents - + Table of contents + @@ -110,6 +110,12 @@ doc = <<~DOC #{WORD_HDR} +

 

+
+

+
+

+

diff --git a/spec/isodoc/i18n_spec.rb b/spec/isodoc/i18n_spec.rb index e8acc302..0ef94dc6 100644 --- a/spec/isodoc/i18n_spec.rb +++ b/spec/isodoc/i18n_spec.rb @@ -76,83 +76,342 @@ INPUT presxml = <<~PRESXML - - - en + + + en - published - withdrawn - - 2 - second edition - - brochure - - - - - Table of contents - - - Foreword -

See Clause 5

-
- Introduction - Introduction Subsection - -
- - 1.<tab/>Scope -

Text

-
- 3.<tab/>Terms, definitions, symbols and abbreviated terms - 3.1.<tab/>Normal Terms - 3.1.1. - Term2 - - - 3.2.<tab/>Symbols -
-
Symbol
-
Definition
-
-
-
- 4.<tab/>Symbols -
-
Symbol
-
Definition
-
-
- 5.<tab/>Clause 4 - 5.1.<tab/>Introduction - - - 5.2.<tab/>Clause 4.2 - - - 2.<tab/>Normative References - -
- <strong>Annex A</strong><br/>(normative)<br/><br/><strong>Annex</strong> - - A.1.<tab/>Annex A.1 - - A.1.1.<tab/>Annex A.1a - - - + published + withdrawn + + 2 + second edition + + brochure + +
+ + + Table of contents + + + Foreword + + Foreword + +

+ See + + Clause + 5 + +

+
+ + Introduction + + Introduction + + + Introduction Subsection + + Introduction Subsection + + + +
+ + + Scope + + + 1 + . + + + + + Scope + + + Clause + 1 + +

Text

+
+ + Terms, definitions, symbols and abbreviated terms + + + 3 + . + + + + + Terms, definitions, symbols and abbreviated terms + + + Clause + 3 + + + Normal Terms + + + 3 + . + 1 + . + + + + + Normal Terms + + + Clause + 3 + . + 1 + + + + + 3 + . + 1 + . + 1 + . + + + + Clause + 3 + . + 1 + . + 1 + + + Term2 + + + + + Symbols + + + 3 + . + 2 + . + + + + + Symbols + + + Clause + 3 + . + 2 + +
+
Symbol
+
Definition
+
+
+
+ + Symbols + + + 4 + . + + + + + Symbols + + + Clause + 4 + +
+
Symbol
+
Definition
+
+
+ + Clause 4 + + + 5 + . + + + + + Clause 4 + + + Clause + 5 + + + Introduction + + + 5 + . + 1 + . + + + + + Introduction + + + Clause + 5 + . + 1 + + + + Clause 4.2 + + + 5 + . + 2 + . + + + + + Clause 4.2 + + + Clause + 5 + . + 2 + + + + + Normative References + + + 2 + . + + + + + Normative References + + + Clause + 2 + + +
+ + + <strong>Annex</strong> + + + + + Annex + A + + +
+ (normative) + +
+
+
+ + Annex + +
+ + Annex + A + + + Annex A.1 + + + A + . + 1 + . + + + + + Annex A.1 + + + Annex + A + . + 1 + + + Annex A.1a + + + A + . + 1 + . + 1 + . + + + + + Annex A.1a + + + Annex + A + . + 1 + . + 1 + + + +
+ - Bibliography - - Bibliography Subsection - - + Bibliography + + Bibliography + + + Bibliography Subsection + + Bibliography Subsection + + + -
+ PRESXML - output = <<~"OUTPUT" + html = <<~"OUTPUT" #{HTML_HDR}
@@ -227,12 +486,15 @@ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert - .new(presxml_options).convert("test", input, true) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output .sub(%r{.*}m, "")))) .to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(output) + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(html) end it "defaults to English" do @@ -250,137 +512,45 @@ - + Foreword -

See

+

See

- Introduction - Introduction Subsection - -
- - Scope -

Text

-
- - Terms, definitions, symbols and abbreviated terms - Normal Terms - - Term2 - - - -
-
Symbol
-
Definition
-
-
-
- -
-
Symbol
-
Definition
-
-
- Clause 4 - Introduction - - - Clause 4.2 - - -
- Annex - - Annex A.1 - - Annex A.1a - - - - Normative References - - Bibliography - - Bibliography Subsection - - - + INPUT output = <<~OUTPUT - - - tlh - - published - withdrawn - - 2 - second edition - - brochure - - - - Table of contents - - Foreword -

See Clause 5

-
- Introduction - Introduction Subsection - -
- - 1.<tab/>Scope -

Text

-
- 3.<tab/>Terms, definitions, symbols and abbreviated terms - 3.1.<tab/>Normal Terms - 3.1.1. - Term2 - - - 3.2.<tab/>Symbols -
-
Symbol
-
Definition
-
-
-
- 4.<tab/>Symbols -
-
Symbol
-
Definition
-
-
- 5.<tab/>Clause 4 - 5.1.<tab/>Introduction - - - 5.2.<tab/>Clause 4.2 - - - 2.<tab/>Normative References - -
- <strong>Annex A</strong><br/>(normative)<br/><br/><strong>Annex</strong> - - A.1.<tab/>Annex A.1 - - A.1.1.<tab/>Annex A.1a - - - - - Bibliography - - Bibliography Subsection - - - -
+ + + tlh + + published + withdrawn + + 2 + second edition + + brochure + + + + + Table of contents + + + Foreword + + Foreword + +

+ See + + Foreword + +

+
+
+
OUTPUT expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert .new(presxml_options) @@ -464,83 +634,342 @@ INPUT presxml = <<~PRESXML - + - fr - - published - withdrawn - - 2 - deuxième édition - - brochure - + fr + + published + withdrawn + + 2 + deuxième édition + + brochure + - - Sommaire - - - Foreword -

See Article 5

-
- Introduction - Introduction Subsection - -
- - 1.<tab/>Scope -

Text

-
- 3.<tab/>Terms, definitions, symbols and abbreviated terms - 3.1.<tab/>Normal Terms - 3.1.1. - Term2 - - - 3.2.<tab/>Symboles -
-
Symbol
-
Definition
-
-
-
- 4.<tab/>Symboles -
-
Symbol
-
Definition
-
-
- 5.<tab/>Clause 4 - 5.1.<tab/>Introduction - - - 5.2.<tab/>Clause 4.2 - - - 2.<tab/>Normative References - -
- <strong>Annexe A</strong><br/>(normative)<br/><br/><strong>Annex</strong> - - A.1.<tab/>Annex A.1 - - A.1.1.<tab/>Annex A.1a + + Sommaire - - + + Foreword + + Foreword + +

+ See + + Article + 5 + +

+
+ + Introduction + + Introduction + + + Introduction Subsection + + Introduction Subsection + + + + + + + Scope + + + 1 + . + + + + + Scope + + + Article + 1 + +

Text

+
+ + Terms, definitions, symbols and abbreviated terms + + + 3 + . + + + + + Terms, definitions, symbols and abbreviated terms + + + Article + 3 + + + Normal Terms + + + 3 + . + 1 + . + + + + + Normal Terms + + + Article + 3 + . + 1 + + + + + 3 + . + 1 + . + 1 + . + + + + Article + 3 + . + 1 + . + 1 + + + Term2 + + + + + Symboles + + + 3 + . + 2 + . + + + + + Symboles + + + Article + 3 + . + 2 + +
+
Symbol
+
Definition
+
+
+
+ + Symboles + + + 4 + . + + + + + Symboles + + + Article + 4 + +
+
Symbol
+
Definition
+
+
+ + Clause 4 + + + 5 + . + + + + + Clause 4 + + + Article + 5 + + + Introduction + + + 5 + . + 1 + . + + + + + Introduction + + + Article + 5 + . + 1 + + + + Clause 4.2 + + + 5 + . + 2 + . + + + + + Clause 4.2 + + + Article + 5 + . + 2 + + + + + Normative References + + + 2 + . + + + + + Normative References + + + Article + 2 + + +
+ + + <strong>Annex</strong> + + + + + Annexe + A + + +
+ (normative) + +
+
+
+ + Annex + +
+ + Annexe + A + + + Annex A.1 + + + A + . + 1 + . + + + + + Annex A.1 + + + Annexe + A + . + 1 + + + Annex A.1a + + + A + . + 1 + . + 1 + . + + + + + Annex A.1a + + + Annexe + A + . + 1 + . + 1 + + + +
+ - Bibliographie - - Bibliography Subsection - - - -
+ Bibliographie + + Bibliographie + + + Bibliography Subsection + + Bibliography Subsection + + + + +
PRESXML - output = <<~"OUTPUT" + html = <<~"OUTPUT" #{HTML_HDR.gsub(' lang="en">', ' lang="fr">').sub('Table of contents', 'Sommaire')}
@@ -615,12 +1044,15 @@ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output .sub(%r{.*}m, "")))) .to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(output) + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(html) end it "processes Simplified Chinese" do @@ -707,94 +1139,354 @@ INPUT presxml = <<~PRESXML - - - zh - - - published - withdrawn - - 2第第二版 - - brochure - - - - - 目 次 - - - Foreword -

See 条5

-
- Introduction - Introduction Subsection - -
- - 1.<tab/>Scope -

ISO 712,第1~1表

-
- 3.<tab/>Terms, definitions, symbols and abbreviated terms - 3.1.<tab/>Normal Terms - 3.1.1. - Term2 - - - 3.2.<tab/>符号 -
-
Symbol
-
Definition
-
-
-
- 4.<tab/>符号 -
-
Symbol
-
Definition
-
-
- 5.<tab/>Clause 4 - 5.1.<tab/>Introduction - - - 5.2.<tab/>Clause 4.2 - + + + zh + + + published + withdrawn + + 2 + 第第二版 + + brochure + + + + + 目 次 + + + Foreword + + Foreword + +

+ See + + + 5 + +

+
+ + Introduction + + Introduction + + + Introduction Subsection + + Introduction Subsection + + + +
+ + + Scope + + + 1 + . + + + + + Scope + + + + 1 + +

+ ISO 712,第1~1表 +

+
+ + Terms, definitions, symbols and abbreviated terms + + + 3 + . + + + + + Terms, definitions, symbols and abbreviated terms + + + + 3 + + + Normal Terms + + + 3 + . + 1 + . + + + + + Normal Terms + + + + 3 + . + 1 + + + + + 3 + . + 1 + . + 1 + . + + + + + 3 + . + 1 + . + 1 + + + Term2 + + + + + 符号 + + + 3 + . + 2 + . + + + + + 符号 + + + + 3 + . + 2 + +
+
Symbol
+
Definition
+
+
+
+ + 符号 + + + 4 + . + + + + + 符号 + + + + 4 + +
+
Symbol
+
Definition
+
+
+ + Clause 4 + + + 5 + . + + + + + Clause 4 + + + + 5 + + + Introduction + + + 5 + . + 1 + . + + + + + Introduction + + + + 5 + . + 1 + + + + Clause 4.2 + + + 5 + . + 2 + . + + + + + Clause 4.2 + + + + 5 + . + 2 + + + - 2.<tab/>Normative References - - Cereals and cereal products. - ISO 712 - ISO 712 - ISO 712, - - -
- - <strong>附件 A</strong><br/>(规范性附录) - <br/> - <br/> - <strong>Annex</strong> + <title id="_">Normative References + + + 2 + . + + + + + Normative References + + + + 2 + + + + Cereals and cereal products + . + + ISO 712 + ISO 712 + ISO 712, + + +
+ + + <strong>Annex</strong> - - A.1.<tab/>Annex A.1 - - A.1.1.<tab/>Annex A.1a - - - + + + + 附件 + A + + +
+ (规范性附录) + +
+
+
+ + Annex + +
+ + 附件 + A + + + Annex A.1 + + + A + . + 1 + . + + + + + Annex A.1 + + + 附件 + A + . + 1 + + + Annex A.1a + + + A + . + 1 + . + 1 + . + + + + + Annex A.1a + + + 附件 + A + . + 1 + . + 1 + + + + + - Bibliography - - Bibliography Subsection - - - -
+ Bibliography + + Bibliography + + + Bibliography Subsection + + Bibliography Subsection + + + + + PRESXML - output = <<~"OUTPUT" + html = <<~"OUTPUT" #{HTML_HDR.gsub(' lang="en">', ' lang="zh">').gsub('Table of contents', '目 次')}
@@ -853,32 +1545,42 @@

-
-

附件 A
(规范性附录)

Annex

-

A.1. Annex A.1

- -

A.1.1. Annex A.1a

- +
+

+ 附件A +
+ (规范性附录) +
+
+ Annex +

+
+

A.1. Annex A.1

+
+

A.1.1. Annex A.1a

+
+
+
+
+
+

Bibliography

+
+

Bibliography Subsection

+
-
-
-

Bibliography

- -

Bibliography Subsection

- -
-
-
- + OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output .sub(%r{.*}m, "")))) .to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(output) + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(html) end it "processes i18n file" do @@ -969,91 +1671,407 @@ INPUT presxml = <<~OUTPUT - - - eo - - - publishedpublikigita - withdrawnfortirita - - 2 - eldono dua - - brochurebroŝuro - - - - </clause> - <foreword obligation="informative" displayorder="2"> - <title>Foreword -

See klaŭzo 5

-

See tabelo 1

- Tabelo 1
- - Introduction - Introduction Subsection - -
- - 1.<tab/>Scope -

ISO 712, Tabelo 1–1

-
- 3.<tab/>Terms, definitions, symbols and abbreviated terms - 3.1.<tab/>Normal Terms - 3.1.1. - Term2 - - - 3.2.<tab/>Simboloj kai mallongigitaj terminoj -
-
Symbol
-
Definition
-
-
-
- 4.<tab/>Simboloj kai mallongigitaj terminoj -
-
Symbol
-
Definition
-
-
- 5.<tab/>Clause 4 - 5.1.<tab/>Introduction - NOTO - - - 5.2.<tab/>Clause 4.2 - + + + eo + + + published + publikigita + withdrawn + fortirita + + 2 + eldono dua + + brochure + broŝuro + + + + + + + + Foreword + + Foreword + +

+ See + + klaŭzo + 5 + +

+

+ See + + tabelo + 1 + +

+ + + + Tabelo + 1 + + + + tabelo + 1 + +
+
+ + Introduction + + Introduction + + + Introduction Subsection + + Introduction Subsection + + + +
+ + + Scope + + + 1 + . + + + + + Scope + + + klaŭzo + 1 + +

+ ISO 712, Tabelo 1–1 +

+
+ + Terms, definitions, symbols and abbreviated terms + + + 3 + . + + + + + Terms, definitions, symbols and abbreviated terms + + + klaŭzo + 3 + + + Normal Terms + + + 3 + . + 1 + . + + + + + Normal Terms + + + klaŭzo + 3 + . + 1 + + + + + 3 + . + 1 + . + 1 + . + + + + klaŭzo + 3 + . + 1 + . + 1 + + + Term2 + + + + + Simboloj kai mallongigitaj terminoj + + + 3 + . + 2 + . + + + + + Simboloj kai mallongigitaj terminoj + + + klaŭzo + 3 + . + 2 + +
+
Symbol
+
Definition
+
+
+
+ + Simboloj kai mallongigitaj terminoj + + + 4 + . + + + + + Simboloj kai mallongigitaj terminoj + + + klaŭzo + 4 + +
+
Symbol
+
Definition
+
+
+ + Clause 4 + + + 5 + . + + + + + Clause 4 + + + klaŭzo + 5 + + + Introduction + + + 5 + . + 1 + . + + + + + Introduction + + + klaŭzo + 5 + . + 1 + + + + + NOTO + + + + + + + noto + + + + klaŭzo + 5 + . + 1 + + + noto + + + + + Clause 4.2 + + + 5 + . + 2 + . + + + + + Clause 4.2 + + + klaŭzo + 5 + . + 2 + + + - 2.<tab/>Normative References - - Cereals and cereal products. - ISO 712 - ISO 712 - ISO 712, - - -
- <strong><strong>Aldono</strong> A</strong><br/>(normative)<br/><br/><strong>Annex</strong> - - A.1.<tab/>Annex A.1 - - A.1.1.<tab/>Annex A.1a - - - - - Bibliography - - Bibliography Subsection - - - -
+ Normative References + + + 2 + . + + + + + Normative References + + + klaŭzo + 2 + + + + Cereals and cereal products + . + + ISO 712 + ISO 712 + ISO 712, + + +
+ + + <strong>Annex</strong> + + + + + + Aldono + + A + + +
+ (normative) + +
+
+
+ + Annex + +
+ + + aldono + + A + + + Annex A.1 + + + A + . + 1 + . + + + + + Annex A.1 + + + + aldono + + A + . + 1 + + + Annex A.1a + + + A + . + 1 + . + 1 + . + + + + + Annex A.1a + + + + aldono + + A + . + 1 + . + 1 + + + +
+ + + Bibliography + + Bibliography + + + Bibliography Subsection + + Bibliography Subsection + + + + +
OUTPUT - output = <<~OUTPUT + html = <<~OUTPUT @@ -1140,8 +2158,7 @@

5.1.  Introduction

- NOTO -   + NOTO 

@@ -1178,16 +2195,17 @@ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert - .new({ i18nyaml: "spec/assets/i18n.yaml" } - .merge(presxml_options)) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options + .merge({ i18nyaml: "spec/assets/i18n.yaml" })) .convert("test", input, true) - .sub(%r{.*}m, "")))) + expect(Xml::C14n.format(strip_guid(pres_output + .sub(%r{.*}m, "")))) .to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert .new({ i18nyaml: "spec/assets/i18n.yaml" }) - .convert("test", presxml, true))) - .to be_equivalent_to Xml::C14n.format(output) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(html) end it "internationalises locality" do @@ -1228,18 +2246,15 @@ INPUT presxml = <<~OUTPUT - - Foreword -

- ISO 712, Preludo 7 -

-
+

+ ISO 712, Preludo 7 +

OUTPUT - expect(Xml::C14n.format(Nokogiri::XML(IsoDoc::PresentationXMLConvert + expect(Xml::C14n.format(strip_guid(Nokogiri::XML(IsoDoc::PresentationXMLConvert .new({ i18nyaml: "spec/assets/i18n.yaml" } .merge(presxml_options)) .convert("test", input, true)) - .at("//xmlns:foreword").to_xml)) + .at("//xmlns:p[@id='A']").to_xml))) .to be_equivalent_to Xml::C14n.format(presxml) end @@ -1320,55 +2335,88 @@ INPUT presxml = <<~OUTPUT - - - zh - - - - - - 版 權 - - - 版權聲明 - - - 版 權 - - - - - - 目 次 - -

樣 板

- - 解 題 - - - 文件序言 -

This is a preamble

-
-

介紹性陳述

- - 簡 介 - - 引言部分 - - 附則 - - - - Ad - - -
-
+ + + zh + + + + + + 版權 + + 版 權 + + + + 版權聲明 + + 版權聲明 + + + + 版權 + + 版 權 + + + + + + + 目 次 + + 樣 板 +

+ 樣 板 +

+ + 解題 + + 解 題 + + + + 文件序言 + + 文件序言 + +

This is a preamble

+
+ 介紹性陳述 +

+ 介紹性陳述 +

+ + 簡介 + + 簡 介 + + + 引言部分 + + 引言部分 + + + 附則 + + 附則 + + + + + Ad + + Ad + + + +
+
OUTPUT expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert - .new(presxml_options).convert("test", input, true) - .sub(%r{.*}m, "")))) + .new(presxml_options).convert("test", input, true) + .sub(%r{.*}m, "")))) .to be_equivalent_to Xml::C14n.format(presxml) end diff --git a/spec/isodoc/inline_spec.rb b/spec/isodoc/inline_spec.rb index 0d4935c0..0ce3175a 100644 --- a/spec/isodoc/inline_spec.rb +++ b/spec/isodoc/inline_spec.rb @@ -4,7 +4,7 @@ it "processes inline formatting" do input = <<~INPUT - Foreword + Foreword

A B C D E F G I


@@ -71,33 +71,26 @@ input = <<~INPUT -

+

INPUT output = <<~OUTPUT - - - - Table of contents - - Foreword -

2021-01-01

-
-
- -
+

2021-01-01

OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(output) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true)) + .at("//xmlns:p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(output) end it "ignores index entries" do input = <<~INPUT -

+

@@ -106,27 +99,20 @@
INPUT output = <<~OUTPUT - - - - Table of contents - - Foreword -

- - - - +

OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(output) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true)) + .at("//xmlns:p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(output) end it "processes concept markup" do input = <<~INPUT -

+

+
+

OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(output) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML(pres_output) + .at("//xmlns:p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(presxml) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML( + IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true), + ) + .at("//p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(html) end it "processes concept attributes" do input = <<~INPUT -

+

  • termterm,
  • termterm,
  • @@ -391,96 +350,80 @@ INPUT + presxml = <<~OUTPUT - - - - Table of contents - - Foreword -

    -

      -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • term,
    • -
    • term,
    • -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • term (Clause 1),
    • -
    • - error! -
    • -
    • - CV_DiscreteCoverage -
    • -
    -

    -
    -
    - - - 1.<tab/>Clause 1 - - -
    +

    +

      +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • term,
    • +
    • term,
    • +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • term (Clause 1),
    • +
    • + error! +
    • +
    • + CV_DiscreteCoverage +
    • +
    +

    OUTPUT - output = <<~OUTPUT - #{HTML_HDR} -
    -
    -

    Foreword

    -

    -

    - -
    -

    -
    -
    -

    1.  Clause 1

    -
    -

- - + html = <<~OUTPUT +

+

+ +
+

OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(output) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML(pres_output) + .at("//xmlns:p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(presxml) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML( + IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true), + ) + .at("//p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(html) end it "processes concept markup for symbols" do input = <<~INPUT -

+

  • term @@ -502,77 +445,42 @@ INPUT presxml = <<~OUTPUT - - - - Table of contents - - Foreword -

    -

      -
    • ISO
    • -
    -

    -
    -
    - - - 1.<tab/>Symbols -
    -
    ISO
    -
    xyz
    -
    IEC
    -
    abc
    -
    -
    -
    -
    +

    +

      +
    • ISO
    • +
    +

    OUTPUT - output = <<~OUTPUT - #{HTML_HDR} -
    -
    -

    Foreword

    -

    -

    -
      -
    • ISO
    • -
    -
    -

    -
    -
    -

    1.  Symbols

    -
    -
    -
    -

    ISO

    -
    -
    xyz
    -
    -

    IEC

    -
    -
    abc
    -
    -
    -
    -
- - + html = <<~OUTPUT +

+

+
    +
  • ISO
  • +
+
+

OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(output) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML(pres_output) + .at("//xmlns:p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(presxml) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML( + IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true), + ) + .at("//p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(html) end it "processes embedded inline formatting" do input = <<~INPUT - Table of contents + Table of contents - Foreword + Foreword

< Requirement /req/core/http Requirement /req/core/http

@@ -601,9 +509,9 @@ input = <<~INPUT - Table of contents + Table of contents - Foreword + Foreword

alttext

@@ -631,9 +539,9 @@ input = <<~INPUT - Table of contents + Table of contents - Foreword + Foreword


@@ -673,7 +581,7 @@ it "processes updatetype links" do input = <<~INPUT - Foreword + Foreword

example @@ -717,9 +625,9 @@ input = <<~INPUT - Table of contents + Table of contents - Foreword + Foreword

example

@@ -748,9 +656,9 @@ input = <<~INPUT - Table of contents + Table of contents - Foreword + Foreword

<A> X<A> @@ -793,9 +701,9 @@ - Table of contents + Table of contents - Foreword + Foreword

A (#((Hello))#) @@ -838,10 +746,14 @@ output = <<~OUTPUT - - Table of contents - - Foreword + + Table of contents + + + Foreword + + Foreword +

@@ -887,34 +799,38 @@ INPUT output = <<~OUTPUT - - - - Table of contents - - Foreword -

- - - + + + + Table of contents + + + Foreword + + Foreword + +

+ + + + + ( - ( - - x - + - y - - ) + x + + + y - 2 - - - -

-
-
- -
+ ) + + 2 + + + +

+
+
+ +
OUTPUT expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert .new({ suppressasciimathdup: true } @@ -964,7 +880,11 @@
INPUT presxml = <<~OUTPUT - Foreword + + Foreword + + Foreword +

A @@ -1019,7 +939,7 @@ input = <<~INPUT -

+

1 @@ -1056,84 +976,62 @@ INPUT presxml = <<~OUTPUT - - - Table of contents - Foreword -

- ISO 712 - ISO 712 - ISO 712, Table 1 - ISO 712, Table 1 - ISO 712, Table 1 and Clause 1 - ISO 712, Table 1–1 - ISO 712, Clause 1, Table 1 - ISO 712, Clause 1 - ISO 712, Clause 1.5 - A - ISO 712, Whole of text - ISO 712, Prelude 7 - ISO 712, URI 7 - A - ISO 712 - ISO 712, Clause 1 - ISO 712, 1 - ISO 712, clause 1 -

-
- 1.<tab/>Normative References - - Cereals and cereal products. - ISO 712 - ISO 712 - ISO 712, - - - - - -
+

+ ISO 712 + ISO 712 + ISO 712, Table 1 + ISO 712, Table 1 + ISO 712, Table 1 and Clause 1 + ISO 712, Table 1–1 + ISO 712, Clause 1, Table 1 + ISO 712, Clause 1 + ISO 712, Clause 1.5 + A + ISO 712, Whole of text + ISO 712, Prelude 7 + ISO 712, URI 7 + A + ISO 712 + ISO 712, Clause 1 + ISO 712, 1 + ISO 712, clause 1 +

OUTPUT html = <<~OUTPUT - #{HTML_HDR} -
- -
-

1.  Normative References

-

ISO 712, Cereals and cereal products.

-
-
- - +

+ ISO 712 + ISO 712 + ISO 712, Table 1 + ISO 712, Table 1 + ISO 712, Table 1 and Clause 1#{' '} + ISO 712, Table 1–1 + ISO 712, Clause 1, Table 1 + ISO 712, Clause 1 + ISO 712, Clause 1.5 + A + ISO 712, Whole of text + ISO 712, Prelude 7 + ISO 712, URI 7 + A + ISO 712 + ISO 712, Clause 1 + ISO 712, 1 + ISO 712, clause 1 +

OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(html) + pres_output = IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML(pres_output) + .at("//xmlns:p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(presxml) + expect(Xml::C14n.format(strip_guid(Nokogiri::XML( + IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true), + ) + .at("//p[@id = 'A']").to_xml))) + .to be_equivalent_to Xml::C14n.format(html) end it "processes eref content pointing to reference with citation URL" do @@ -1204,13 +1102,17 @@ INPUT presxml = <<~OUTPUT - Avant-propos + + Avant-propos + + Avant-propos +

ISO 712 ISO 712 ISO 713, Tableau 1 ISO 713, Tableau 1 - ISO 713, Tableau 1 et Article 1 + ISO 713, Tableau 1 et Article 1 ISO 713, Tableau 1–1 ISO 713, Article 1, Tableau 1 ISO 713, Article 1 @@ -1228,25 +1130,25 @@ html = <<~OUTPUT

OUTPUT @@ -1321,7 +1223,11 @@ INPUT presxml = <<~OUTPUT - Avant-propos + + Avant-propos + + Avant-propos +

ISO 712

@@ -1338,7 +1244,7 @@ input = <<~INPUT -

+

1 @@ -1382,135 +1288,81 @@ INPUT presxml = <<~PRESXML - - - Table of contents - Foreword -

- ISO 712 - ISO 712 - ISO 713, Table 1 - ISO 713, Table 1 - ISO 713, Table 1 and Clause 1 - ISO 713, Table 1–1 - ISO 713, Clause 1, Table 1 - ISO 713, Clause 1 - ISO 713, Clause 1.5 - A - ISO 713, Whole of text - ISO 713, Prelude 7 - A - ISO 713 - ISO 713, Clause 1 -

-
-
- - - - - -
+

+ ISO 712 + ISO 712 + ISO 713, Table 1 + ISO 713, Table 1 + ISO 713, Table 1 and Clause 1 + ISO 713, Table 1–1 + ISO 713, Clause 1, Table 1 + ISO 713, Clause 1 + ISO 713, Clause 1.5 + A + ISO 713, Whole of text + ISO 713, Prelude 7 + A + ISO 713 + ISO 713, Clause 1 +

PRESXML html = <<~OUTPUT - #{HTML_HDR} -
- -
- - +

+ ISO 712 + ISO 712 + ISO 713, Table 1 + ISO 713, Table 1 + ISO 713, Table 1 and Clause 1 + ISO 713, Table 1–1 + ISO 713, Clause 1, Table 1 + ISO 713, Clause 1 + ISO 713, Clause 1.5 + A + ISO 713, Whole of text + ISO 713, Prelude 7 + A + ISO 713 + ISO 713, Clause 1 +

OUTPUT word = <<~OUTPUT - - - - -
-

 

+
+

admonition

-

-
+

+ + + OUTPUT + word = <<~OUTPUT + + + + + +
+

 

+
+

+
+

+
+

+

-
-
-

- -   -

- note -
-

-
-

-
-

abstract

-
-

-
-

-
-

introduction

-
-

 

+
+

abstract

-

-
+

+

-
-
-

admonition

+
+

introduction

+
+
note
+

 

+
+

+
+

+
+
+

admonition

+
+
+

Clause 4

+
+

Introduction

-
-

Clause 4

-
-

Introduction

-
-
- - - Clause 4.2 -   - - -
+
+ + + Clause 4.2 +   + +
- - - OUTPUT +
+ + + OUTPUT + expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) + .convert("test", input, true))) + .to be_equivalent_to Xml::C14n.format(html) + expect(Xml::C14n.format(IsoDoc::WordConvert.new({}) + .convert("test", input, true))) + .to be_equivalent_to Xml::C14n.format(word) end it "processes indexsect" do input = <<~INPUT - Glossary + Glossary
  • A
@@ -161,7 +160,8 @@ OUTPUT expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", input, true))).to be_equivalent_to Xml::C14n.format(output) + .convert("test", input, true))) + .to be_equivalent_to Xml::C14n.format(output) end it "processes annexes containing one, or more than one special sections" do @@ -213,122 +213,333 @@
INPUT presxml = <<~OUTPUT - - Table of contents - - - <strong>Annex A</strong> - <br/> - (normative) - <br/> - <br/> - <strong>Glossary</strong> - - - - A.1. - Glossary - - - - - - <strong>Annex B</strong> - <br/> - (normative) - <br/> - <br/> - <strong>Glossary</strong> - - - - B.1. - <tab/> - Term Collection - - - B.1.1. - Term - - - - - B.2. - <tab/> - Term Collection 2 - - - B.2.1. - Term - - - - - - <strong>Annex C</strong> - <br/> - (normative) - <br/> - <br/> - <strong>Glossary</strong> - - - - C.1. - <tab/> - Term Collection - - - C.1.1. - Term - - - - - C.2. - <tab/> - References - - - - - - <strong>Annex D</strong> - <br/> - (normative) - <br/> - <br/> - <strong>Term Collection</strong> - - - - D.1. - - Term - - - - - + + + + Table of contents + + + + + <strong>Glossary</strong> + + + + + Annex + A + + +
+ (normative) + +
+
+
+ + Glossary + +
+ + Annex + A + + + + + + A + . + 1 + . + + + + Annex + A + . + 1 + + + Glossary + + + +
+ + + <strong>Glossary</strong> + + + + + Annex + B + + +
+ (normative) + +
+
+
+ + Glossary + +
+ + Annex + B + + + Term Collection + + + B + . + 1 + . + + + + + Term Collection + + + Annex + B + . + 1 + + + + + B + . + 1 + . + 1 + . + + + + Annex + B + . + 1 + . + 1 + + + Term + + + + + Term Collection 2 + + + B + . + 2 + . + + + + + Term Collection 2 + + + Annex + B + . + 2 + + + + + B + . + 2 + . + 1 + . + + + + Annex + B + . + 2 + . + 1 + + + Term + + + +
+ + + <strong>Glossary</strong> + + + + + Annex + C + + +
+ (normative) + +
+
+
+ + Glossary + +
+ + Annex + C + + + Term Collection + + + C + . + 1 + . + + + + + Term Collection + + + Annex + C + . + 1 + + + + + C + . + 1 + . + 1 + . + + + + Annex + C + . + 1 + . + 1 + + + Term + + + + + References + + + C + . + 2 + . + + + + + References + + + Annex + C + . + 2 + + +
+ + + <strong>Term Collection</strong> + + + + + Annex + D + + +
+ (normative) + +
+
+
+ + Term Collection + +
+ + Annex + D + + + + + + D + . + 1 + . + + + + Annex + D + . + 1 + + + Term + + + +
+
OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(presxml) + expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true)))) + .to be_equivalent_to Xml::C14n.format(presxml) end it "processes cross-align" do input = <<~INPUT - + - Title + Title

Para

- Iitre + Iitre

Alinée

@@ -370,6 +581,7 @@ OUTPUT expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", input, true))).to be_equivalent_to Xml::C14n.format(output) + .convert("test", input, true))) + .to be_equivalent_to Xml::C14n.format(output) end end diff --git a/spec/isodoc/section_title_spec.rb b/spec/isodoc/section_title_spec.rb index 848f904b..9ad5e5c0 100644 --- a/spec/isodoc/section_title_spec.rb +++ b/spec/isodoc/section_title_spec.rb @@ -118,152 +118,468 @@ INPUT presxml = <<~PRESXML - - - - - Copyright - - - - - License - - - - - Legal - - - - - Feedback - - - - - - Table of contents - - - Abstract - - - Foreword -

This is a preamble

-
- - Introduction - - Introduction Subsection - - - - Dedication - - - Note to reader - - - Acknowledgements - -
- - - NOTE -

Initial note

-
- - WARNING -

Initial admonition

-
- - 1.<tab/>Scope -

Text

-
- - 3.<tab/>Terms, Definitions, Symbols and Abbreviated Terms - - 3.1.<tab/>Normal Terms - - 3.1.1. - Term2 - - - - 3.2.<tab/>Symbols -
-
Symbol
-
Definition
-
-
-
- - 4.<tab/>Symbols and abbreviated terms -
-
Symbol
-
Definition
-
-
- - 5.<tab/>Clause 4 - - 5.1.<tab/>Introduction - - - 5.2.<tab/>Clause 4.2 - - - 5.3. - - - - 2.<tab/>Normative References - -
- - - <strong>Annex A</strong> - <br/> - (normative) - <br/> - <br/> - <strong>Annex</strong> - - - A.1.<tab/>Annex A.1 - - A.1.1.<tab/>Annex A.1a - - - A.1.2.<tab/>Annex Bibliography - - - - - - <strong>Annex B</strong> - <br/> - (normative) - - - - - Bibliography - - Bibliography Subsection - - - - - - Postface 1 - - - Postface 2 - - -
+ + + + + Copyright + + Copyright + + + + + + License + + License + + + + + + Legal + + Legal + + + + + + Feedback + + Feedback + + + + + + + Table of contents + + + Abstract + + Abstract + + + + Foreword + + Foreword + +

This is a preamble

+
+ + Introduction + + Introduction + + + Introduction Subsection + + Introduction Subsection + + + + + Dedication + + Dedication + + + + Note to reader + + Note to reader + + + + Acknowledgements + + Acknowledgements + + +
+ + + + + NOTE + + + + + +

Initial note

+
+ + WARNING + + WARNING + +

Initial admonition

+
+ + Scope + + + 1 + . + + + + + Scope + + + Clause + 1 + +

Text

+
+ + Terms, Definitions, Symbols and Abbreviated Terms + + + 3 + . + + + + + Terms, Definitions, Symbols and Abbreviated Terms + + + Clause + 3 + + + Normal Terms + + + 3 + . + 1 + . + + + + + Normal Terms + + + Clause + 3 + . + 1 + + + + + 3 + . + 1 + . + 1 + . + + + + Clause + 3 + . + 1 + . + 1 + + + Term2 + + + + + Symbols + + + 3 + . + 2 + . + + + + + Symbols + + + Clause + 3 + . + 2 + +
+
Symbol
+
Definition
+
+
+
+ + Symbols and abbreviated terms + + + 4 + . + + + + + Symbols and abbreviated terms + + + Clause + 4 + +
+
Symbol
+
Definition
+
+
+ + Clause 4 + + + 5 + . + + + + + Clause 4 + + + Clause + 5 + + + Introduction + + + 5 + . + 1 + . + + + + + Introduction + + + Clause + 5 + . + 1 + + + + Clause 4.2 + + + 5 + . + 2 + . + + + + + Clause 4.2 + + + Clause + 5 + . + 2 + + + + + + 5 + . + 3 + . + + + + Clause + 5 + . + 3 + + + + + Normative References + + + 2 + . + + + + + Normative References + + + Clause + 2 + + +
+ + + <strong>Annex</strong> + + + + + Annex + A + + +
+ (normative) + +
+
+
+ + Annex + +
+ + Annex + A + + + Annex A.1 + + + A + . + 1 + . + + + + + Annex A.1 + + + Annex + A + . + 1 + + + Annex A.1a + + + A + . + 1 + . + 1 + . + + + + + Annex A.1a + + + Annex + A + . + 1 + . + 1 + + + + Annex Bibliography + + + A + . + 1 + . + 2 + . + + + + + Annex Bibliography + + + Annex + A + . + 1 + . + 2 + + + +
+ + + + + Annex + B + + +
+ (normative) +
+ + Annex + B + +
+ + + Bibliography + + Bibliography + + + Bibliography Subsection + + Bibliography Subsection + + + + + + + Postface 1 + + Postface 1 + + + + Postface 2 + + Postface 2 + + + +
PRESXML html = <<~"OUTPUT" @@ -320,8 +636,8 @@

- NOTE -   Initial note + NOTE  + Initial note

@@ -488,7 +804,7 @@

-

NOTE  Initial note

+

NOTE  Initial note

WARNING

Initial admonition

@@ -568,21 +884,22 @@ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + pres_output = IsoDoc::PresentationXMLConvert .new(presxml_options) - .convert("test", input, true)))) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output))) .to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))) + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) .to be_equivalent_to Xml::C14n.format(html) - expect(Xml::C14n.format(IsoDoc::WordConvert.new({}) - .convert("test", presxml, true))) + expect(Xml::C14n.format(strip_guid(IsoDoc::WordConvert.new({}) + .convert("test", pres_output, true)))) .to be_equivalent_to Xml::C14n.format(word) end it "processes section subtitles" do input = <<~INPUT - + Abstract @@ -766,8 +1083,8 @@

- NOTE -   Initial note + NOTE  + Initial note

@@ -933,25 +1250,7 @@ OUTPUT word = <<~OUTPUT - - - - - -
-

 

-
-

-
-

-
-

-
-

-
-

Table of contents

-
+ #{WORD_HDR}


@@ -1030,8 +1329,8 @@

- NOTE -   + NOTE +   Initial note

@@ -1230,9 +1529,11 @@ presxml = IsoDoc::PresentationXMLConvert.new(presxml_options) .convert("test", input, true) expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true)))).to be_equivalent_to Xml::C14n.format(html) + .convert("test", presxml, true)))) + .to be_equivalent_to Xml::C14n.format(html) expect(Xml::C14n.format(strip_guid(IsoDoc::WordConvert.new({}) - .convert("test", presxml, true)))).to be_equivalent_to Xml::C14n.format(word) + .convert("test", presxml, true)))) + .to be_equivalent_to Xml::C14n.format(word) end it "processes section names suppressing section numbering" do @@ -1301,83 +1602,158 @@ INPUT output = <<~OUTPUT - - - - Table of contents + + + + Table of contents + + + Foreword + + Foreword + +

This is a preamble

+
+ + Introduction + + Introduction + + + Introduction Subsection + + Introduction Subsection + + + +
+ + + Scope + + Scope + +

Text

+
+ + Terms, Definitions, Symbols and Abbreviated Terms + + Terms, Definitions, Symbols and Abbreviated Terms + + + Normal Terms + + Normal Terms + + + + + 3 + . + 1 + . + 1 + . + + + + Clause + 3 + . + 1 + . + 1 + + + Term2 + + + + + Symbols + + Symbols + +
+
Symbol
+
Definition
+
+
+
+ + Symbols + + Symbols + +
+
Symbol
+
Definition
+
+
+ + Clause 4 + + Clause 4 + + + Introduction + + Introduction + + + + Clause 4.2 + + Clause 4.2 + + + - - Foreword -

This is a preamble

-
- - Introduction - - Introduction Subsection - - -
- - - Scope -

Text

-
- - Terms, Definitions, Symbols and Abbreviated Terms - - Normal Terms - - 3.1.1. - Term2 - - - Symbols -
-
Symbol
-
Definition
-
-
-
- Symbols -
-
Symbol
-
Definition
-
-
- - Clause 4 - - Introduction - - - Clause 4.2 - - - - - Normative References - -
- - - <strong>Annex</strong> - - - Annex A.1 - - Annex A.1a - - - - - - Bibliography - - Bibliography Subsection - - - -
+ + + Normative References + + Normative References + + + + + + <strong>Annex</strong> + + + + Annex + + + + Annex A.1 + + Annex A.1 + + + Annex A.1a + + Annex A.1a + + + + + + + Bibliography + + Bibliography + + + Bibliography Subsection + + Bibliography Subsection + + + + + OUTPUT expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert .new({ suppressheadingnumbers: true } @@ -1448,79 +1824,145 @@ INPUT output = <<~OUTPUT - - - - Table of contents - - - - - Scope -

Text

-
- - Terms, Definitions, Symbols and Abbreviated Terms - - Normal Terms - - - Term2 - - - - Symbols -
-
Symbol
-
Definition
-
-
-
- Symbols -
-
Symbol
-
Definition
-
-
- - Clause 4 - - Introduction - - - Clause 4.2 - - - - 1. - - - - - 2. - - - Normative References - -
- - <strong>Annex</strong> - - Annex A.1 - - Annex A.1a - - - - - - Bibliography - - Bibliography Subsection - - - -
+ + + + Table of contents + + + + + Scope + + Scope + +

Text

+
+ + Terms, Definitions, Symbols and Abbreviated Terms + + Terms, Definitions, Symbols and Abbreviated Terms + + + Normal Terms + + Normal Terms + + + + Term2 + + + + + Symbols + + Symbols + +
+
Symbol
+
Definition
+
+
+
+ + Symbols + + Symbols + +
+
Symbol
+
Definition
+
+
+ + Clause 4 + + Clause 4 + + + Introduction + + Introduction + + + + Clause 4.2 + + Clause 4.2 + + + + + + + 1 + . + + + + Clause + 1 + + + + + + + + 2 + . + + + + Clause + 2 + + + + Normative References + + Normative References + + +
+ + + <strong>Annex</strong> + + + + Annex + + + + Annex A.1 + + Annex A.1 + + + Annex A.1a + + Annex A.1a + + + + + + + Bibliography + + Bibliography + + + Bibliography Subsection + + Bibliography Subsection + + + + +
OUTPUT expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert .new(presxml_options) @@ -1532,16 +1974,16 @@ input = <<~INPUT - A0

+ A0

Introduction - A

+ A

Introduction Subsection - B

+ B

Introduction Sub-subsection - C

+ C

@@ -1566,132 +2008,288 @@ INPUT presxml = <<~PRESXML - - - - Table of contents - -

A0

- - Introduction -

A

- - Introduction Subsection -

B

- - Introduction Sub-subsection -

C

-
-
-
-
- - - - 1. - <tab/> - Introduction - -

A

- - - 1.1. - <tab/> - Introduction Subsection - -

B

- - - 1.1.1. - <tab/> - Introduction Sub-subsection - -

C

-
-
-
-

D

- - - 2. - <tab/> - Clause 2 - - -
-
+ + + + Table of contents + + A0 +

+ A0 +

+ + Introduction + + Introduction + + A +

+ A +

+ + Introduction Subsection + + Introduction Subsection + + B +

+ B +

+ + Introduction Sub-subsection + + Introduction Sub-subsection + + C +

+ C +

+
+
+
+
+ + + Introduction + + + 1 + . + + + + + Introduction + + + Clause + 1 + + A +

+ A +

+ + Introduction Subsection + + + 1 + . + 1 + . + + + + + Introduction Subsection + + + Clause + 1 + . + 1 + + B +

+ B +

+ + Introduction Sub-subsection + + + 1 + . + 1 + . + 1 + . + + + + + Introduction Sub-subsection + + + Clause + 1 + . + 1 + . + 1 + + C +

+ C +

+
+
+
+ D +

+ D +

+ + Clause 2 + + + 2 + . + + + + + Clause 2 + + + Clause + 2 + + +
+
PRESXML html = <<~OUTPUT #{HTML_HDR} -

A0

-
-
-

Introduction

-

A

-
-

Introduction Subsection

-

B

-
-

Introduction Sub-subsection

-

C

-
-
+

A0

+
+
+

Introduction

+

A

+
+

Introduction Subsection

+

B

+
+

Introduction Sub-subsection

+

C

+
+
+
+
+

1.  Introduction

+

A

+
+

1.1.  Introduction Subsection

+

B

+
+

1.1.1.  Introduction Sub-subsection

+

C

+
+
+
+

D

+
+

2.  Clause 2

+
-
-

1.   Introduction

-

A

-
-

1.1.   Introduction Subsection

-

B

-
-

1.1.1.   Introduction Sub-subsection

-

C

-
-
-
-

D

-
-

2.   Clause 2

-
-
- + OUTPUT word = <<~OUTPUT - -


+
+ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + pres_output = IsoDoc::PresentationXMLConvert .new(presxml_options) - .convert("test", input, true)))) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output))) .to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))).to be_equivalent_to Xml::C14n.format(html) - IsoDoc::WordConvert.new({}).convert("test", presxml, false) - expect(Xml::C14n.format(File.read("test.doc") + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(html) + IsoDoc::WordConvert.new({}).convert("test", pres_output, false) + expect(Xml::C14n.format(strip_guid(File.read("test.doc") .sub(/^.*.*$}m, ""))) + .sub(%r{.*$}m, "")))) .to be_equivalent_to Xml::C14n.format(word) end @@ -1707,20 +2305,25 @@ INPUT output = <<~OUTPUT - - - - - Table of contents - - - Introduction - - Introduction Subsection - - - - + + + + Table of contents + + + Introduction + + Introduction + + + Introduction Subsection + + Introduction Subsection + + + + + OUTPUT expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert .new({ suppressheadingnumbers: true } @@ -1746,28 +2349,78 @@ INPUT presxml = <<~PRESXML - - - - Table of contents - - - - - 1.<tab/>Clause 4 - - 1.1.<tab/>Introduction - - - 1.2.<tab/>Clause 4.2 -

ABC

-
-
-
-
+ + + + Table of contents + + + + + Clause 4 + + + 1 + . + + + + + Clause 4 + + + Clause + 1 + + + Introduction + + + 1 + . + 1 + . + + + + + Introduction + + + Clause + 1 + . + 1 + + + + Clause 4.2 + + + 1 + . + 2 + . + + + + + Clause 4.2 + + + Clause + 1 + . + 2 + +

ABC

+
+
+
+
PRESXML - output = <<~"OUTPUT" + html = <<~"OUTPUT" #{HTML_HDR}

1.  Clause 4

@@ -1783,13 +2436,14 @@ OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + pres_output = IsoDoc::PresentationXMLConvert .new(presxml_options) - .convert("test", input, true)))) + .convert("test", input, true) + expect(Xml::C14n.format(strip_guid(pres_output))) .to be_equivalent_to Xml::C14n.format(presxml) - expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", presxml, true))) - .to be_equivalent_to Xml::C14n.format(output) + expect(Xml::C14n.format(strip_guid(IsoDoc::HtmlConvert.new({}) + .convert("test", pres_output, true)))) + .to be_equivalent_to Xml::C14n.format(html) end it "processes inline section headers with suppressed heading numbering" do @@ -1811,20 +2465,33 @@ .merge(presxml_options)) .convert("test", input, true)))) .to be_equivalent_to Xml::C14n.format(<<~OUTPUT) - - Table of contents + + + + Table of contents + + - - Clause 4 - - Introduction - - - Clause 4.2 - - + + Clause 4 + + Clause 4 + + + Introduction + + Introduction + + + + Clause 4.2 + + Clause 4.2 + + + - + OUTPUT end @@ -1848,37 +2515,79 @@ INPUT output = <<~OUTPUT - - - - Table of contents - - - Intro - - - - - - - 1. - - 1.1. - - - 1.2. - - - - + + + + Table of contents + + + + Intro + + Intro + + + + + + + + + + + 1 + . + + + + Clause + 1 + + + + + 1 + . + 1 + . + + + + Clause + 1 + . + 1 + + + + + + 1 + . + 2 + . + + + + Clause + 1 + . + 2 + + + + + OUTPUT - expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert.new(presxml_options) - .convert("test", input, true)))).to be_equivalent_to Xml::C14n.format(output) + expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true)))) + .to be_equivalent_to Xml::C14n.format(output) end it "processes disconnected titles" do input = <<~INPUT - + @@ -1936,6 +2645,57 @@ OUTPUT expect(Xml::C14n.format(IsoDoc::HtmlConvert.new({}) - .convert("test", input, true))).to be_equivalent_to Xml::C14n.format(output) + .convert("test", input, true))) + .to be_equivalent_to Xml::C14n.format(output) + end + + it "processes duplicate ids between Semantic and Presentation XML titles" do + input = <<~INPUT + + + + Title <bookmark id="A2"/> <index><primary>title</primary></index> + + + + INPUT + output = <<~OUTPUT + + + + Table of contents + + + + + + Title + <bookmark original-id="A2"/> + + + + 1 + . + + + + + + Title + + + + + Clause + 1 + + + + + OUTPUT + expect(Xml::C14n.format(strip_guid(IsoDoc::PresentationXMLConvert + .new(presxml_options) + .convert("test", input, true)))) + .to be_equivalent_to Xml::C14n.format(output) end end diff --git a/spec/isodoc/sourcecode_spec.rb b/spec/isodoc/sourcecode_spec.rb index d58586e2..934ca03c 100644 --- a/spec/isodoc/sourcecode_spec.rb +++ b/spec/isodoc/sourcecode_spec.rb @@ -4,11 +4,8 @@ it "processes sourcecode" do input = <<~INPUT - - - Ruby code - puts x - + + Ruby codeputs x Hey Que? @@ -16,84 +13,106 @@ INPUT presxml = <<~OUTPUT - - - - Table of contents - - Foreword - - - Figure 1 — Ruby - code - - puts x - - Hey - Que? - - - + + + + Table of contents + + + Foreword + + Foreword + + + + Ruby + code + + + + Figure + 1 + +  — + + Ruby + code + + + + Figure + 1 + + puts x + + Hey + Que? + + + + OUTPUT html = <<~OUTPUT #{HTML_HDR}
-
-

Foreword

-

       
         puts x
     
-

Figure 1 — Ruby code

-
Hey
       Que?
-
-
- - +
+

Foreword

+
puts x
+

+ Figure 1 — Ruby + code +

+
+                      Hey
+                      
+ Que? +
+
+
+
+ + OUTPUT doc = <<~OUTPUT - -