metanorma-standoc 1.11.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +3 -31
- data/.gitignore +23 -0
- data/Gemfile +2 -0
- data/lib/asciidoctor/standoc/base.rb +2 -241
- data/lib/asciidoctor/standoc/blocks.rb +2 -238
- data/lib/asciidoctor/standoc/blocks_notes.rb +2 -100
- data/lib/asciidoctor/standoc/cleanup.rb +2 -207
- data/lib/asciidoctor/standoc/cleanup_amend.rb +2 -53
- data/lib/asciidoctor/standoc/cleanup_block.rb +2 -173
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +2 -204
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +2 -108
- data/lib/asciidoctor/standoc/cleanup_image.rb +2 -69
- data/lib/asciidoctor/standoc/cleanup_inline.rb +2 -179
- data/lib/asciidoctor/standoc/cleanup_maths.rb +2 -221
- data/lib/asciidoctor/standoc/cleanup_ref.rb +2 -169
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +2 -93
- data/lib/asciidoctor/standoc/cleanup_reqt.rb +2 -110
- data/lib/asciidoctor/standoc/cleanup_section.rb +2 -184
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +2 -91
- data/lib/asciidoctor/standoc/cleanup_symbols.rb +2 -47
- data/lib/asciidoctor/standoc/cleanup_table.rb +2 -67
- data/lib/asciidoctor/standoc/cleanup_terms.rb +2 -113
- data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +2 -161
- data/lib/asciidoctor/standoc/cleanup_text.rb +2 -95
- data/lib/asciidoctor/standoc/cleanup_toc.rb +3 -0
- data/lib/asciidoctor/standoc/cleanup_xref.rb +2 -106
- data/lib/asciidoctor/standoc/converter.rb +2 -123
- data/lib/asciidoctor/standoc/datamodel/attributes_table_preprocessor.rb +2 -56
- data/lib/asciidoctor/standoc/datamodel/diagram_preprocessor.rb +2 -102
- data/lib/asciidoctor/standoc/datamodel/plantuml_renderer.rb +3 -404
- data/lib/asciidoctor/standoc/deprecated.rb +5 -0
- data/lib/asciidoctor/standoc/front.rb +2 -219
- data/lib/asciidoctor/standoc/front_contributor.rb +2 -191
- data/lib/asciidoctor/standoc/inline.rb +2 -229
- data/lib/asciidoctor/standoc/lists.rb +2 -119
- data/lib/asciidoctor/standoc/macros.rb +2 -203
- data/lib/asciidoctor/standoc/macros_form.rb +2 -62
- data/lib/asciidoctor/standoc/macros_note.rb +2 -44
- data/lib/asciidoctor/standoc/macros_plantuml.rb +2 -112
- data/lib/asciidoctor/standoc/macros_terms.rb +2 -180
- data/lib/asciidoctor/standoc/ref.rb +2 -225
- data/lib/asciidoctor/standoc/ref_sect.rb +2 -143
- data/lib/asciidoctor/standoc/ref_utility.rb +2 -0
- data/lib/asciidoctor/standoc/render.rb +3 -0
- data/lib/asciidoctor/standoc/reqt.rb +2 -89
- data/lib/asciidoctor/standoc/section.rb +2 -190
- data/lib/asciidoctor/standoc/table.rb +2 -84
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +2 -178
- data/lib/asciidoctor/standoc/terms.rb +2 -153
- data/lib/asciidoctor/standoc/utils.rb +2 -116
- data/lib/asciidoctor/standoc/validate.rb +2 -157
- data/lib/asciidoctor/standoc/validate_section.rb +2 -54
- data/lib/isodoc/html/htmlstyle.css +20 -11
- data/lib/isodoc/html/htmlstyle.scss +11 -11
- data/lib/metanorma/standoc/base.rb +149 -0
- data/lib/{asciidoctor → metanorma}/standoc/basicdoc.rng +0 -0
- data/lib/{asciidoctor → metanorma}/standoc/biblio.rng +0 -0
- data/lib/metanorma/standoc/blocks.rb +239 -0
- data/lib/metanorma/standoc/blocks_notes.rb +101 -0
- data/lib/metanorma/standoc/cleanup.rb +146 -0
- data/lib/metanorma/standoc/cleanup_amend.rb +54 -0
- data/lib/metanorma/standoc/cleanup_block.rb +173 -0
- data/lib/metanorma/standoc/cleanup_boilerplate.rb +213 -0
- data/lib/metanorma/standoc/cleanup_footnotes.rb +109 -0
- data/lib/metanorma/standoc/cleanup_image.rb +70 -0
- data/lib/metanorma/standoc/cleanup_inline.rb +190 -0
- data/lib/metanorma/standoc/cleanup_maths.rb +222 -0
- data/lib/metanorma/standoc/cleanup_ref.rb +170 -0
- data/lib/metanorma/standoc/cleanup_ref_dl.rb +104 -0
- data/lib/metanorma/standoc/cleanup_reqt.rb +111 -0
- data/lib/metanorma/standoc/cleanup_section.rb +212 -0
- data/lib/metanorma/standoc/cleanup_section_names.rb +92 -0
- data/lib/metanorma/standoc/cleanup_symbols.rb +48 -0
- data/lib/metanorma/standoc/cleanup_table.rb +68 -0
- data/lib/metanorma/standoc/cleanup_terms.rb +140 -0
- data/lib/metanorma/standoc/cleanup_terms_designations.rb +199 -0
- data/lib/metanorma/standoc/cleanup_text.rb +96 -0
- data/lib/metanorma/standoc/cleanup_toc.rb +98 -0
- data/lib/metanorma/standoc/cleanup_xref.rb +107 -0
- data/lib/metanorma/standoc/converter.rb +124 -0
- data/lib/metanorma/standoc/datamodel/attributes_table_preprocessor.rb +57 -0
- data/lib/metanorma/standoc/datamodel/diagram_preprocessor.rb +103 -0
- data/lib/metanorma/standoc/datamodel/plantuml_renderer.rb +409 -0
- data/lib/metanorma/standoc/front.rb +224 -0
- data/lib/metanorma/standoc/front_contributor.rb +192 -0
- data/lib/metanorma/standoc/inline.rb +232 -0
- data/lib/{asciidoctor → metanorma}/standoc/isodoc.rng +90 -18
- data/lib/metanorma/standoc/lists.rb +120 -0
- data/lib/metanorma/standoc/macros.rb +204 -0
- data/lib/metanorma/standoc/macros_form.rb +63 -0
- data/lib/metanorma/standoc/macros_note.rb +45 -0
- data/lib/metanorma/standoc/macros_plantuml.rb +113 -0
- data/lib/metanorma/standoc/macros_terms.rb +181 -0
- data/lib/metanorma/standoc/ref.rb +243 -0
- data/lib/metanorma/standoc/ref_sect.rb +153 -0
- data/lib/metanorma/standoc/ref_utility.rb +129 -0
- data/lib/metanorma/standoc/render.rb +115 -0
- data/lib/metanorma/standoc/reqt.rb +90 -0
- data/lib/{asciidoctor → metanorma}/standoc/reqt.rng +0 -0
- data/lib/metanorma/standoc/section.rb +209 -0
- data/lib/metanorma/standoc/table.rb +85 -0
- data/lib/metanorma/standoc/term_lookup_cleanup.rb +179 -0
- data/lib/metanorma/standoc/terms.rb +160 -0
- data/lib/metanorma/standoc/utils.rb +101 -0
- data/lib/metanorma/standoc/validate.rb +158 -0
- data/lib/metanorma/standoc/validate_section.rb +55 -0
- data/lib/metanorma/standoc/version.rb +1 -1
- data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/model_representation.adoc.erb +0 -0
- data/lib/{asciidoctor → metanorma}/standoc/views/datamodel/plantuml_representation.adoc.erb +0 -0
- data/lib/metanorma-standoc.rb +1 -1
- data/metanorma-standoc.gemspec +4 -4
- data/spec/{asciidoctor → metanorma}/base_spec.rb +73 -8
- data/spec/{asciidoctor → metanorma}/blank_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/blocks_spec.rb +49 -20
- data/spec/{asciidoctor → metanorma}/cleanup_blocks_spec.rb +25 -1
- data/spec/{asciidoctor → metanorma}/cleanup_sections_spec.rb +2 -2
- data/spec/{asciidoctor → metanorma}/cleanup_spec.rb +9 -9
- data/spec/{asciidoctor → metanorma}/cleanup_terms_spec.rb +528 -91
- data/spec/{asciidoctor → metanorma}/datamodel/attributes_table_preprocessor_spec.rb +22 -22
- data/spec/{asciidoctor → metanorma}/datamodel/diagram_preprocessor_spec.rb +17 -17
- data/spec/{asciidoctor → metanorma}/inline_spec.rb +175 -6
- data/spec/{asciidoctor → metanorma}/isobib_cache_spec.rb +5 -9
- data/spec/{asciidoctor → metanorma}/lists_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/macros_json2text_spec.rb +0 -0
- data/spec/{asciidoctor → metanorma}/macros_plantuml_spec.rb +3 -3
- data/spec/{asciidoctor → metanorma}/macros_spec.rb +8 -8
- data/spec/{asciidoctor → metanorma}/macros_yaml2text_spec.rb +0 -0
- data/spec/metanorma/refs_dl_spec.rb +863 -0
- data/spec/{asciidoctor → metanorma}/refs_spec.rb +1277 -687
- data/spec/{asciidoctor → metanorma}/section_spec.rb +90 -3
- data/spec/{asciidoctor → metanorma}/table_spec.rb +1 -1
- data/spec/{asciidoctor → metanorma}/validate_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +179 -179
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +12 -12
- data/spec/vcr_cassettes/isobib_get_123.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_123_1.yml +98 -98
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +111 -111
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +13 -13
- data/spec/vcr_cassettes/isobib_get_124.yml +14 -14
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +14 -14
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +46 -46
- metadata +89 -38
- data/lib/asciidoctor/standoc/ref_date_id.rb +0 -62
- data/spec/asciidoctor/refs_dl_spec.rb +0 -864
@@ -1,48 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Cleanup
|
4
|
-
# Indices sort after letter but before any following
|
5
|
-
# letter (x, x_m, x_1, xa); we use colon to force that sort order.
|
6
|
-
# Numbers sort *after* letters; we use thorn to force that sort order.
|
7
|
-
def symbol_key(sym)
|
8
|
-
key = sym.dup
|
9
|
-
key.traverse do |n|
|
10
|
-
n.name == "math" and
|
11
|
-
n.replace(grkletters(MathML2AsciiMath.m2a(n.to_xml)))
|
12
|
-
end
|
13
|
-
ret = Nokogiri::XML(key.to_xml)
|
14
|
-
HTMLEntities.new.decode(ret.text.downcase)
|
15
|
-
.gsub(/[\[\]{}<>()]/, "").gsub(/\s/m, "")
|
16
|
-
.gsub(/[[:punct:]]|[_^]/, ":\\0").gsub(/`/, "")
|
17
|
-
.gsub(/[0-9]+/, "þ\\0")
|
18
|
-
end
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/cleanup_symbols"
|
19
3
|
|
20
|
-
def grkletters(text)
|
21
|
-
text.gsub(/\b(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|
|
22
|
-
lambda|mu|nu|xi|omicron|pi|rho|sigma|tau|upsilon|phi|chi|
|
23
|
-
psi|omega)\b/xi, "&\\1;")
|
24
|
-
end
|
25
|
-
|
26
|
-
def extract_symbols_list(dlist)
|
27
|
-
dl_out = []
|
28
|
-
dlist.xpath("./dt | ./dd").each do |dtd|
|
29
|
-
if dtd.name == "dt"
|
30
|
-
dl_out << { dt: dtd.remove, key: symbol_key(dtd) }
|
31
|
-
else
|
32
|
-
dl_out.last[:dd] = dtd.remove
|
33
|
-
end
|
34
|
-
end
|
35
|
-
dl_out
|
36
|
-
end
|
37
|
-
|
38
|
-
def symbols_cleanup(docxml)
|
39
|
-
docxml.xpath("//definitions/dl").each do |dl|
|
40
|
-
dl_out = extract_symbols_list(dl)
|
41
|
-
dl_out.sort! { |a, b| a[:key] <=> b[:key] || a[:dt] <=> b[:dt] }
|
42
|
-
dl.children = dl_out.map { |d| d[:dt].to_s + d[:dd].to_s }.join("\n")
|
43
|
-
end
|
44
|
-
docxml
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,68 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Cleanup
|
4
|
-
def dl1_table_cleanup(xmldoc)
|
5
|
-
q = "//table/following-sibling::*[1][self::dl]"
|
6
|
-
xmldoc.xpath(q).each do |s|
|
7
|
-
s["key"] == "true" and s.previous_element << s.remove
|
8
|
-
end
|
9
|
-
end
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/cleanup_table"
|
10
3
|
|
11
|
-
# move Key dl after table footer
|
12
|
-
def dl2_table_cleanup(xmldoc)
|
13
|
-
q = "//table/following-sibling::*[1][self::p]"
|
14
|
-
xmldoc.xpath(q).each do |s|
|
15
|
-
if s.text =~ /^\s*key[^a-z]*$/i && s&.next_element&.name == "dl"
|
16
|
-
s.next_element["key"] = "true"
|
17
|
-
s.previous_element << s.next_element.remove
|
18
|
-
s.remove
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def insert_thead(table)
|
24
|
-
thead = table.at("./thead")
|
25
|
-
return thead unless thead.nil?
|
26
|
-
|
27
|
-
if tname = table.at("./name")
|
28
|
-
thead = tname.add_next_sibling("<thead/>").first
|
29
|
-
return thead
|
30
|
-
end
|
31
|
-
table.children.first.add_previous_sibling("<thead/>").first
|
32
|
-
end
|
33
|
-
|
34
|
-
def header_rows_cleanup(xmldoc)
|
35
|
-
xmldoc.xpath("//table[@headerrows]").each do |s|
|
36
|
-
thead = insert_thead(s)
|
37
|
-
(thead.xpath("./tr").size...s["headerrows"].to_i).each do
|
38
|
-
row = s.at("./tbody/tr")
|
39
|
-
row.parent = thead
|
40
|
-
end
|
41
|
-
thead.xpath(".//td").each { |n| n.name = "th" }
|
42
|
-
s.delete("headerrows")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def table_cleanup(xmldoc)
|
47
|
-
dl1_table_cleanup(xmldoc)
|
48
|
-
dl2_table_cleanup(xmldoc)
|
49
|
-
notes_table_cleanup(xmldoc)
|
50
|
-
header_rows_cleanup(xmldoc)
|
51
|
-
end
|
52
|
-
|
53
|
-
# move notes into table
|
54
|
-
def notes_table_cleanup(xmldoc)
|
55
|
-
nomatches = false
|
56
|
-
until nomatches
|
57
|
-
nomatches = true
|
58
|
-
xmldoc.xpath("//table/following-sibling::*[1]"\
|
59
|
-
"[self::note[not(@keep-separate = 'true')]]").each do |n|
|
60
|
-
n.delete("keep-separate")
|
61
|
-
n.previous_element << n.remove
|
62
|
-
nomatches = false
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
@@ -1,114 +1,3 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/cleanup_terms"
|
3
3
|
|
4
|
-
module Asciidoctor
|
5
|
-
module Standoc
|
6
|
-
module Cleanup
|
7
|
-
def termdomain_cleanup(xmldoc)
|
8
|
-
xmldoc.xpath("//p/domain").each do |a|
|
9
|
-
prev = a.parent.previous
|
10
|
-
prev.next = a.remove
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def termdomain1_cleanup(xmldoc)
|
15
|
-
xmldoc.xpath("//term").each do |t|
|
16
|
-
d = t.xpath("./domain | ./subject | ./usageinfo").last or next
|
17
|
-
defn = d.at("../definition") and defn.previous = d.remove
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def termdefinition_cleanup(xmldoc)
|
22
|
-
generate_termdefinitions(xmldoc)
|
23
|
-
split_termdefinitions(xmldoc)
|
24
|
-
end
|
25
|
-
|
26
|
-
TERMDEF_BLOCKS =
|
27
|
-
"./p | ./ol | ./dl | ./ul | ./figure | ./formula | ./table".freeze
|
28
|
-
|
29
|
-
def generate_termdefinitions(xmldoc)
|
30
|
-
xmldoc.xpath("//term[not(definition)]").each do |d|
|
31
|
-
first_child = d.at(TERMDEF_BLOCKS) || next
|
32
|
-
t = Nokogiri::XML::Element.new("definition", xmldoc)
|
33
|
-
first_child.replace(t)
|
34
|
-
t << first_child.remove
|
35
|
-
d.xpath(TERMDEF_BLOCKS).each do |n|
|
36
|
-
t << n.remove
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def split_termdefinitions(xmldoc)
|
42
|
-
xmldoc.xpath("//definition").each do |d|
|
43
|
-
n = d.children.first
|
44
|
-
.add_previous_sibling("<nonverbalrepresentation/>").first
|
45
|
-
v = d.children.first.add_previous_sibling("<verbaldefinition/>").first
|
46
|
-
nonverb = false
|
47
|
-
d.elements.each do |e|
|
48
|
-
nonverb = split_termdefinitions1(e, n, v, nonverb)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def split_termdefinitions1(elem, nonverbal, verbal, nonverb)
|
54
|
-
case elem.name
|
55
|
-
when "nonverbalrepresentation", "verbaldefinition" then return nonverb
|
56
|
-
when "figure", "table", "formula"
|
57
|
-
nonverbal << elem.remove
|
58
|
-
nonverb = true
|
59
|
-
when "termsource"
|
60
|
-
(nonverb ? nonverbal : verbal) << elem.remove
|
61
|
-
else verbal << elem.remove
|
62
|
-
end
|
63
|
-
nonverb
|
64
|
-
end
|
65
|
-
|
66
|
-
def termdocsource_cleanup(xmldoc)
|
67
|
-
f = xmldoc.at("//preface | //sections")
|
68
|
-
xmldoc.xpath("//termdocsource").each { |s| f.previous = s.remove }
|
69
|
-
end
|
70
|
-
|
71
|
-
def term_children_cleanup(xmldoc)
|
72
|
-
xmldoc.xpath("//terms[terms]").each { |t| t.name = "clause" }
|
73
|
-
xmldoc.xpath("//term").each do |t|
|
74
|
-
%w(termnote termexample termsource term).each do |w|
|
75
|
-
t.xpath("./#{w}").each { |n| t << n.remove }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def termdef_from_termbase(xmldoc)
|
81
|
-
xmldoc.xpath("//term").each do |x|
|
82
|
-
if (c = x.at("./origin/termref")) && !x.at("./definition")
|
83
|
-
x.at("./origin").previous = fetch_termbase(c["base"], c.text)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
def termnote_example_cleanup(xmldoc)
|
89
|
-
%w(note example).each do |w|
|
90
|
-
xmldoc.xpath("//term#{w}[not(ancestor::term)]").each do |x|
|
91
|
-
x.name = w
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def termdef_cleanup(xmldoc)
|
97
|
-
termdef_unnest_cleanup(xmldoc)
|
98
|
-
Asciidoctor::Standoc::TermLookupCleanup.new(xmldoc, @log).call
|
99
|
-
term_nonverbal_designations(xmldoc)
|
100
|
-
term_dl_to_metadata(xmldoc)
|
101
|
-
term_termsource_to_designation(xmldoc)
|
102
|
-
term_designation_reorder(xmldoc)
|
103
|
-
termdef_from_termbase(xmldoc)
|
104
|
-
termdef_stem_cleanup(xmldoc)
|
105
|
-
termdomain_cleanup(xmldoc)
|
106
|
-
termdefinition_cleanup(xmldoc)
|
107
|
-
termdomain1_cleanup(xmldoc)
|
108
|
-
termnote_example_cleanup(xmldoc)
|
109
|
-
term_children_cleanup(xmldoc)
|
110
|
-
termdocsource_cleanup(xmldoc)
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
@@ -1,162 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Cleanup
|
4
|
-
def termdef_stem_cleanup(xmldoc)
|
5
|
-
xmldoc.xpath("//term/p/stem").each do |a|
|
6
|
-
if a.parent.elements.size == 1 # para contains just a stem expression
|
7
|
-
parent = a.parent
|
8
|
-
parent.replace("<admitted>#{term_expr(a.to_xml)}</admitted>")
|
9
|
-
end
|
10
|
-
end
|
11
|
-
xmldoc.xpath("//term//expression/name[stem]").each do |n|
|
12
|
-
n.parent.name = "letter-symbol"
|
13
|
-
end
|
14
|
-
end
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/cleanup_terms_designations"
|
15
3
|
|
16
|
-
# release termdef tags from surrounding paras
|
17
|
-
def termdef_unnest_cleanup(xmldoc)
|
18
|
-
desgn = "//p/admitted | //p/deprecates | //p/preferred | //p//related"
|
19
|
-
nodes = xmldoc.xpath(desgn)
|
20
|
-
while !nodes.empty?
|
21
|
-
nodes[0].parent.replace(nodes[0].parent.children)
|
22
|
-
nodes = xmldoc.xpath(desgn)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def term_dl_to_metadata(xmldoc)
|
27
|
-
xmldoc.xpath("//term[dl[@metadata = 'true']]").each do |t|
|
28
|
-
t.xpath("./dl[@metadata = 'true']").each do |dl|
|
29
|
-
prev = dl_to_designation(dl) or next
|
30
|
-
term_dl_to_designation_metadata(prev, dl)
|
31
|
-
term_dl_to_term_metadata(prev, dl)
|
32
|
-
term_dl_to_expression_metadata(prev, dl)
|
33
|
-
dl.remove
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def term_dl_to_term_metadata(prev, dlist)
|
39
|
-
return unless prev.name == "preferred" &&
|
40
|
-
prev.at("./preceding-sibling::preferred").nil?
|
41
|
-
|
42
|
-
ins = term_element_insert_point(prev)
|
43
|
-
%w(domain subject usageinfo).each do |a|
|
44
|
-
ins = dl_to_elems(ins, prev.parent, dlist, a)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def term_dl_to_designation_metadata(prev, dlist)
|
49
|
-
%w(absent geographicArea).each { |a| dl_to_attrs(related2pref(prev), dlist, a) }
|
50
|
-
end
|
51
|
-
|
52
|
-
def term_element_insert_point(prev)
|
53
|
-
ins = prev
|
54
|
-
while %w(preferred admitted deprecates related domain dl)
|
55
|
-
.include? ins&.next_element&.name
|
56
|
-
ins = ins.next_element
|
57
|
-
end
|
58
|
-
ins
|
59
|
-
end
|
60
|
-
|
61
|
-
def term_dl_to_expression_metadata(prev, dlist)
|
62
|
-
%w(language script type isInternational).each do |a|
|
63
|
-
dl_to_attrs(prev, dlist, a)
|
64
|
-
end
|
65
|
-
%w(abbreviationType pronunciation).reverse.each do |a|
|
66
|
-
dl_to_elems(prev.at("./expression/name"), prev, dlist, a)
|
67
|
-
end
|
68
|
-
g = dlist.at("./dt[text()='grammar']/following::dd//dl") and
|
69
|
-
term_dl_to_expression_grammar(prev, g)
|
70
|
-
term_to_letter_symbol(prev, dlist)
|
71
|
-
end
|
72
|
-
|
73
|
-
def term_dl_to_expression_grammar(prev, dlist)
|
74
|
-
prev.at(".//expression") or return
|
75
|
-
prev.at(".//expression") << "<grammar><sentinel/></grammar>"
|
76
|
-
%w(gender isPreposition isParticiple isAdjective isAdverb isNoun
|
77
|
-
grammarValue).reverse.each do |a|
|
78
|
-
dl_to_elems(prev.at(".//expression/grammar/*"), prev.elements.last,
|
79
|
-
dlist, a)
|
80
|
-
end
|
81
|
-
term_dl_to_designation_gender(prev)
|
82
|
-
end
|
83
|
-
|
84
|
-
def term_dl_to_designation_gender(prev)
|
85
|
-
gender = prev.at(".//expression/grammar/gender")
|
86
|
-
/,/.match?(gender&.text) and
|
87
|
-
gender.replace(gender.text.split(/,\s*/)
|
88
|
-
.map { |x| "<gender>#{x}</gender>" }.join)
|
89
|
-
prev.at(".//expression/grammar/sentinel").remove
|
90
|
-
end
|
91
|
-
|
92
|
-
def term_to_letter_symbol(prev, dlist)
|
93
|
-
ls = dlist.at("./dt[text()='letter-symbol']/following::dd/p")
|
94
|
-
return unless ls&.text == "true"
|
95
|
-
|
96
|
-
prev.at(".//expression").name = "letter-symbol"
|
97
|
-
end
|
98
|
-
|
99
|
-
def dl_to_designation(dlist)
|
100
|
-
prev = dlist.previous_element
|
101
|
-
unless %w(preferred admitted deprecates related).include? prev&.name
|
102
|
-
@log.add("AsciiDoc Input", dlist, "Metadata definition list does "\
|
103
|
-
"not follow a term designation")
|
104
|
-
return nil
|
105
|
-
end
|
106
|
-
prev
|
107
|
-
end
|
108
|
-
|
109
|
-
def term_nonverbal_designations(xmldoc)
|
110
|
-
xmldoc.xpath("//term/preferred | //term/admitted | //term/deprecates")
|
111
|
-
.each do |d|
|
112
|
-
d.text.strip.empty? or next
|
113
|
-
n = d.next_element
|
114
|
-
if %w(formula figure).include?(n&.name)
|
115
|
-
term_nonverbal_designations1(d, n)
|
116
|
-
else d.at("./expression/name") or
|
117
|
-
d.children = term_expr("")
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def term_nonverbal_designations1(desgn, elem)
|
123
|
-
desgn = related2pref(desgn)
|
124
|
-
if elem.name == "figure"
|
125
|
-
elem.at("./name").remove
|
126
|
-
desgn.children =
|
127
|
-
"<graphical-symbol>#{elem.remove.to_xml}</graphical-symbol>"
|
128
|
-
else
|
129
|
-
desgn.children = term_expr(elem.at("./stem").to_xml)
|
130
|
-
elem.remove
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def term_termsource_to_designation(xmldoc)
|
135
|
-
xmldoc.xpath("//term/termsource").each do |t|
|
136
|
-
p = t.previous_element
|
137
|
-
while %w(domain subject usageinfo).include? p&.name
|
138
|
-
p = p.previous_element
|
139
|
-
end
|
140
|
-
%w(preferred admitted deprecates related).include?(p&.name) or
|
141
|
-
next
|
142
|
-
related2pref(p) << t.remove
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
def term_designation_reorder(xmldoc)
|
147
|
-
xmldoc.xpath("//term").each do |t|
|
148
|
-
%w(preferred admitted deprecates related)
|
149
|
-
.each_with_object([]) do |tag, m|
|
150
|
-
t.xpath("./#{tag}").each { |x| m << x.remove }
|
151
|
-
end.reverse.each do |x|
|
152
|
-
t.children.first.previous = x
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def related2pref(elem)
|
158
|
-
elem.name == "related" ? elem = elem.at("./preferred") : elem
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
@@ -1,96 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Cleanup
|
4
|
-
def textcleanup(result)
|
5
|
-
text = result.flatten.map { |l| l.sub(/\s*$/, "") } * "\n"
|
6
|
-
!@keepasciimath and text = asciimath2mathml(text)
|
7
|
-
text = text.gsub(/\s+<fn /, "<fn ")
|
8
|
-
text.gsub(%r{<passthrough\s+formats="metanorma">([^<]*)
|
9
|
-
</passthrough>}mx) { HTMLEntities.new.decode($1) }
|
10
|
-
end
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/cleanup_text"
|
11
3
|
|
12
|
-
IGNORE_DUMBQUOTES =
|
13
|
-
"//pre | //pre//* | //tt | //tt//* | "\
|
14
|
-
"//sourcecode | //sourcecode//* | //bibdata//* | //stem | "\
|
15
|
-
"//stem//* | //figure[@class = 'pseudocode'] | "\
|
16
|
-
"//figure[@class = 'pseudocode']//*".freeze
|
17
|
-
|
18
|
-
def smartquotes_cleanup(xmldoc)
|
19
|
-
xmldoc.xpath("//date").each { |d| Metanorma::Utils::endash_date(d) }
|
20
|
-
if @smartquotes then smartquotes_cleanup1(xmldoc)
|
21
|
-
else dumbquote_cleanup(xmldoc)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def smartquotes_cleanup1(xmldoc)
|
26
|
-
uninterrupt_quotes_around_xml(xmldoc)
|
27
|
-
dumb2smart_quotes(xmldoc)
|
28
|
-
end
|
29
|
-
|
30
|
-
# "abc<tag/>", def => "abc",<tag/> def
|
31
|
-
=begin
|
32
|
-
def uninterrupt_quotes_around_xml(xmldoc)
|
33
|
-
xmldoc.xpath("//*[following::text()[1]"\
|
34
|
-
"[starts-with(., '\"') or starts-with(., \"'\")]]")
|
35
|
-
.each do |x|
|
36
|
-
next if !x.ancestors("pre, tt, sourcecode, stem, figure").empty?
|
37
|
-
|
38
|
-
uninterrupt_quotes_around_xml1(x)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
=end
|
42
|
-
=begin
|
43
|
-
def uninterrupt_quotes_around_xml(xmldoc)
|
44
|
-
xmldoc.traverse do |n|
|
45
|
-
next unless n.element? && n&.next&.text? &&
|
46
|
-
n.ancestors("pre, tt, sourcecode, stem, figure").empty?
|
47
|
-
next unless /^['"]/.match?(n.next.text)
|
48
|
-
|
49
|
-
uninterrupt_quotes_around_xml1(n)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
=end
|
53
|
-
def uninterrupt_quotes_around_xml(xmldoc)
|
54
|
-
xmldoc.traverse do |n|
|
55
|
-
next unless n.text? && n&.previous&.element?
|
56
|
-
next unless /^['"]/.match?(n.text)
|
57
|
-
next unless n.previous.ancestors("pre, tt, sourcecode, stem, figure")
|
58
|
-
.empty?
|
59
|
-
|
60
|
-
uninterrupt_quotes_around_xml1(n.previous)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def uninterrupt_quotes_around_xml1(elem)
|
65
|
-
prev = elem.at(".//preceding::text()[1]") or return
|
66
|
-
/\S$/.match?(prev.text) or return
|
67
|
-
foll = elem.at(".//following::text()[1]")
|
68
|
-
m = /^(["'][[:punct:]]*)(\s|$)/
|
69
|
-
.match(HTMLEntities.new.decode(foll&.text)) or return
|
70
|
-
foll.content = foll.text.sub(/^(["'][[:punct:]]*)/, "")
|
71
|
-
prev.content = "#{prev.text}#{m[1]}"
|
72
|
-
end
|
73
|
-
|
74
|
-
def dumb2smart_quotes(xmldoc)
|
75
|
-
(xmldoc.xpath("//*[child::text()]") - xmldoc.xpath(IGNORE_DUMBQUOTES))
|
76
|
-
.each do |x|
|
77
|
-
x.children.each do |n|
|
78
|
-
next unless n.text?
|
79
|
-
|
80
|
-
/[-'"(<>]|\.\.|\dx/.match(n) or next
|
81
|
-
|
82
|
-
n.replace(Metanorma::Utils::smartformat(n.text))
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def dumbquote_cleanup(xmldoc)
|
88
|
-
xmldoc.traverse do |n|
|
89
|
-
next unless n.text?
|
90
|
-
|
91
|
-
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
@@ -1,107 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Cleanup
|
4
|
-
# extending localities to cover ISO referencing
|
5
|
-
LOCALITY_REGEX_STR = <<~REGEXP.freeze
|
6
|
-
^((?<locality>section|clause|part|paragraph|chapter|page|
|
7
|
-
table|annex|figure|example|note|formula|list|time|anchor|
|
8
|
-
locality:[^ \\t\\n\\r:,;=]+)(\\s+|=)
|
9
|
-
(?<ref>[^"][^ \\t\\n,:-]*|"[^"]+")
|
10
|
-
(-(?<to>[^"][^ \\t\\n,:-]*|"[^"]"))?|
|
11
|
-
(?<locality2>whole|locality:[^ \\t\\n\\r:,;=]+))(?<punct>[,:;]?)\\s*
|
12
|
-
(?<text>.*)$
|
13
|
-
REGEXP
|
14
|
-
LOCALITY_RE = Regexp.new(LOCALITY_REGEX_STR.gsub(/\s/, ""),
|
15
|
-
Regexp::IGNORECASE | Regexp::MULTILINE)
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/cleanup_xref"
|
16
3
|
|
17
|
-
def tq(text)
|
18
|
-
text.sub(/^"/, "").sub(/"$/, "")
|
19
|
-
end
|
20
|
-
|
21
|
-
def extract_localities(elem)
|
22
|
-
f = elem&.children&.first or return
|
23
|
-
f.text? or return
|
24
|
-
head = f.remove.text
|
25
|
-
tail = elem&.children&.remove
|
26
|
-
extract_localities1(elem, head)
|
27
|
-
tail and elem << tail
|
28
|
-
end
|
29
|
-
|
30
|
-
def extract_localities1(elem, text)
|
31
|
-
b = elem.add_child("<localityStack/>").first if LOCALITY_RE.match text
|
32
|
-
while (m = LOCALITY_RE.match text)
|
33
|
-
ref = m[:ref] ? "<referenceFrom>#{tq m[:ref]}</referenceFrom>" : ""
|
34
|
-
refto = m[:to] ? "<referenceTo>#{tq m[:to]}</referenceTo>" : ""
|
35
|
-
b.add_child("<locality type='#{locality_label(m)}'>#{ref}#{refto}"\
|
36
|
-
"</locality>")
|
37
|
-
text = m[:text]
|
38
|
-
b = elem.add_child("<localityStack/>").first if m[:punct] == ";"
|
39
|
-
end
|
40
|
-
elem.add_child(text) if text
|
41
|
-
end
|
42
|
-
|
43
|
-
def locality_label(match)
|
44
|
-
loc = match[:locality] || match[:locality2]
|
45
|
-
/^locality:/.match?(loc) ? loc : loc&.downcase
|
46
|
-
end
|
47
|
-
|
48
|
-
def xref_to_eref(elem)
|
49
|
-
elem["bibitemid"] = elem["target"]
|
50
|
-
unless elem["citeas"] = @anchors&.dig(elem["target"], :xref)
|
51
|
-
@internal_eref_namespaces.include?(elem["type"]) or
|
52
|
-
@log.add("Crossreferences", elem,
|
53
|
-
"#{elem['target']} does not have a corresponding "\
|
54
|
-
"anchor ID in the bibliography!")
|
55
|
-
end
|
56
|
-
elem.delete("target")
|
57
|
-
extract_localities(elem) unless elem.children.empty?
|
58
|
-
end
|
59
|
-
|
60
|
-
def xref_cleanup(xmldoc)
|
61
|
-
xmldoc.xpath("//xref").each do |x|
|
62
|
-
/:/.match(x["target"]) and xref_to_internal_eref(x)
|
63
|
-
next unless x.name == "xref"
|
64
|
-
|
65
|
-
if refid? x["target"]
|
66
|
-
x.name = "eref"
|
67
|
-
xref_to_eref(x)
|
68
|
-
else x.delete("type")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def xref_to_internal_eref(elem)
|
74
|
-
a = elem["target"].split(":", 3)
|
75
|
-
unless a.size < 2 || a[0].empty? || a[1].empty?
|
76
|
-
elem["target"] = "#{a[0]}_#{a[1]}"
|
77
|
-
a.size > 2 and
|
78
|
-
elem.children = %{anchor="#{a[2..-1].join}",#{elem&.children&.text}}
|
79
|
-
elem["type"] = a[0]
|
80
|
-
@internal_eref_namespaces << a[0]
|
81
|
-
elem.name = "eref"
|
82
|
-
xref_to_eref(elem)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def quotesource_cleanup(xmldoc)
|
87
|
-
xmldoc.xpath("//quote/source | //terms/source").each do |x|
|
88
|
-
xref_to_eref(x)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def origin_cleanup(xmldoc)
|
93
|
-
xmldoc.xpath("//origin/concept[termref]").each do |x|
|
94
|
-
t = x.at("./termref")
|
95
|
-
x.replace(t)
|
96
|
-
end
|
97
|
-
xmldoc.xpath("//origin").each do |x|
|
98
|
-
x["citeas"] = @anchors&.dig(x["bibitemid"], :xref) or
|
99
|
-
@log.add("Crossreferences", x,
|
100
|
-
"#{x['bibitemid']} does not have a corresponding anchor "\
|
101
|
-
"ID in the bibliography!")
|
102
|
-
extract_localities(x) unless x.children.empty?
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|