From f147a0b20b80fcdfc2d5fa8f44a6e1db176f771b Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Sun, 21 Jul 2024 19:04:53 +1000 Subject: [PATCH] Do not add linebreak within XML blocks, wrong for CJK: https://github.com/metanorma/mn-samples-jis/issues/25 --- lib/metanorma/standoc/anchor.rb | 6 +++--- lib/metanorma/standoc/base.rb | 2 +- lib/metanorma/standoc/blocks.rb | 10 +++++----- lib/metanorma/standoc/blocks_image.rb | 2 +- lib/metanorma/standoc/blocks_notes.rb | 12 ++++++------ lib/metanorma/standoc/cleanup_ref.rb | 1 - lib/metanorma/standoc/inline.rb | 10 +++++----- lib/metanorma/standoc/lists.rb | 8 ++++---- lib/metanorma/standoc/ref.rb | 21 +++++++++------------ lib/metanorma/standoc/terms.rb | 4 ++-- metanorma-standoc.gemspec | 1 + 11 files changed, 37 insertions(+), 40 deletions(-) diff --git a/lib/metanorma/standoc/anchor.rb b/lib/metanorma/standoc/anchor.rb index 4e854def..ec76026c 100644 --- a/lib/metanorma/standoc/anchor.rb +++ b/lib/metanorma/standoc/anchor.rb @@ -34,7 +34,7 @@ def inline_anchor_xref_attrs(node) t = node.target.gsub(/^#/, "").gsub(%r{(\.xml|\.adoc)(#.*$)}, "\\2") attrs, text = inline_anchor_xref_match(text) attrs.empty? and - return { target: t, type: "inline", text: text, style: @xrefstyle } + return { target: t, type: "inline", text:, style: @xrefstyle } inline_anchor_xref_attrs1(attrs, t, text) end @@ -46,13 +46,13 @@ def concatenate_attributes_to_xref_text(node) end def inline_anchor_xref_attrs1(attrs, target, text) - { target: target, hidden: attrs["hidden"], + { target:, hidden: attrs["hidden"], type: attrs.key?("fn") ? "footnote" : "inline", case: %w(capital lowercase).detect { |x| attrs.key?(x) }, label: attrs["label"], style: attrs["style"] || @xrefstyle, droploc: attrs.key?("droploc") ? true : nil, - text: text }.compact + text: }.compact end XREF_ATTRS = "hidden|style|droploc|capital|lowercase|label".freeze diff --git a/lib/metanorma/standoc/base.rb b/lib/metanorma/standoc/base.rb index 39f9285c..31477dd2 100644 --- a/lib/metanorma/standoc/base.rb +++ b/lib/metanorma/standoc/base.rb @@ -130,7 +130,7 @@ def metadata_attrs(node) %w(presentation semantic).each do |t| /^#{t}-metadata-/.match?(k) or next k = k.sub(/^#{t}-metadata-/, "") - csv_split(v, ",")&.each do |c| + quoted_csv_split(v)&.each do |c| ret << "<#{t}-metadata><#{k}>#{c}" end end diff --git a/lib/metanorma/standoc/blocks.rb b/lib/metanorma/standoc/blocks.rb index 4f87c437..0250a4ef 100644 --- a/lib/metanorma/standoc/blocks.rb +++ b/lib/metanorma/standoc/blocks.rb @@ -90,7 +90,7 @@ def term_example(node) )) do |ex| wrap_in_para(node, ex) end - end.join("\n") + end.join("") end def example(node) @@ -128,7 +128,7 @@ def pseudocode_example(node) figure_title(node, ex) wrap_in_para(node, ex) end - end.join("\n") + end.join("") end def example_attrs(node) @@ -141,7 +141,7 @@ def example_proper(node) node.title.nil? or ex.name { |name| name << node.title } wrap_in_para(node, ex) end - end.join("\n") + end.join("") end def para_attrs(node) @@ -158,7 +158,7 @@ def paragraph(node) xml.p **para_attrs(node) do |xml_t| xml_t << node.content end - end.join("\n") + end.join("") end def quote_attrs(node) @@ -183,7 +183,7 @@ def quote(node) quote_attribution(node, q) wrap_in_para(node, q) end - end.join("\n") + end.join("") end def listing_attrs(node) diff --git a/lib/metanorma/standoc/blocks_image.rb b/lib/metanorma/standoc/blocks_image.rb index 7d09e2e4..af30071c 100644 --- a/lib/metanorma/standoc/blocks_image.rb +++ b/lib/metanorma/standoc/blocks_image.rb @@ -26,7 +26,7 @@ def figure_example(node) node.title.nil? or ex.name { |name| name << node.title } wrap_in_para(node, ex) end - end.join("\n") + end.join("") end def figure_title(node, out) diff --git a/lib/metanorma/standoc/blocks_notes.rb b/lib/metanorma/standoc/blocks_notes.rb index 7022130e..1a661853 100644 --- a/lib/metanorma/standoc/blocks_notes.rb +++ b/lib/metanorma/standoc/blocks_notes.rb @@ -32,7 +32,7 @@ def sidebar(node) xml.review **sidebar_attrs(node) do |r| wrap_in_para(node, r) end - end.join("\n") + end.join("") end def todo_attrs(node) @@ -41,7 +41,7 @@ def todo_attrs(node) attr_code(id_attr(node) .merge(reviewer: node.attr("reviewer") || node.attr("source") || "(Unknown)", - date: date, type: "todo")) + date:, type: "todo")) end def todo(node) @@ -49,7 +49,7 @@ def todo(node) xml.review **todo_attrs(node) do |r| wrap_in_para(node, r) end - end.join("\n") + end.join("") end def termnote(node) @@ -57,7 +57,7 @@ def termnote(node) xml.termnote **termnote_attrs(node) do |ex| wrap_in_para(node, ex) end - end.join("\n") + end.join("") end def note(node) @@ -67,7 +67,7 @@ def note(node) xml.note **note_attrs(node) do |c| wrap_in_para(node, c) end - end.join("\n") + end.join("") end def boilerplate_note(node) @@ -101,7 +101,7 @@ def admonition(node) node.title.nil? or a.name { |name| name << node.title } wrap_in_para(node, a) end - end.join("\n") + end.join("") end def admonition_alternatives(node) diff --git a/lib/metanorma/standoc/cleanup_ref.rb b/lib/metanorma/standoc/cleanup_ref.rb index 69a7c3b3..ec2a0b93 100644 --- a/lib/metanorma/standoc/cleanup_ref.rb +++ b/lib/metanorma/standoc/cleanup_ref.rb @@ -1,4 +1,3 @@ -require "set" require "relaton_bib" require_relative "merge_bibitems" require_relative "spans_to_bibitem" diff --git a/lib/metanorma/standoc/inline.rb b/lib/metanorma/standoc/inline.rb index 976bb36c..675f1afa 100644 --- a/lib/metanorma/standoc/inline.rb +++ b/lib/metanorma/standoc/inline.rb @@ -43,21 +43,21 @@ def stem_parse(text, xml, style, block) if /<([^:>&]+:)?math(\s+[^>&]+)?> | <([^:>&]+:)?math(\s+[^>&]+)?>/x.match? text math = xml_encode(text) - xml.stem type: "MathML", block: block do |s| + xml.stem(type: "MathML", block:) do |s| s << math end elsif style == :latexmath then latex_parse(text, xml, block) else - xml.stem text&.gsub("&#", "&#"), type: "AsciiMath", block: block + xml.stem text&.gsub("&#", "&#"), type: "AsciiMath", block: end end def latex_parse(text, xml, block) latex = latex_parse1(text, block) or - return xml.stem type: "MathML", block: block - xml.stem type: "MathML", block: block do |s| + return xml.stem type: "MathML", block: + xml.stem(type: "MathML", block:) do |s| math = Nokogiri::XML.fragment(latex.sub(/<\?[^>]+>/, "")) - .elements[0] + .elements[0] math.delete("alttext") s.parent.children = math s << "#{text}" diff --git a/lib/metanorma/standoc/lists.rb b/lib/metanorma/standoc/lists.rb index 5b4284e7..7a6d23d9 100644 --- a/lib/metanorma/standoc/lists.rb +++ b/lib/metanorma/standoc/lists.rb @@ -41,7 +41,7 @@ def ulist(node) list_caption(node, xml_ul) node.items.each { |item| ul_li(xml_ul, item) } end - end.join("\n") + end.join("") end def olist_style(style) @@ -67,7 +67,7 @@ def olist(node) list_caption(node, xml_ol) node.items.each { |item| li(xml_ol, item) } end - end.join("\n") + end.join("") end def dt(terms, xml_dl) @@ -107,7 +107,7 @@ def dlist(node) dd(dd, xml_dl) end end - end.join("\n") + end.join("") end def colist(node) @@ -117,7 +117,7 @@ def colist(node) xml_li.p { |p| p << item.text } end end - end.join("\n") + end.join("") end def list_caption(node, out) diff --git a/lib/metanorma/standoc/ref.rb b/lib/metanorma/standoc/ref.rb index c3467a40..342d26a8 100644 --- a/lib/metanorma/standoc/ref.rb +++ b/lib/metanorma/standoc/ref.rb @@ -27,7 +27,7 @@ def isorefrender1(bib, match, code, year, allp = "") def isorefmatchescode(match, _item) code = analyse_ref_code(match[:code]) yr = norm_year(match[:year]) - { code: match[:code], year: yr, match: match, + { code: match[:code], year: yr, match:, title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel], analyse_code: code, lang: @lang || :all } end @@ -47,7 +47,7 @@ def isorefmatchesout(item, xml) def isorefmatches2code(match, _item) code = analyse_ref_code(match[:code]) { code: match[:code], no_year: true, lang: @lang || :all, - note: match[:fn], year: nil, match: match, analyse_code: code, + note: match[:fn], year: nil, match:, analyse_code: code, title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel] } end @@ -77,7 +77,7 @@ def isorefmatches3code(match, _item) code = analyse_ref_code(match[:code]) yr = norm_year(match[:year]) hasyr = !yr.nil? && yr != "--" - { code: match[:code], match: match, yr: yr, hasyr: hasyr, + { code: match[:code], match:, yr:, hasyr:, year: hasyr ? yr : nil, lang: @lang || :all, all_parts: true, no_year: yr == "--", title: match[:text], usrlbl: match[:usrlbl] || code[:usrlabel] } @@ -162,11 +162,11 @@ def refitemcode(item, node) def refitem1code(_item, match) code = analyse_ref_code(match[:code]) ((code[:id] && code[:numeric]) || code[:nofetch]) and - return { code: nil, match: match, analyse_code: code, + return { code: nil, match:, analyse_code: code, hidden: code[:hidden] } { code: code[:id], analyse_code: code, localfile: code[:localfile], year: (m = refitem1yr(code[:id])) ? m[:year] : nil, - title: match[:text], match: match, hidden: code[:hidden], + title: match[:text], match:, hidden: code[:hidden], usrlbl: match[:usrlbl] || code[:usrlabel], lang: @lang || :all } end @@ -187,29 +187,26 @@ def refitemout(item, xml) ISO_REF = %r{^[^"]+)"> \[(?\([^)]+\))?(?(?:ISO|IEC)[^0-9]*\s[0-9-]+|IEV) - (?::(?[0-9][0-9-]+))?\],?\s*(?.*)$}xm.freeze + (?::(?[0-9][0-9-]+))?\],?\s*(?.*)$}xm ISO_REF_NO_YEAR = %r{^[^"]+)"> \[(?\([^)]+\))?(?(?:ISO|IEC)[^0-9]*\s[0-9-]+): - (?:--|&\#821[12];)\],?\s* + (?:--|–|—|&\#821[12];)\],?\s* (?:]*>\s*

