Module: Metanorma::Standoc::Symbols
- Included in:
- Cleanup
- Defined in:
- lib/metanorma/cleanup/symbols.rb
Instance Method Summary collapse
- #extract_symbols_list(dlist) ⇒ Object
-
#symbol_key(sym) ⇒ Object
Indices sort after letter but before any following letter (x, x_m, x_1, xa); we use colon to force that sort order.
- #symbols_cleanup(docxml) ⇒ Object
Instance Method Details
#extract_symbols_list(dlist) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/metanorma/cleanup/symbols.rb', line 19 def extract_symbols_list(dlist) dl_out = [] dlist.xpath("./dt | ./dd").each do |dtd| if dtd.name == "dt" dl_out << { dt: dtd.remove, key: symbol_key(dtd) } else dl_out.last[:dd] = dtd.remove end end dl_out end |
#symbol_key(sym) ⇒ Object
Indices sort after letter but before any following letter (x, x_m, x_1, xa); we use colon to force that sort order. Numbers sort after letters; we use thorn to force that sort order. Capitals sort before their corresponding lowercase.
10 11 12 13 14 15 16 17 |
# File 'lib/metanorma/cleanup/symbols.rb', line 10 def symbol_key(sym) @c.decode(asciimath_key(sym).text) .gsub(/[\[\]{}<>()]/, "").gsub(/\s/m, "") .gsub(/[[:punct:]]|[_^]/, ":\\0").delete("`") .gsub(/[0-9]+/, "รพ\\0") .tr("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz", "ABCFEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") end |
#symbols_cleanup(docxml) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/metanorma/cleanup/symbols.rb', line 31 def symbols_cleanup(docxml) docxml.xpath("//definitions/dl").each do |dl| dl_out = extract_symbols_list(dl) dl_out.sort! { |a, b| a[:key] <=> b[:key] || a[:dt] <=> b[:dt] } dl.children = dl_out.map { |d| d[:dt].to_s + d[:dd].to_s }.join("\n") end docxml end |