Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug processing of ampersand for XML entities in number formatting a… #923

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/cleanup_maths.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def mathml_stem_format(stem)
"#{m[1]}='#{m[2]}'"
end.join(",")
stem.xpath(".//m:mn", "m" => MATHML_NS).each do |m|
m["data-metanorma-numberformat"] = attr
attr.empty? or m["data-metanorma-numberformat"] = attr
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/metanorma/standoc/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ def init_bib_log
def init_math(node)
@keepasciimath = node.attr("mn-keep-asciimath") &&
node.attr("mn-keep-asciimath") != "false"
@numberfmt_default = kv_parse(node.attr("number-presentation"))
@numberfmt_formula = node.attr("number-presentation-formula")
@numberfmt_default = kv_parse(@c.decode(node.attr("number-presentation")))
@numberfmt_formula = @c.decode(node.attr("number-presentation-formula"))
@numberfmt_formula == "number-presentation" and
@numberfmt_formula = node.attr("number-presentation")
@numberfmt_formula = @c.decode(node.attr("number-presentation"))
@numberfmt_formula == "default" and
@numberfmt_formula = "notation='basic'"
@numberfmt_prof = node.attributes.each_with_object({}) do |(k, v), m|
p = /^number-presentation-profile-(.*)$/.match(k) or next
m[p[1]] = kv_parse(v)
m[p[1]] = kv_parse(@c.decode(v))
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/metanorma/standoc/macros_inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def unquote(str)
def format(attrs)
# a="," => "a=,"
quoted_csv_split(attrs || "", ",").map do |x|
m = /^(.+?)=(.+)?$/.match(x) or next
m = /^(.+?)=(.+)?$/.match(HTMLEntities.new.decode(x)) or next
"#{m[1]}='#{m[2]}'"
end.join(",")
end
Expand Down
3 changes: 2 additions & 1 deletion lib/metanorma/standoc/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def quoted_csv_split(text, delim = ",", eql = "=")
%("\\1#{eql}\\3"))
Metanorma::Utils::csv_split(text, delim)
.map do |x|
c.encode(x.sub(/^(["'])(.+)\1$/, "\\2"), :basic, :hexadecimal)
c.encode(x.sub(/^(["'])(.+)\1$/, "\\2"),
:basic, :hexadecimal)
end
end

Expand Down
9 changes: 8 additions & 1 deletion spec/metanorma/cleanup_math_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,18 @@
:nodoc:
:novalid:
:no-isobib:
:number-presentation: notation=e,exponent_sign=plus,precision=4
:number-presentation: notation=e,,exponent_sign=plus,precision=4
:number-presentation-profile-3: notation=scientific,exponent_sign=nil,decimal=","
:number-presentation-profile-x: notation=engineering,precision=4,times=','
:number-presentation-profile-y: group_digits=3,fraction_group_digits=3,decimal=",",group= ,notation=general

number:145[]
number:245[profile=3]
number:345[profile=x]
number:445[profile=x,precision=5]
number:545[profile=x,precision=5,digit_count=10,precision=nil]
number:645[precision=5,digit_count=10,exponent_sign=nil]
number:745[profile=y]
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Expand Down Expand Up @@ -124,6 +126,11 @@
<mn data-metanorma-numberformat="notation='e',precision='5',digit_count='10'">0.645e3</mn>
</math>
</stem>
<stem type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mn data-metanorma-numberformat="notation='general',exponent_sign='plus',precision='4',group_digits='3',fraction_group_digits='3',decimal=',',group=' '">0.745e3</mn>
</math>
</stem>
</p>
</sections>
</standard-document>
Expand Down
12 changes: 12 additions & 0 deletions spec/metanorma/macros_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@
number:10e20[decimal=",",notation=exponential]
number:1.0e19[decimal=",",notation=exponential]
number:1.0e-19[decimal=",",notation=exponential]
number:327428.7432878432992[decimal=",",group=&#x2009;,notation=exponential]
number:327428.7432878432992[group_digits=3,fraction_group_digits=3,decimal=",",group=&#x2009;,notation=general]
INPUT
output = <<~OUTPUT
#{BLANK_HDR}
Expand Down Expand Up @@ -164,6 +166,16 @@
<mn data-metanorma-numberformat="decimal=',',notation='exponential'">0.10e-18</mn>
</math>
</stem>
<stem type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mn data-metanorma-numberformat="decimal=',',group=' ',notation='exponential'">0.3274287432878432992e6</mn>
</math>
</stem>
<stem type="MathML">
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mn data-metanorma-numberformat="group_digits='3',fraction_group_digits='3',decimal=',',group=' ',notation='general'">0.3274287432878432992e6</mn>
</math>
</stem>
</p>
</sections>
</standard-document>
Expand Down
Loading