metanorma-standoc 3.3.0 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/isodoc/html/htmlstyle.css +7 -2
- data/lib/isodoc/html/htmlstyle.scss +1 -1
- data/lib/isodoc/{pdf_convert.rb → standoc/pdf_convert.rb} +1 -1
- data/lib/metanorma/{standoc/cleanup_amend.rb → cleanup/amend.rb} +2 -2
- data/lib/metanorma/{standoc/cleanup_asciibib.rb → cleanup/asciibib.rb} +1 -1
- data/lib/metanorma/{standoc/cleanup_attachment.rb → cleanup/attachment.rb} +1 -1
- data/lib/metanorma/{standoc/cleanup_bibdata.rb → cleanup/bibdata.rb} +4 -2
- data/lib/metanorma/{standoc/cleanup_bibitem.rb → cleanup/bibitem.rb} +11 -9
- data/lib/metanorma/{standoc/cleanup_block.rb → cleanup/block.rb} +3 -3
- data/lib/metanorma/{standoc/cleanup_boilerplate.rb → cleanup/boilerplate.rb} +8 -11
- data/lib/metanorma/{standoc/cleanup_boilerplate_liquid.rb → cleanup/boilerplate_liquid.rb} +1 -1
- data/lib/metanorma/{standoc → cleanup}/cleanup.rb +130 -105
- data/lib/metanorma/{standoc/cleanup_dochistory.rb → cleanup/dochistory.rb} +2 -2
- data/lib/metanorma/{standoc/cleanup_footnotes.rb → cleanup/footnotes.rb} +1 -1
- data/lib/metanorma/{standoc/cleanup_image.rb → cleanup/image.rb} +70 -13
- data/lib/metanorma/{standoc/cleanup_index.rb → cleanup/index.rb} +1 -1
- data/lib/metanorma/{standoc/cleanup_inline.rb → cleanup/inline.rb} +1 -1
- data/lib/metanorma/cleanup/log.rb +41 -0
- data/lib/metanorma/{standoc/cleanup_maths.rb → cleanup/maths.rb} +2 -2
- data/lib/metanorma/{standoc/cleanup_mathvariant.rb → cleanup/mathvariant.rb} +1 -1
- data/lib/metanorma/{standoc → cleanup}/merge_bibitems.rb +1 -1
- data/lib/metanorma/cleanup/metadata.rb +54 -0
- data/lib/metanorma/{standoc/cleanup_ref.rb → cleanup/ref.rb} +5 -4
- data/lib/metanorma/{standoc/cleanup_reqt.rb → cleanup/reqt.rb} +2 -2
- data/lib/metanorma/{standoc/cleanup_review.rb → cleanup/review.rb} +1 -1
- data/lib/metanorma/{standoc/cleanup_section.rb → cleanup/section.rb} +2 -2
- data/lib/metanorma/{standoc/cleanup_section_names.rb → cleanup/section_names.rb} +1 -1
- data/lib/metanorma/{standoc → cleanup}/spans_to_bibitem.rb +1 -1
- data/lib/metanorma/{standoc → cleanup}/spans_to_bibitem_preprocessing.rb +1 -1
- data/lib/metanorma/{standoc/cleanup_symbols.rb → cleanup/symbols.rb} +2 -2
- data/lib/metanorma/{standoc/cleanup_table.rb → cleanup/table.rb} +1 -1
- data/lib/metanorma/{standoc/term_lookup_cleanup.rb → cleanup/term_lookup.rb} +1 -1
- data/lib/metanorma/{standoc/cleanup_terms.rb → cleanup/terms.rb} +3 -3
- data/lib/metanorma/{standoc/cleanup_terms_boilerplate.rb → cleanup/terms_boilerplate.rb} +1 -6
- data/lib/metanorma/{standoc/cleanup_terms_designations.rb → cleanup/terms_designations.rb} +1 -1
- data/lib/metanorma/{standoc/cleanup_text.rb → cleanup/text.rb} +33 -23
- data/lib/metanorma/{standoc/cleanup_toc.rb → cleanup/toc.rb} +10 -8
- data/lib/metanorma/{standoc/cleanup_xref.rb → cleanup/xref.rb} +2 -2
- data/lib/metanorma/{standoc/cleanup_xref_localities.rb → cleanup/xref_localities.rb} +1 -1
- data/lib/metanorma/{standoc → converter}/base.rb +38 -17
- data/lib/metanorma/{standoc → converter}/blocks.rb +4 -2
- data/lib/metanorma/{standoc → converter}/blocks_image.rb +12 -0
- data/lib/metanorma/{standoc/blocks_notes_examples.rb → converter/blocks_notes.rb} +0 -60
- data/lib/metanorma/{standoc → converter}/converter.rb +11 -4
- data/lib/metanorma/converter/date_utils.rb +52 -0
- data/lib/metanorma/{standoc → converter}/front.rb +1 -0
- data/lib/metanorma/{standoc → converter}/init.rb +35 -11
- data/lib/metanorma/{standoc → converter}/inline.rb +15 -11
- data/lib/metanorma/{standoc → converter}/isolated_converter.rb +1 -1
- data/lib/metanorma/{standoc → converter}/ref.rb +1 -1
- data/lib/metanorma/{standoc → converter}/ref_queue.rb +6 -0
- data/lib/metanorma/{standoc → converter}/section.rb +1 -0
- data/lib/metanorma/{standoc → converter}/utils.rb +8 -15
- data/lib/metanorma/{standoc → converter}/version.rb +1 -1
- data/lib/metanorma/standoc.rb +1 -1
- data/lib/metanorma/{standoc → validate}/basicdoc.rng +5 -1
- data/lib/metanorma/{standoc → validate}/biblio.rng +4 -4
- data/lib/metanorma/validate/image.rb +190 -0
- data/lib/metanorma/{standoc → validate}/isodoc.rng +77 -28
- data/lib/metanorma/validate/schema.rb +149 -0
- data/lib/metanorma/validate/section.rb +81 -0
- data/lib/metanorma/validate/table.rb +97 -0
- data/lib/metanorma/validate/term.rb +137 -0
- data/lib/metanorma/{standoc → validate}/validate.rb +60 -16
- data/lib/metanorma-standoc.rb +3 -3
- data/lib/nokogiri/xml/builder.rb +16 -0
- data/metanorma-standoc.gemspec +1 -1
- metadata +95 -136
- data/lib/asciidoctor/standoc/base.rb +0 -2
- data/lib/asciidoctor/standoc/blocks.rb +0 -2
- data/lib/asciidoctor/standoc/blocks_notes.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_amend.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_block.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_boilerplate.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_footnotes.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_image.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_inline.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_maths.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_ref.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_ref_dl.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_reqt.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_section.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_symbols.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_table.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_terms.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_terms_designations.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_text.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_toc.rb +0 -2
- data/lib/asciidoctor/standoc/cleanup_xref.rb +0 -2
- data/lib/asciidoctor/standoc/converter.rb +0 -2
- data/lib/asciidoctor/standoc/deprecated.rb +0 -7
- data/lib/asciidoctor/standoc/front.rb +0 -2
- data/lib/asciidoctor/standoc/front_contributor.rb +0 -2
- data/lib/asciidoctor/standoc/inline.rb +0 -2
- data/lib/asciidoctor/standoc/lists.rb +0 -2
- data/lib/asciidoctor/standoc/macros.rb +0 -2
- data/lib/asciidoctor/standoc/macros_form.rb +0 -2
- data/lib/asciidoctor/standoc/macros_note.rb +0 -2
- data/lib/asciidoctor/standoc/macros_terms.rb +0 -2
- data/lib/asciidoctor/standoc/ref.rb +0 -2
- data/lib/asciidoctor/standoc/ref_sect.rb +0 -2
- data/lib/asciidoctor/standoc/ref_utility.rb +0 -2
- data/lib/asciidoctor/standoc/render.rb +0 -2
- data/lib/asciidoctor/standoc/reqt.rb +0 -2
- data/lib/asciidoctor/standoc/section.rb +0 -2
- data/lib/asciidoctor/standoc/table.rb +0 -2
- data/lib/asciidoctor/standoc/term_lookup_cleanup.rb +0 -2
- data/lib/asciidoctor/standoc/terms.rb +0 -2
- data/lib/asciidoctor/standoc/utils.rb +0 -2
- data/lib/asciidoctor/standoc/validate.rb +0 -2
- data/lib/asciidoctor/standoc/validate_section.rb +0 -2
- data/lib/metanorma/standoc/validate_image.rb +0 -182
- data/lib/metanorma/standoc/validate_schema.rb +0 -144
- data/lib/metanorma/standoc/validate_section.rb +0 -79
- data/lib/metanorma/standoc/validate_table.rb +0 -95
- data/lib/metanorma/standoc/validate_term.rb +0 -135
- /data/lib/metanorma/{standoc → converter}/anchor.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/blocks_examples.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/front_committee.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/front_contributor.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/front_ext.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/front_organisation.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/front_title.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/lists.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/localbib.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/log.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/macros.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/macros_embed.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/macros_form.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/macros_inline.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/macros_link.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/macros_nosub.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/macros_note.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/macros_number.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/macros_terms.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/processor.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/ref_sect.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/ref_utility.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/regex.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/render.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/reqt.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/sectiontype.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/table.rb +0 -0
- /data/lib/metanorma/{standoc → converter}/terms.rb +0 -0
- /data/lib/metanorma/{standoc → validate}/biblio-standoc.rng +0 -0
- /data/lib/metanorma/{standoc → validate}/isodoc-compile.rng +0 -0
- /data/lib/metanorma/{standoc → validate}/reqt.rng +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a7f6a1a5d54bb2ad0e64f98ebe39c519bea34a6252781a294bacae9342072c13
|
|
4
|
+
data.tar.gz: a3f32b49f251c6555799c53dcc1d00b08edaf5500a267bd9e459faff33d364c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58d985cce5eb147eb952d9494e1a64207d95a35f054f9aec84378562bb6bdedfd0073306df23ee9214631c6ba73201cd4e98a3abcea8fd56d968235724885202
|
|
7
|
+
data.tar.gz: 87a87b2e41d1e763c8bdff7254a64d6c2bd7710b33c6f81909313bd889feba22c932ddc70c725fa0bc40434a404872ffdc80884c1cd9d6f16da4f42828c2fd39
|
|
@@ -319,6 +319,11 @@ svg {
|
|
|
319
319
|
display: block; /* ← removes unwanted inline spacing */
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
+
/* style dfn by override in flavor */
|
|
323
|
+
dfn {
|
|
324
|
+
font-style: inherit;
|
|
325
|
+
}
|
|
326
|
+
|
|
322
327
|
#standard-band {
|
|
323
328
|
background-color: #0AC442;
|
|
324
329
|
}
|
|
@@ -624,7 +629,7 @@ body pre * {
|
|
|
624
629
|
}
|
|
625
630
|
}
|
|
626
631
|
|
|
627
|
-
div.figure
|
|
632
|
+
div.figure figcaption {
|
|
628
633
|
font-weight: 700;
|
|
629
634
|
font-size: 1em;
|
|
630
635
|
text-align: center;
|
|
@@ -1071,7 +1076,7 @@ table table.plain, table table.plain th, table table.plain td {
|
|
|
1071
1076
|
font-size: 0.95em;
|
|
1072
1077
|
}
|
|
1073
1078
|
|
|
1074
|
-
|
|
1079
|
+
table > caption {
|
|
1075
1080
|
text-align: center;
|
|
1076
1081
|
margin-top: 2.5em;
|
|
1077
1082
|
font-weight: 400;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Metanorma
|
|
2
2
|
module Standoc
|
|
3
|
-
module
|
|
3
|
+
module Amend
|
|
4
4
|
def change_clauses(docxml)
|
|
5
5
|
docxml.xpath("//clause[@change]").each do |c|
|
|
6
6
|
create_amend(c)
|
|
@@ -58,7 +58,7 @@ module Metanorma
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def move_attrs_to_amend(clause, amend)
|
|
61
|
-
%w(change path path_end title).each do |e|
|
|
61
|
+
%w(change path path_end title position).each do |e|
|
|
62
62
|
clause[e] or next
|
|
63
63
|
amend[e] = clause[e]
|
|
64
64
|
clause.delete(e)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Metanorma
|
|
2
2
|
module Standoc
|
|
3
|
-
module
|
|
3
|
+
module Bibdata
|
|
4
4
|
def bibdata_cleanup(xmldoc)
|
|
5
5
|
bibdata_anchor_cleanup(xmldoc)
|
|
6
6
|
bibdata_docidentifier_cleanup(xmldoc)
|
|
@@ -120,7 +120,7 @@ module Metanorma
|
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
def hdr2bibitem(hdr)
|
|
123
|
-
xml = isolated_asciidoctor_convert(hdr[:text],
|
|
123
|
+
xml = @conv.isolated_asciidoctor_convert(hdr[:text],
|
|
124
124
|
backend: hdr2bibitem_type(hdr),
|
|
125
125
|
header_footer: true)
|
|
126
126
|
b = Nokogiri::XML(xml).at("//xmlns:bibdata")
|
|
@@ -222,6 +222,8 @@ module Metanorma
|
|
|
222
222
|
p.nil? || p.text.strip.empty? and c.remove
|
|
223
223
|
end
|
|
224
224
|
end
|
|
225
|
+
|
|
226
|
+
def docidentifier_cleanup(xmldoc); end
|
|
225
227
|
end
|
|
226
228
|
end
|
|
227
229
|
end
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
require_relative "
|
|
1
|
+
require_relative "attachment"
|
|
2
2
|
|
|
3
3
|
module Metanorma
|
|
4
4
|
module Standoc
|
|
5
|
-
module
|
|
5
|
+
module Bibitem
|
|
6
|
+
include Attachment
|
|
7
|
+
|
|
6
8
|
def formattedref_spans(xmldoc)
|
|
7
9
|
xmldoc.xpath("//bibitem[formattedref//span]").each do |b|
|
|
8
10
|
ret = new_bibitem_from_formattedref_spans(b)
|
|
@@ -14,7 +16,7 @@ module Metanorma
|
|
|
14
16
|
end
|
|
15
17
|
|
|
16
18
|
def new_bibitem_from_formattedref_spans(bib)
|
|
17
|
-
ret = SpansToBibitem.new(bib).convert
|
|
19
|
+
ret = Metanorma::Standoc::Cleanup::SpansToBibitem.new(bib).convert
|
|
18
20
|
ret.err.each do |e|
|
|
19
21
|
@log.add(e[:fatal] ? "STANDOC_52" : "STANDOC_53",
|
|
20
22
|
bib, params: [e[:msg]])
|
|
@@ -26,7 +28,7 @@ module Metanorma
|
|
|
26
28
|
merge_bibitem_from_formattedref_span_attrs(bib, new)
|
|
27
29
|
if bib.at("./title") && bib["amend"]
|
|
28
30
|
# there already is a fetched record here: merge
|
|
29
|
-
bib.children = MergeBibitems
|
|
31
|
+
bib.children = Metanorma::Standoc::Cleanup::MergeBibitems
|
|
30
32
|
.new(bib.to_xml, new.to_xml).merge.to_noko.children
|
|
31
33
|
elsif bib.at("./title") # replace record
|
|
32
34
|
bib.children = new.children.to_xml
|
|
@@ -135,11 +137,11 @@ module Metanorma
|
|
|
135
137
|
def fetch_local_bibitem(xmldoc)
|
|
136
138
|
xmldoc.xpath("//bibitem[formattedref][uri[@type = 'citation']]")
|
|
137
139
|
.each do |b|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
uri = b&.at("./uri[@type = 'citation']")&.text
|
|
141
|
+
bibitem = read_local_bibitem(uri) or next
|
|
142
|
+
bibitem["id"] = b["id"]
|
|
143
|
+
bibitem["anchor"] = b["anchor"]
|
|
144
|
+
b.replace(bibitem)
|
|
143
145
|
end
|
|
144
146
|
end
|
|
145
147
|
|
|
@@ -3,7 +3,7 @@ require "htmlentities"
|
|
|
3
3
|
|
|
4
4
|
module Metanorma
|
|
5
5
|
module Standoc
|
|
6
|
-
module
|
|
6
|
+
module Block
|
|
7
7
|
def para_cleanup(xmldoc)
|
|
8
8
|
["//p[not(ancestor::bibdata)]", "//ol[not(ancestor::bibdata)]",
|
|
9
9
|
"//ul[not(ancestor::bibdata)]", "//quote[not(ancestor::bibdata)]",
|
|
@@ -187,9 +187,9 @@ module Metanorma
|
|
|
187
187
|
source_markup_prep(node).each_slice(4).map.with_object([]) do |a, acc|
|
|
188
188
|
acc << safe_noko(a[0], node.document)
|
|
189
189
|
a.size == 4 or next
|
|
190
|
-
acc << isolated_asciidoctor_convert(
|
|
190
|
+
acc << @conv.isolated_asciidoctor_convert(
|
|
191
191
|
"{blank} #{a[2]}", doctype: :inline,
|
|
192
|
-
backend: backend&.to_sym || :standoc
|
|
192
|
+
backend: @conv.backend&.to_sym || :standoc
|
|
193
193
|
).strip
|
|
194
194
|
end.join
|
|
195
195
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
require_relative "
|
|
2
|
-
require_relative "
|
|
1
|
+
require_relative "terms_boilerplate"
|
|
2
|
+
require_relative "boilerplate_liquid"
|
|
3
3
|
|
|
4
4
|
module Metanorma
|
|
5
5
|
module Standoc
|
|
6
|
-
module
|
|
6
|
+
module Boilerplate
|
|
7
7
|
def norm_ref_preface(ref, isodoc)
|
|
8
8
|
ins = norm_ref_boilerplate_insert_location(ref)
|
|
9
9
|
ins2 = norm_ref_process_boilerplate_note(ref)
|
|
@@ -37,13 +37,9 @@ module Metanorma
|
|
|
37
37
|
ref.at("./title")
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
NORM_REF =
|
|
41
|
-
"//bibliography/references[@normative = 'true'][not(@hidden)] | " \
|
|
42
|
-
"//bibliography/clause[.//references[@normative = 'true']]".freeze
|
|
43
|
-
|
|
44
40
|
def dup_with_namespace(elem)
|
|
45
41
|
ret = elem.dup
|
|
46
|
-
ret.add_namespace(nil, xml_namespace)
|
|
42
|
+
ret.add_namespace(nil, @conv.xml_namespace)
|
|
47
43
|
ret
|
|
48
44
|
end
|
|
49
45
|
|
|
@@ -52,7 +48,8 @@ module Metanorma
|
|
|
52
48
|
# in termdef_boilerplate_insert and initial_boilerplate
|
|
53
49
|
xmldoc.at("//metanorma-extension/semantic-metadata/" \
|
|
54
50
|
"headless[text() = 'true']") and return nil
|
|
55
|
-
@isodoc ||= isodoc(@lang, @script, @locale)
|
|
51
|
+
@isodoc ||= @conv.isodoc(@lang, @script, @locale)
|
|
52
|
+
@i18n = @isodoc.i18n
|
|
56
53
|
isodoc_bibdata_parse(xmldoc)
|
|
57
54
|
@isodoc
|
|
58
55
|
end
|
|
@@ -189,7 +186,7 @@ module Metanorma
|
|
|
189
186
|
end
|
|
190
187
|
|
|
191
188
|
def boilerplate_file_restructure(file)
|
|
192
|
-
ret = adoc2xml(file, backend.to_sym)
|
|
189
|
+
ret = adoc2xml(file, @conv.backend.to_sym)
|
|
193
190
|
boilerplate_xml_cleanup(ret)
|
|
194
191
|
ret.name = "boilerplate"
|
|
195
192
|
boilerplate_top_elements(ret)
|
|
@@ -198,7 +195,7 @@ module Metanorma
|
|
|
198
195
|
|
|
199
196
|
def boilerplate_snippet_convert(adoc, isodoc)
|
|
200
197
|
b = isodoc.populate_template(adoc, nil)
|
|
201
|
-
ret = boilerplate_xml_cleanup(adoc2xml(b, backend.to_sym))
|
|
198
|
+
ret = boilerplate_xml_cleanup(adoc2xml(b, @conv.backend.to_sym))
|
|
202
199
|
@i18n.l10n(ret.children.to_xml, @lang, @script).strip
|
|
203
200
|
end
|
|
204
201
|
|
|
@@ -1,32 +1,139 @@
|
|
|
1
1
|
require "nokogiri"
|
|
2
2
|
require "pathname"
|
|
3
3
|
require "html2doc"
|
|
4
|
-
require_relative "cleanup_block"
|
|
5
|
-
require_relative "cleanup_table"
|
|
6
|
-
require_relative "cleanup_footnotes"
|
|
7
|
-
require_relative "cleanup_ref"
|
|
8
|
-
require_relative "cleanup_asciibib"
|
|
9
|
-
require_relative "cleanup_boilerplate"
|
|
10
|
-
require_relative "cleanup_bibdata"
|
|
11
|
-
require_relative "cleanup_section"
|
|
12
|
-
require_relative "cleanup_index"
|
|
13
|
-
require_relative "cleanup_terms"
|
|
14
|
-
require_relative "cleanup_symbols"
|
|
15
|
-
require_relative "cleanup_xref"
|
|
16
|
-
require_relative "cleanup_inline"
|
|
17
|
-
require_relative "cleanup_amend"
|
|
18
|
-
require_relative "cleanup_maths"
|
|
19
|
-
require_relative "cleanup_image"
|
|
20
|
-
require_relative "cleanup_reqt"
|
|
21
|
-
require_relative "cleanup_text"
|
|
22
|
-
require_relative "cleanup_toc"
|
|
23
|
-
require_relative "cleanup_review"
|
|
24
|
-
require_relative "cleanup_dochistory"
|
|
25
4
|
require "relaton_iev"
|
|
5
|
+
require "forwardable"
|
|
6
|
+
require_relative "attachment"
|
|
7
|
+
require_relative "block"
|
|
8
|
+
require_relative "table"
|
|
9
|
+
require_relative "footnotes"
|
|
10
|
+
require_relative "ref"
|
|
11
|
+
require_relative "asciibib"
|
|
12
|
+
require_relative "boilerplate"
|
|
13
|
+
require_relative "bibdata"
|
|
14
|
+
require_relative "bibitem"
|
|
15
|
+
require_relative "section"
|
|
16
|
+
require_relative "section_names"
|
|
17
|
+
require_relative "index"
|
|
18
|
+
require_relative "terms"
|
|
19
|
+
require_relative "symbols"
|
|
20
|
+
require_relative "xref"
|
|
21
|
+
require_relative "inline"
|
|
22
|
+
require_relative "amend"
|
|
23
|
+
require_relative "maths"
|
|
24
|
+
require_relative "metadata"
|
|
25
|
+
require_relative "image"
|
|
26
|
+
require_relative "reqt"
|
|
27
|
+
require_relative "text"
|
|
28
|
+
require_relative "toc"
|
|
29
|
+
require_relative "review"
|
|
30
|
+
require_relative "dochistory"
|
|
31
|
+
require_relative "terms_designations"
|
|
32
|
+
require_relative "merge_bibitems"
|
|
33
|
+
require_relative "spans_to_bibitem"
|
|
34
|
+
require_relative "spans_to_bibitem_preprocessing"
|
|
35
|
+
require_relative "log"
|
|
26
36
|
|
|
27
37
|
module Metanorma
|
|
28
38
|
module Standoc
|
|
29
|
-
|
|
39
|
+
class Cleanup
|
|
40
|
+
extend Forwardable
|
|
41
|
+
|
|
42
|
+
attr_reader :log, :files_to_delete
|
|
43
|
+
|
|
44
|
+
# XPath expressions for boilerplate insertion
|
|
45
|
+
NORM_REF =
|
|
46
|
+
"//bibliography/references[@normative = 'true'][not(@hidden)] | " \
|
|
47
|
+
"//bibliography/clause[.//references[@normative = 'true']]".freeze
|
|
48
|
+
|
|
49
|
+
TERM_CLAUSE =
|
|
50
|
+
"//sections//terms[not(.//ancestor::clause[@type = 'terms'])] | " \
|
|
51
|
+
"//sections/clause[descendant::terms][@type = 'terms'] | " \
|
|
52
|
+
"//sections/clause[not(@type = 'terms')]//terms".freeze
|
|
53
|
+
|
|
54
|
+
# Use metaprogramming to copy instance variables from converter
|
|
55
|
+
def copied_instance_variables
|
|
56
|
+
%i[
|
|
57
|
+
datauriattachment datauriimage local_log isodoc anchors localdir c
|
|
58
|
+
refids sourcecode_markup_start sourcecode_markup_end smartquotes
|
|
59
|
+
toclevels htmltoclevels doctoclevels pdftoclevels stage_published
|
|
60
|
+
numberfmt_default svg_conform_profile dataurimaxsize index_terms
|
|
61
|
+
boilerplateauthority embed_hdr embed_id erefstyle originstyle
|
|
62
|
+
xrefstyle blockunnumbered keepasciimath numberfmt_formula
|
|
63
|
+
numberfmt_prof sort_biblio reqt_models default_requirement_model
|
|
64
|
+
document_scheme
|
|
65
|
+
]
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def initialize(converter)
|
|
69
|
+
@conv= converter
|
|
70
|
+
@anchor_alias = {}
|
|
71
|
+
@internal_eref_namespaces = []
|
|
72
|
+
|
|
73
|
+
# Shadow instance variables from converter (attributes/accessors)
|
|
74
|
+
@log = converter.log
|
|
75
|
+
@bibdb = converter.bibdb
|
|
76
|
+
@lang = converter.lang
|
|
77
|
+
@script = converter.script
|
|
78
|
+
@libdir = converter.libdir
|
|
79
|
+
@locale = converter.locale
|
|
80
|
+
@novalid = converter.novalid
|
|
81
|
+
@output_dir = converter.output_dir
|
|
82
|
+
@filename = converter.filename
|
|
83
|
+
@files_to_delete = converter.files_to_delete
|
|
84
|
+
|
|
85
|
+
copied_instance_variables.each do |var|
|
|
86
|
+
instance_variable_set("@#{var}",
|
|
87
|
+
converter.instance_variable_get("@#{var}"))
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Special handling for derived values
|
|
91
|
+
@i18n = @isodoc&.i18n
|
|
92
|
+
|
|
93
|
+
# Reuse converter's relaton_log instead of creating a new one
|
|
94
|
+
@relaton_log = converter.relaton_log
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def to_xml(xml)
|
|
98
|
+
@conv.to_xml(xml)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
class << self
|
|
102
|
+
attr_accessor :_file
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.inherited(konv) # rubocop:disable Lint/MissingSuper
|
|
106
|
+
konv._file = caller_locations(1..1).first.absolute_path
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Include all cleanup modules
|
|
110
|
+
include Attachment
|
|
111
|
+
include Block
|
|
112
|
+
include Table
|
|
113
|
+
include Footnotes
|
|
114
|
+
include Ref
|
|
115
|
+
include Asciibib
|
|
116
|
+
include Boilerplate
|
|
117
|
+
include Bibdata
|
|
118
|
+
include Bibitem
|
|
119
|
+
include Section
|
|
120
|
+
include SectionNames
|
|
121
|
+
include Index
|
|
122
|
+
include Terms
|
|
123
|
+
include Symbols
|
|
124
|
+
include Xref
|
|
125
|
+
include Inline
|
|
126
|
+
include Amend
|
|
127
|
+
include Maths
|
|
128
|
+
include Image
|
|
129
|
+
include Reqt
|
|
130
|
+
include Text
|
|
131
|
+
include Toc
|
|
132
|
+
include Review
|
|
133
|
+
include Dochistory
|
|
134
|
+
include TermsDesignations
|
|
135
|
+
include Metadata
|
|
136
|
+
|
|
30
137
|
def cleanup(xmldoc)
|
|
31
138
|
@doctype = xmldoc.at("//bibdata/ext/doctype")&.text
|
|
32
139
|
element_name_cleanup(xmldoc)
|
|
@@ -58,7 +165,7 @@ module Metanorma
|
|
|
58
165
|
clausebefore_cleanup(xmldoc) # feeeds: floatingtitle_cleanup
|
|
59
166
|
floatingtitle_cleanup(xmldoc)
|
|
60
167
|
bibitem_cleanup(xmldoc) # feeds: normref_cleanup, biblio_cleanup,
|
|
61
|
-
# reference_names, bpart_cleanup
|
|
168
|
+
# reference_names, bpart_cleanup, attachment_cleanup
|
|
62
169
|
normref_cleanup(xmldoc)
|
|
63
170
|
biblio_cleanup(xmldoc)
|
|
64
171
|
reference_names(xmldoc)
|
|
@@ -108,46 +215,6 @@ module Metanorma
|
|
|
108
215
|
xmldoc
|
|
109
216
|
end
|
|
110
217
|
|
|
111
|
-
def relaton_iev_cleanup(xmldoc)
|
|
112
|
-
_, err = RelatonIev::iev_cleanup(xmldoc, @bibdb)
|
|
113
|
-
err.each do |e|
|
|
114
|
-
@log.add("RELATON_5", nil, params: e)
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
RELATON_SEVERITIES =
|
|
119
|
-
{ "INFO": "RELATON_4", "WARN": "RELATON_3", "ERROR": "RELATON_2",
|
|
120
|
-
"FATAL": "RELATON_1", "UNKNOWN": "RELATON_4" }.freeze
|
|
121
|
-
|
|
122
|
-
def relaton_log_cleanup(_xmldoc)
|
|
123
|
-
@relaton_log or return
|
|
124
|
-
@relaton_log.rewind
|
|
125
|
-
@relaton_log.string.split(/(?<=})\n(?={)/).each do |l|
|
|
126
|
-
e = JSON.parse(l)
|
|
127
|
-
relaton_log_add?(e) and
|
|
128
|
-
@log.add(RELATON_SEVERITIES[e["severity"].to_sym], e["key"],
|
|
129
|
-
params: [e["message"]])
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def relaton_log_add?(entry)
|
|
134
|
-
entry["message"].include?("Fetching from") and return false
|
|
135
|
-
entry["message"].include?("Downloaded index from") and return false
|
|
136
|
-
entry["message"].start_with?("Found:") or return true
|
|
137
|
-
id = /^Found: `(.+)`$/.match(entry["message"]) or return true
|
|
138
|
-
#entry["key"].end_with?(id[1]) and return false
|
|
139
|
-
#true
|
|
140
|
-
!relaton_key_eqv?(entry["key"], id[1])
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
def relaton_key_eqv?(sought, found)
|
|
144
|
-
sought = sought.sub(" (all parts)", "").sub(/:(19|20)\d\d$/, "")
|
|
145
|
-
found = found.sub(" (all parts)", "").sub(/:(19|20)\d\d$/, "")
|
|
146
|
-
sought.end_with?(found)
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def docidentifier_cleanup(xmldoc); end
|
|
150
|
-
|
|
151
218
|
TEXT_ELEMS =
|
|
152
219
|
%w{status language script version author name callout phone email
|
|
153
220
|
street city state country postcode identifier referenceFrom surname
|
|
@@ -172,48 +239,6 @@ module Metanorma
|
|
|
172
239
|
def element_name_cleanup(xmldoc)
|
|
173
240
|
xmldoc.traverse { |n| n.name = n.name.tr("_", "-") }
|
|
174
241
|
end
|
|
175
|
-
|
|
176
|
-
def metadata_cleanup(xmldoc)
|
|
177
|
-
bibdata_published(xmldoc) # feeds: bibdata_cleanup,
|
|
178
|
-
# docidentifier_cleanup (in generic: template)
|
|
179
|
-
(@metadata_attrs.nil? || @metadata_attrs.empty?) and return
|
|
180
|
-
ins = add_misc_container(xmldoc)
|
|
181
|
-
ins << @metadata_attrs
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
def pres_metadata_cleanup(xmldoc)
|
|
185
|
-
@isodoc ||= isodoc(@lang, @script, @locale)
|
|
186
|
-
isodoc_bibdata_parse(xmldoc)
|
|
187
|
-
xmldoc.xpath("//presentation-metadata/* | //semantic-metadata/*")
|
|
188
|
-
.each do |x|
|
|
189
|
-
/\{\{|\{%/.match?(x) or next
|
|
190
|
-
x.children = @isodoc.populate_template(to_xml(x.children), nil)
|
|
191
|
-
end
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
def metadata_cleanup_final(xmldoc)
|
|
195
|
-
root = nil
|
|
196
|
-
%w(semantic presentation).each do |k|
|
|
197
|
-
xmldoc.xpath("//#{k}-metadata").each_with_index do |x, i|
|
|
198
|
-
if i.zero? then root = x
|
|
199
|
-
else
|
|
200
|
-
root << x.remove.elements
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
end
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
def annotation_cleanup(xmldoc)
|
|
207
|
-
ret = xmldoc.xpath("//annotation[@type = 'ignore-log']")
|
|
208
|
-
.each_with_object([]) do |ann, m|
|
|
209
|
-
error_ids = Array(csv_split(ann.text || "", ","))
|
|
210
|
-
m << { from: ann["from"], to: ann["to"], error_ids: error_ids }
|
|
211
|
-
ann
|
|
212
|
-
end
|
|
213
|
-
config = @log.suppress_log
|
|
214
|
-
config[:locations] += ret
|
|
215
|
-
@log.suppress_log = config
|
|
216
|
-
end
|
|
217
242
|
end
|
|
218
243
|
end
|
|
219
244
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module Metanorma
|
|
2
2
|
module Standoc
|
|
3
|
-
module
|
|
3
|
+
module Dochistory
|
|
4
4
|
def bib_relation_insert_pt(xmldoc)
|
|
5
5
|
ins = nil
|
|
6
6
|
%w(relation copyright status abstract script language note version
|
|
@@ -81,7 +81,7 @@ module Metanorma
|
|
|
81
81
|
|
|
82
82
|
def amend_description(yaml)
|
|
83
83
|
a = yaml["description"] or return ""
|
|
84
|
-
out = adoc2xml(a, backend.to_sym)
|
|
84
|
+
out = adoc2xml(a, @conv.backend.to_sym)
|
|
85
85
|
"<description>#{out.children.to_xml}</description>"
|
|
86
86
|
end
|
|
87
87
|
|
|
@@ -3,7 +3,7 @@ require "crass"
|
|
|
3
3
|
|
|
4
4
|
module Metanorma
|
|
5
5
|
module Standoc
|
|
6
|
-
module
|
|
6
|
+
module Image
|
|
7
7
|
def svgmap_cleanup(xmldoc)
|
|
8
8
|
svgmap_moveattrs(xmldoc)
|
|
9
9
|
svgmap_populate(xmldoc)
|
|
@@ -55,31 +55,88 @@ module Metanorma
|
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def img_cleanup(xmldoc)
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
# do not datauri encode SVG, we need to deduplicate its IDs
|
|
61
|
-
unless read_in_if_svg(i, @localdir)
|
|
62
|
-
i["src"] = Vectory::Utils::datauri(i["src"], @localdir)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
58
|
+
altmedia_cleanup(xmldoc)
|
|
59
|
+
@datauriimage and datauri_image(xmldoc)
|
|
66
60
|
svg_cleanup(xmldoc)
|
|
67
61
|
xmldoc
|
|
68
62
|
end
|
|
69
63
|
|
|
64
|
+
def datauri_image(xmldoc)
|
|
65
|
+
xmldoc.xpath("//image | //altsource").each do |i|
|
|
66
|
+
# do not datauri encode SVG, we need to deduplicate its IDs
|
|
67
|
+
unless read_in_if_svg?(i, @localdir)
|
|
68
|
+
i["src"] &&= Vectory::Utils::datauri(i["src"], @localdir)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def altmedia_cleanup(xmldoc)
|
|
74
|
+
xmldoc.xpath("//image[@altmedia]").each do |i|
|
|
75
|
+
altmedia_root_cleanup(i)
|
|
76
|
+
d = altmedia_prep(i)
|
|
77
|
+
d or next
|
|
78
|
+
altsource_populate(i, d)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def altsource_populate(img, dlist)
|
|
83
|
+
dlist.each do |e|
|
|
84
|
+
e[:dd].nil? and next
|
|
85
|
+
img << "<altsource tag='#{e[:dt]}'/>"
|
|
86
|
+
image_attr_copy(e[:dd], img.elements.last)
|
|
87
|
+
altsource_attr_copy(e[:dd], img.elements.last, img)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def image_attr_copy(src, dest)
|
|
92
|
+
%w(src mimetype filename alt).each do |k|
|
|
93
|
+
src[k] and dest[k] = src[k]
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def altsource_attr_copy(src, dest, img)
|
|
98
|
+
%w(media).each do |k|
|
|
99
|
+
src[k] and dest[k] = src[k]
|
|
100
|
+
end
|
|
101
|
+
%w(height width).each do |k|
|
|
102
|
+
dest[k] = img[k]
|
|
103
|
+
src[k] or next
|
|
104
|
+
src[k] == "auto" and next
|
|
105
|
+
dest[k] = src[k]
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def altmedia_root_cleanup(img)
|
|
110
|
+
%w(altmedia src filename mimetype).each do |k|
|
|
111
|
+
img.delete(k)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def altmedia_prep(img)
|
|
116
|
+
dl = img.at("./dl") or return
|
|
117
|
+
d = extract_symbols_list(dl.remove).map do |e|
|
|
118
|
+
{ dt: e[:dt].text, dd: e[:dd].at(".//image") }
|
|
119
|
+
end
|
|
120
|
+
unless d.detect { |e| e[:dt] == "default" }
|
|
121
|
+
d << d.first.dup
|
|
122
|
+
d[-1][:dt] = "default"
|
|
123
|
+
end
|
|
124
|
+
d
|
|
125
|
+
end
|
|
126
|
+
|
|
70
127
|
def svg_cleanup(xmldoc)
|
|
71
128
|
svg_uniqueids(xmldoc)
|
|
72
129
|
svg_classupdate(xmldoc)
|
|
73
130
|
end
|
|
74
131
|
|
|
75
|
-
def read_in_if_svg(img, localdir)
|
|
132
|
+
def read_in_if_svg?(img, localdir)
|
|
76
133
|
img["src"] or return false
|
|
77
134
|
path = Vectory::Utils.svgmap_rewrite0_path(img["src"], localdir)
|
|
78
135
|
File.file?(path) or return false
|
|
79
136
|
types = MIME::Types.type_for(path) or return false
|
|
80
137
|
types.first == "image/svg+xml" or return false
|
|
81
138
|
svg = File.read(path, encoding: "utf-8") or return false
|
|
82
|
-
img.
|
|
139
|
+
img.add_first_child Nokogiri::XML(svg).root
|
|
83
140
|
true
|
|
84
141
|
end
|
|
85
142
|
|
|
@@ -101,7 +158,7 @@ module Metanorma
|
|
|
101
158
|
end
|
|
102
159
|
|
|
103
160
|
def svg_suffix_css_style(node, idx)
|
|
104
|
-
node[:node] == :style_rule && /\./.match?(node[:selector][:value]) or
|
|
161
|
+
(node[:node] == :style_rule && /\./.match?(node[:selector][:value])) or
|
|
105
162
|
return
|
|
106
163
|
v = node[:selector][:value]
|
|
107
164
|
.gsub(/([^.\s]*\.\S+)/, "\\1_inject_#{idx}")
|
|
@@ -149,7 +206,7 @@ module Metanorma
|
|
|
149
206
|
svg_uniqueids2(svg, iri_properties, idx, ids)
|
|
150
207
|
new_ids = id_elems.map { |x| x["id"] }
|
|
151
208
|
.map { |x| x + (ids[x] ? "_inject_#{idx}" : "") }
|
|
152
|
-
ids.merge(new_ids.each.
|
|
209
|
+
ids.merge(new_ids.each.to_h { |value| [value, true] })
|
|
153
210
|
end
|
|
154
211
|
|
|
155
212
|
def svg_uniqueids2(svg, iri_properties, idx, ids)
|