Class: Metanorma::Standoc::NumberInlineMacro
- Inherits:
-
Asciidoctor::Extensions::InlineMacroProcessor
- Object
- Asciidoctor::Extensions::InlineMacroProcessor
- Metanorma::Standoc::NumberInlineMacro
show all
- Includes:
- Utils
- Defined in:
- lib/metanorma/standoc/macros_inline.rb
Constant Summary
collapse
- MATHML_NS =
"http://www.w3.org/1998/Math/MathML".freeze
Constants included
from Utils
Utils::SUBCLAUSE_XPATH
Instance Method Summary
collapse
Methods included from Utils
adoc2xml, #asciimath_key, #attr_code, #convert, #csv_split, #dl_to_attrs, #dl_to_elems, #document_ns_attributes, #grkletters, #isodoc, #kv_parse, #link_unwrap, #noko, #quoted_csv_split, #refid?, #term_expr, #to_xml, #wrap_in_para, #xml_encode
Instance Method Details
163
164
165
166
167
168
169
170
171
|
# File 'lib/metanorma/standoc/macros_inline.rb', line 163
def format(attrs, number)
out = quoted_csv_split(attrs || "", ",").map do |x|
m = /^(.+?)=(.+)?$/.match(HTMLEntities.new.decode(x)) or next
"#{m[1]}='#{m[2]}'"
end
/^\+/.match?(number.strip) and out << "number_sign='plus'"
out.join(",")
end
|
#number(text) ⇒ Object
173
174
175
176
177
178
|
# File 'lib/metanorma/standoc/macros_inline.rb', line 173
def number(text)
n = BigDecimal(text)
trailing_zeroes = 0
m = /\.[1-9]*(0+)/.match(text) and trailing_zeroes += m[1].size
n.to_s("E").sub("e", "0" * trailing_zeroes + "e") end
|
#process(parent, target, attrs) ⇒ Object
180
181
182
183
184
185
186
187
188
|
# File 'lib/metanorma/standoc/macros_inline.rb', line 180
def process(parent, target, attrs)
out = Asciidoctor::Inline.new(parent, :quoted, attrs["text"]).convert
fmt = format(out, target)
fmt.empty? and fmt = "default"
fmt = %( number-format="#{fmt}")
<<~OUTPUT
<stem type="MathML"#{fmt}><math xmlns='#{MATHML_NS}'><mn>#{number(target)}</mn></math></stem>
OUTPUT
end
|
#unquote(str) ⇒ Object
159
160
161
|
# File 'lib/metanorma/standoc/macros_inline.rb', line 159
def unquote(str)
str.sub(/^(["'])(.+)\1$/, "\\2")
end
|