lib/isodoc/gb/gbbaseconvert.rb in metanorma-gb-1.3.25 vs lib/isodoc/gb/gbbaseconvert.rb in metanorma-gb-1.3.26

- old
+ new

@@ -10,11 +10,12 @@ def extract_fonts(options) b = options[:bodyfont] || "Arial" h = options[:headerfont] || "Arial" m = options[:monospacefont] || "Courier" t = options[:titlefont] || "Arial" - "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n$titlefont: #{t};\n" + "$bodyfont: #{b};\n$headerfont: #{h};\n$monospacefont: #{m};\n"\ + "$titlefont: #{t};\n" end def metadata_init(lang, script, labels) unless ["en", "zh"].include? lang lang = "zh" @@ -43,11 +44,12 @@ YAML.load_file(File.join(File.dirname(__FILE__), "i18n-en.yaml")) elsif lang == "zh" && script == "Hans" YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml")) else - YAML.load_file(File.join(File.dirname(__FILE__), "i18n-zh-Hans.yaml")) + YAML.load_file(File.join(File.dirname(__FILE__), + "i18n-zh-Hans.yaml")) end @labels = @labels.merge(y) end def omit_docid_prefix(prefix) @@ -98,38 +100,31 @@ def example_label(node) l10n(super + ":") end def note_parse(node, out) + note_parse1(node, out, note_label(node) + ":") + end + + def note_parse1(node, out, label) @note = true out.table **attr_code(id: node["id"], class: "Note") do |t| t.tr do |tr| @libdir = File.dirname(__FILE__) tr.td **EXAMPLE_TBL_ATTR do |td| - td << l10n(note_label(node) + ":") + td << l10n(label) end tr.td **{ style: "vertical-align:top;", class: "Note" } do |td| node.children.each { |n| parse(n, td) } end end end @note = false end def termnote_parse(node, out) - @note = true - out.table **attr_code(id: node["id"], class: "Note") do |t| - t.tr do |tr| - tr.td **EXAMPLE_TBL_ATTR do |td| - td << l10n("#{anchor(node['id'], :label)}:") - end - tr.td **{ style: "vertical-align:top;", class: "Note" } do |td| - node.children.each { |n| parse(n, td) } - end - end - end - @note = false + note_parse1(node, out, "#{anchor(node['id'], :label)}:") end def middle(isoxml, out) super end_line(isoxml, out) @@ -166,19 +161,21 @@ end def termref_render(x) x.sub!(%r{\s*\[MODIFICATION\]\s*$}m, l10n(", #{@modified_lbl}")) parts = x.split(%r{(\s*\[MODIFICATION\]|,)}m) - parts[1] = l10n(", #{@source_lbl}") if parts.size > 1 && parts[1] == "," && - !/^\s*#{@modified_lbl}/.match(parts[2]) + parts[1] = l10n(", #{@source_lbl}") if parts.size > 1 && + parts[1] == "," && !/^\s*#{@modified_lbl}/.match(parts[2]) parts.map do |p| - /\s*\[MODIFICATION\]/.match(p) ? l10n(", #{@modified_lbl} &mdash; ") : p + /\s*\[MODIFICATION\]/.match(p) ? + l10n(", #{@modified_lbl} &mdash; ") : p end.join.sub(/\A\s*/m, l10n("[")).sub(/\s*\z/m, l10n("]")) end def termref_resolve(docxml) - docxml.split(%r{(\[TERMREF\]|\[/TERMREF\])}).each_slice(4). + docxml.gsub(%r{\s*\[/TERMREF\]\s*</p>\s*<p>\s*\[TERMREF\]}, l10n("; ")). + split(%r{(\[TERMREF\]|\[/TERMREF\])}).each_slice(4). map do |a| a.size < 3 ? a[0] : a[0] + termref_render(a[2]) end.join end @@ -249,14 +246,11 @@ false end def example_parse(node, out) out.div **{ id: node["id"], class: "example" } do |div| - if node_begins_with_para(node) - example_p_parse(node, div) - else - example_parse1(node, div) - end + node_begins_with_para(node) ? + example_p_parse(node, div) : example_parse1(node, div) end end def textcleanup(docxml) termref_resolve(docxml)