(?[^\]]+)

\s*)?,?\s?(?.*)$}xm - .freeze ISO_REF_ALL_PARTS = %r{^[^"]+)"> \[(?\([^)]+\))?(?(?:ISO|IEC)[^0-9]*\s[0-9]+) - (?::(?--|&\#821[12];|[0-9][0-9-]+))?\s + (?::(?--|–|—|&\#821[12];|[0-9][0-9-]+))?\s \(all\sparts\)\],?\s* - (?:]*>\s*

(?[^\]]+)

\s*,?\s?)?(?.*)$}xm.freeze + (?:]*>\s*

(?[^\]]+)

\s*,?\s?)?(?.*)$}xm NON_ISO_REF = %r{^[^"]+)"> \[(?\([^)]+\))?(?.+?)\],?\s*(?.*)$}xm - .freeze NON_ISO_REF1 = %r{^[^"]+)"> (?\([^)]+\))?(?.+?),?\s*(?.*)$}xm - .freeze def reference1_matches(item) matched = ISO_REF.match item diff --git a/lib/metanorma/standoc/terms.rb b/lib/metanorma/standoc/terms.rb index ac5a39ec..3daed89c 100644 --- a/lib/metanorma/standoc/terms.rb +++ b/lib/metanorma/standoc/terms.rb @@ -170,7 +170,7 @@ def termsource(node) seen_xref = Nokogiri::XML.fragment(matched[:xref]) add_term_source(node, xml_t, seen_xref, matched) end - end.join("\n") + end.join("") end def termdefinition(node) @@ -178,7 +178,7 @@ def termdefinition(node) xml.definition **attr_code(type: node.attr("type")) do |d| d << node.content end - end.join("\n") + end.join("") end end end diff --git a/metanorma-standoc.gemspec b/metanorma-standoc.gemspec index 984faf25..5144fff3 100644 --- a/metanorma-standoc.gemspec +++ b/metanorma-standoc.gemspec @@ -37,6 +37,7 @@ Gem::Specification.new do |spec| spec.add_dependency "metanorma-plugin-datastruct", "~> 0.3.0" spec.add_dependency "metanorma-plugin-glossarist", "~> 0.2.0" spec.add_dependency "metanorma-plugin-lutaml", "~> 0.7.0" + spec.add_dependency "metanorma-utils", "~> 1.9.0" spec.add_dependency "ruby-jing" # relaton-cli not just relaton, to avoid circular reference in metanorma spec.add_dependency "asciimath2unitsml", "~> 0.4.0"