Skip to content

Commit

Permalink
Do not add linebreak within XML blocks, wrong for CJK: metanorma/mn-s…
Browse files Browse the repository at this point in the history
opoudjis committed Jul 21, 2024
1 parent 7cf145d commit f147a0b
Showing 11 changed files with 37 additions and 40 deletions.
6 changes: 3 additions & 3 deletions lib/metanorma/standoc/anchor.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/base.rb
Original file line number Diff line number Diff line change
@@ -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}</#{k}></#{t}-metadata>"
end
end
10 changes: 5 additions & 5 deletions lib/metanorma/standoc/blocks.rb
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/blocks_image.rb
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 6 additions & 6 deletions lib/metanorma/standoc/blocks_notes.rb
Original file line number Diff line number Diff line change
@@ -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,23 +41,23 @@ 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)
noko do |xml|
xml.review **todo_attrs(node) do |r|
wrap_in_para(node, r)
end
end.join("\n")
end.join("")
end

def termnote(node)
noko do |xml|
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)
1 change: 0 additions & 1 deletion lib/metanorma/standoc/cleanup_ref.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "set"
require "relaton_bib"
require_relative "merge_bibitems"
require_relative "spans_to_bibitem"
10 changes: 5 additions & 5 deletions lib/metanorma/standoc/inline.rb
Original file line number Diff line number Diff line change
@@ -43,21 +43,21 @@ def stem_parse(text, xml, style, block)
if /&lt;([^:>&]+:)?math(\s+[^>&]+)?&gt; |
<([^:>&]+:)?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("&amp;#", "&#"), type: "AsciiMath", block: block
xml.stem text&.gsub("&amp;#", "&#"), 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 << "<latexmath>#{text}</latexmath>"
8 changes: 4 additions & 4 deletions lib/metanorma/standoc/lists.rb
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 9 additions & 12 deletions lib/metanorma/standoc/ref.rb
Original file line number Diff line number Diff line change
@@ -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{^<ref\sid="(?<anchor>[^"]+)">
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
(?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm.freeze
(?::(?<year>[0-9][0-9-]+))?\]</ref>,?\s*(?<text>.*)$}xm

ISO_REF_NO_YEAR =
%r{^<ref\sid="(?<anchor>[^"]+)">
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9-]+):
(?:--|&\#821[12];)\]</ref>,?\s*
(?:--|–|—|&\#821[12];)\]</ref>,?\s*
(?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>)?,?\s?(?<text>.*)$}xm
.freeze

ISO_REF_ALL_PARTS =
%r{^<ref\sid="(?<anchor>[^"]+)">
\[(?<usrlbl>\([^)]+\))?(?<code>(?:ISO|IEC)[^0-9]*\s[0-9]+)
(?::(?<year>--|&\#821[12];|[0-9][0-9-]+))?\s
(?::(?<year>--|–|—|&\#821[12];|[0-9][0-9-]+))?\s
\(all\sparts\)\]</ref>,?\s*
(?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm.freeze
(?:<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?)?(?<text>.*)$}xm

NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
\[(?<usrlbl>\([^)]+\))?(?<code>.+?)\]</ref>,?\s*(?<text>.*)$}xm
.freeze

NON_ISO_REF1 = %r{^<ref\sid="(?<anchor>[^"]+)">
(?<usrlbl>\([^)]+\))?(?<code>.+?)</ref>,?\s*(?<text>.*)$}xm
.freeze

def reference1_matches(item)
matched = ISO_REF.match item
4 changes: 2 additions & 2 deletions lib/metanorma/standoc/terms.rb
Original file line number Diff line number Diff line change
@@ -170,15 +170,15 @@ 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)
noko do |xml|
xml.definition **attr_code(type: node.attr("type")) do |d|
d << node.content
end
end.join("\n")
end.join("")
end
end
end
1 change: 1 addition & 0 deletions metanorma-standoc.gemspec
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit f147a0b

Please sign in to comment.