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,117 +1,3 @@
|
|
1
|
-
require "
|
2
|
-
require "
|
3
|
-
require "htmlentities"
|
4
|
-
require "json"
|
5
|
-
require "pathname"
|
6
|
-
require "uuidtools"
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/utils"
|
7
3
|
|
8
|
-
module Asciidoctor
|
9
|
-
module Standoc
|
10
|
-
module Utils
|
11
|
-
def convert(node, transform = nil, opts = {})
|
12
|
-
transform ||= node.node_name
|
13
|
-
opts.empty? ? (send transform, node) : (send transform, node, opts)
|
14
|
-
end
|
15
|
-
|
16
|
-
def document_ns_attributes(_doc)
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
|
20
|
-
NOKOHEAD = <<~HERE.freeze
|
21
|
-
<!DOCTYPE html SYSTEM
|
22
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
23
|
-
<html xmlns="http://www.w3.org/1999/xhtml">
|
24
|
-
<head> <title></title> <meta charset="UTF-8" /> </head>
|
25
|
-
<body> </body> </html>
|
26
|
-
HERE
|
27
|
-
|
28
|
-
# block for processing XML document fragments as XHTML,
|
29
|
-
# to allow for HTMLentities
|
30
|
-
# Unescape special chars used in Asciidoctor substitution processing
|
31
|
-
def noko(&block)
|
32
|
-
doc = ::Nokogiri::XML.parse(NOKOHEAD)
|
33
|
-
fragment = doc.fragment("")
|
34
|
-
::Nokogiri::XML::Builder.with fragment, &block
|
35
|
-
fragment.to_xml(encoding: "US-ASCII", indent: 0).lines.map do |l|
|
36
|
-
l.gsub(/>\n$/, ">").gsub(/\s*\n$/m, " ").gsub("–", "\u0096")
|
37
|
-
.gsub("—", "\u0097").gsub("–", "\u0096")
|
38
|
-
.gsub("—", "\u0097")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def attr_code(attributes)
|
43
|
-
attributes.compact.transform_values do |v|
|
44
|
-
v.is_a?(String) ? HTMLEntities.new.decode(v) : v
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
# if the contents of node are blocks, output them to out;
|
49
|
-
# else, wrap them in <p>
|
50
|
-
def wrap_in_para(node, out)
|
51
|
-
if node.blocks? then out << node.content
|
52
|
-
else
|
53
|
-
out.p { |p| p << node.content }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
SUBCLAUSE_XPATH = "//clause[not(parent::sections)]"\
|
58
|
-
"[not(ancestor::boilerplate)]".freeze
|
59
|
-
|
60
|
-
def isodoc(lang, script, i18nyaml = nil)
|
61
|
-
conv = html_converter(EmptyAttr.new)
|
62
|
-
i18n = conv.i18n_init(lang, script, i18nyaml)
|
63
|
-
conv.metadata_init(lang, script, i18n)
|
64
|
-
conv
|
65
|
-
end
|
66
|
-
|
67
|
-
def default_script(lang)
|
68
|
-
case lang
|
69
|
-
when "ar", "fa" then "Arab"
|
70
|
-
when "ur" then "Aran"
|
71
|
-
when "ru", "bg" then "Cyrl"
|
72
|
-
when "hi" then "Deva"
|
73
|
-
when "el" then "Grek"
|
74
|
-
when "zh" then "Hans"
|
75
|
-
when "ko" then "Kore"
|
76
|
-
when "he" then "Hebr"
|
77
|
-
when "ja" then "Jpan"
|
78
|
-
else
|
79
|
-
"Latn"
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def dl_to_attrs(elem, dlist, name)
|
84
|
-
e = dlist.at("./dt[text()='#{name}']") or return
|
85
|
-
val = e.at("./following::dd/p") || e.at("./following::dd") or return
|
86
|
-
elem[name] = val.text
|
87
|
-
end
|
88
|
-
|
89
|
-
def dl_to_elems(ins, elem, dlist, name)
|
90
|
-
a = elem.at("./#{name}[last()]")
|
91
|
-
ins = a if a
|
92
|
-
dlist.xpath("./dt[text()='#{name}']").each do |e|
|
93
|
-
v = e.at("./following::dd")
|
94
|
-
e = v.elements and e.size == 1 && e.first.name == "p" and v = e.first
|
95
|
-
v.name = name
|
96
|
-
ins.next = v
|
97
|
-
ins = ins.next
|
98
|
-
end
|
99
|
-
ins
|
100
|
-
end
|
101
|
-
|
102
|
-
def term_expr(elem)
|
103
|
-
"<expression><name>#{elem}</name></expression>"
|
104
|
-
end
|
105
|
-
|
106
|
-
class EmptyAttr
|
107
|
-
def attr(_any_attribute)
|
108
|
-
nil
|
109
|
-
end
|
110
|
-
|
111
|
-
def attributes
|
112
|
-
{}
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
@@ -1,158 +1,3 @@
|
|
1
|
-
require "asciidoctor/standoc/
|
2
|
-
|
3
|
-
require "nokogiri"
|
4
|
-
require "jing"
|
5
|
-
require "iev"
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/validate"
|
6
3
|
|
7
|
-
module Asciidoctor
|
8
|
-
module Standoc
|
9
|
-
module Validate
|
10
|
-
SOURCELOCALITY = "./origin//locality[@type = 'clause']/"\
|
11
|
-
"referenceFrom".freeze
|
12
|
-
|
13
|
-
def init_iev
|
14
|
-
return nil if @no_isobib
|
15
|
-
return @iev if @iev
|
16
|
-
|
17
|
-
@iev = Iev::Db.new(@iev_globalname, @iev_localname) unless @no_isobib
|
18
|
-
@iev
|
19
|
-
end
|
20
|
-
|
21
|
-
def iev_validate(xmldoc)
|
22
|
-
@iev = init_iev or return
|
23
|
-
xmldoc.xpath("//term").each do |t|
|
24
|
-
t.xpath(".//termsource").each do |src|
|
25
|
-
(/^IEC 60050-/.match(src&.at("./origin/@citeas")&.text) &&
|
26
|
-
loc = src.xpath(SOURCELOCALITY)&.text) or next
|
27
|
-
iev_validate1(t, loc, xmldoc)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def iev_validate1(term, loc, xmldoc)
|
33
|
-
iev = @iev.fetch(loc,
|
34
|
-
xmldoc&.at("//language")&.text || "en") or return
|
35
|
-
pref = term.xpath("./preferred//name").inject([]) do |m, x|
|
36
|
-
m << x&.text&.downcase
|
37
|
-
end
|
38
|
-
pref.include?(iev.downcase) or
|
39
|
-
@log.add("Bibliography", term, %(Term "#{pref[0]}" does not match ) +
|
40
|
-
%(IEV #{loc} "#{iev}"))
|
41
|
-
end
|
42
|
-
|
43
|
-
def content_validate(doc)
|
44
|
-
@fatalerror = []
|
45
|
-
xref_validate(doc)
|
46
|
-
section_validate(doc)
|
47
|
-
norm_ref_validate(doc)
|
48
|
-
repeat_id_validate(doc.root)
|
49
|
-
iev_validate(doc.root)
|
50
|
-
concept_validate(doc, "concept", "refterm")
|
51
|
-
concept_validate(doc, "related", "preferred//name")
|
52
|
-
@fatalerror.empty? or clean_abort(@fatalerror.join("\n"), doc.to_xml)
|
53
|
-
end
|
54
|
-
|
55
|
-
def norm_ref_validate(doc)
|
56
|
-
found = false
|
57
|
-
doc.xpath("//references[@normative = 'true']/bibitem").each do |b|
|
58
|
-
next unless docid = b.at("./docidentifier[@type = 'metanorma']")
|
59
|
-
next unless /^\[\d+\]$/.match?(docid.text)
|
60
|
-
|
61
|
-
@log.add("Bibliography", b,
|
62
|
-
"Numeric reference in normative references")
|
63
|
-
found = true
|
64
|
-
end
|
65
|
-
found and @fatalerror << "Numeric reference in normative references"
|
66
|
-
end
|
67
|
-
|
68
|
-
def concept_validate(doc, tag, refterm)
|
69
|
-
found = false
|
70
|
-
doc.xpath("//#{tag}/xref").each do |x|
|
71
|
-
next if doc.at("//term[@id = '#{x['target']}']")
|
72
|
-
next if doc.at("//definitions//dt[@id = '#{x['target']}']")
|
73
|
-
|
74
|
-
ref = x&.at("../#{refterm}")&.text
|
75
|
-
@log.add("Anchors", x,
|
76
|
-
"#{tag.capitalize} #{ref} is pointing to "\
|
77
|
-
"#{x['target']}, which is not a term or symbol")
|
78
|
-
found = true
|
79
|
-
end
|
80
|
-
found and
|
81
|
-
@fatalerror << "#{tag.capitalize} not cross-referencing term or symbol"
|
82
|
-
end
|
83
|
-
|
84
|
-
def repeat_id_validate1(ids, elem)
|
85
|
-
if ids[elem["id"]]
|
86
|
-
@log.add("Anchors", elem, "Anchor #{elem['id']} has already been "\
|
87
|
-
"used at line #{ids[elem['id']]}")
|
88
|
-
@fatalerror << "Multiple instances of same ID: #{elem['id']}"
|
89
|
-
else
|
90
|
-
ids[elem["id"]] = elem.line
|
91
|
-
end
|
92
|
-
ids
|
93
|
-
end
|
94
|
-
|
95
|
-
def repeat_id_validate(doc)
|
96
|
-
ids = {}
|
97
|
-
doc.xpath("//*[@id]").each do |x|
|
98
|
-
ids = repeat_id_validate1(ids, x)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def schema_validate(doc, schema)
|
103
|
-
Tempfile.open(["tmp", ".xml"], encoding: "UTF-8") do |f|
|
104
|
-
schema_validate1(f, doc, schema)
|
105
|
-
rescue Jing::Error => e
|
106
|
-
clean_abort("Jing failed with error: #{e}", doc.to_xml)
|
107
|
-
ensure
|
108
|
-
f.close!
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def schema_validate1(file, doc, schema)
|
113
|
-
file.write(doc.to_xml)
|
114
|
-
file.close
|
115
|
-
errors = Jing.new(schema).validate(file.path)
|
116
|
-
warn "Syntax Valid!" if errors.none?
|
117
|
-
errors.each do |e|
|
118
|
-
@log.add("Metanorma XML Syntax",
|
119
|
-
"XML Line #{'%06d' % e[:line]}:#{e[:column]}", e[:message])
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
# RelaxNG cannot cope well with wildcard attributes. So we strip
|
124
|
-
# any attributes from FormattedString instances (which can contain
|
125
|
-
# xs:any markup, and are signalled with @format) before validation.
|
126
|
-
def formattedstr_strip(doc)
|
127
|
-
doc.xpath("//*[@format] | //stem | //bibdata//description | "\
|
128
|
-
"//formattedref | //bibdata//note | //bibdata/abstract | "\
|
129
|
-
"//bibitem/abstract | //bibitem/note | //misc-container")
|
130
|
-
.each do |n|
|
131
|
-
n.elements.each do |e|
|
132
|
-
e.traverse do |e1|
|
133
|
-
e1.element? and e1.each { |k, _v| e1.delete(k) }
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
doc
|
138
|
-
end
|
139
|
-
|
140
|
-
# manually check for xref/@target, xref/@to integrity
|
141
|
-
def xref_validate(doc)
|
142
|
-
ids = doc.xpath("//*/@id").each_with_object({}) { |x, m| m[x.text] = 1 }
|
143
|
-
doc.xpath("//xref/@target | //xref/@to").each do |x|
|
144
|
-
next if ids[x.text]
|
145
|
-
|
146
|
-
@log.add("Anchors", x.parent,
|
147
|
-
"Crossreference target #{x.text} is undefined")
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
def validate(doc)
|
152
|
-
content_validate(doc)
|
153
|
-
schema_validate(formattedstr_strip(doc.dup),
|
154
|
-
File.join(File.dirname(__FILE__), "isodoc.rng"))
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
@@ -1,55 +1,3 @@
|
|
1
|
-
require "
|
1
|
+
require "asciidoctor/standoc/deprecated"
|
2
|
+
require "metanorma/standoc/validate_section"
|
2
3
|
|
3
|
-
module Asciidoctor
|
4
|
-
module Standoc
|
5
|
-
module Validate
|
6
|
-
def section_validate(doc)
|
7
|
-
sourcecode_style(doc.root)
|
8
|
-
hanging_para_style(doc.root)
|
9
|
-
asset_style(doc.root)
|
10
|
-
end
|
11
|
-
|
12
|
-
def sourcecode_style(root)
|
13
|
-
root.xpath("//sourcecode").each do |x|
|
14
|
-
callouts = x.elements.select { |e| e.name == "callout" }
|
15
|
-
annotations = x.elements.select { |e| e.name == "annotation" }
|
16
|
-
if callouts.size != annotations.size
|
17
|
-
@log.add("AsciiDoc Input", x,
|
18
|
-
"mismatch of callouts and annotations")
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def style_warning(node, msg, text = nil)
|
24
|
-
w = msg
|
25
|
-
w += ": #{text}" if text
|
26
|
-
@log.add("Metanorma XML Style Warning", node, w)
|
27
|
-
end
|
28
|
-
|
29
|
-
def asset_title_style(root)
|
30
|
-
root.xpath("//figure[image][not(name)]").each do |node|
|
31
|
-
style_warning(node, "Figure should have title", nil)
|
32
|
-
end
|
33
|
-
root.xpath("//table[not(name)]").each do |node|
|
34
|
-
style_warning(node, "Table should have title", nil)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def asset_style(root)
|
39
|
-
asset_title_style(root)
|
40
|
-
end
|
41
|
-
|
42
|
-
def hanging_para_style(root)
|
43
|
-
root.xpath("//clause | //annex | //foreword | //introduction | "\
|
44
|
-
"//acknowledgements").each do |c|
|
45
|
-
next unless c.at("./clause")
|
46
|
-
next if c.elements.reject do |n|
|
47
|
-
%w(clause title).include? n.name
|
48
|
-
end.empty?
|
49
|
-
|
50
|
-
style_warning(c, "Hanging paragraph in clause")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
@@ -76,6 +76,12 @@ code *, pre *, tt *, kbd *, samp * {
|
|
76
76
|
font-family: {{monospacefont}} !important;
|
77
77
|
font-variant-ligatures: none; }
|
78
78
|
|
79
|
+
p code, dt code, li code, label code, legend code, caption code, th code, td code,
|
80
|
+
p tt, dt tt, li tt, label tt, legend tt, caption tt, th tt, td tt,
|
81
|
+
p kbd, dt kbd, li kbd, label kbd, legend kbd, caption kbd, th kbd, td kbd,
|
82
|
+
p samp, dt samp, li samp, label samp, legend samp, caption samp, th samp, td samp {
|
83
|
+
font-size: {{monospacefontsize}}; }
|
84
|
+
|
79
85
|
article, aside, details, figcaption, figure,
|
80
86
|
footer, header, hgroup, menu, nav, section {
|
81
87
|
display: block; }
|
@@ -87,6 +93,9 @@ table {
|
|
87
93
|
h1, h2, h3, h4, h5, h6 {
|
88
94
|
font-family: {{headerfont}}; }
|
89
95
|
|
96
|
+
.h1, .h2, .h3, .h4, .h5, .h6 {
|
97
|
+
font-family: {{headerfont}}; }
|
98
|
+
|
90
99
|
blockquote, q {
|
91
100
|
quotes: none; }
|
92
101
|
blockquote:before, blockquote:after, q:before, q:after {
|
@@ -467,32 +476,32 @@ p.document-stage {
|
|
467
476
|
/*
|
468
477
|
3.1 Titles
|
469
478
|
*/
|
470
|
-
h1, h2, h3, h4, h5, h6 {
|
479
|
+
h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
|
471
480
|
font-family: {{headerfont}};
|
472
481
|
color: #C70039;
|
473
482
|
font-weight: 300;
|
474
483
|
margin-top: 1.6em;
|
475
484
|
margin-bottom: 0.3em; }
|
476
485
|
|
477
|
-
h1 {
|
486
|
+
h1, .h1 {
|
478
487
|
font-size: 1.6em;
|
479
488
|
text-transform: uppercase;
|
480
489
|
margin-top: 2em; }
|
481
490
|
|
482
|
-
h1#content {
|
491
|
+
h1#content, #content.h1 {
|
483
492
|
margin-top: 2em; }
|
484
493
|
|
485
|
-
h2 {
|
494
|
+
h2, .h2 {
|
486
495
|
margin-top: 1.3em;
|
487
496
|
font-size: 1.3em;
|
488
497
|
font-weight: 400; }
|
489
498
|
|
490
|
-
h3 {
|
499
|
+
h3, .h3 {
|
491
500
|
margin-top: 1.1em;
|
492
501
|
font-size: 1.1em;
|
493
502
|
font-weight: 100; }
|
494
503
|
|
495
|
-
.TermNum
|
504
|
+
.TermNum {
|
496
505
|
color: #C70039;
|
497
506
|
font-weight: 100; }
|
498
507
|
|
@@ -791,7 +800,7 @@ p {
|
|
791
800
|
margin-top: 1em;
|
792
801
|
margin-bottom: 1em; }
|
793
802
|
|
794
|
-
h2 p {
|
803
|
+
h2 p, .h2 p {
|
795
804
|
display: inline; }
|
796
805
|
|
797
806
|
/*
|
@@ -942,7 +951,7 @@ To top button
|
|
942
951
|
@media print {
|
943
952
|
.document-info, nav, .copyright {
|
944
953
|
page-break-before: always; }
|
945
|
-
h1, h2, h3, h4 {
|
954
|
+
h1, h2, h3, h4, .h1, .h2, .h3, .h4 {
|
946
955
|
page-break-after: avoid;
|
947
956
|
margin-top: 1.2em; }
|
948
957
|
.note, .figure, pre, .pseudocode, table {
|
@@ -965,12 +974,12 @@ To top button
|
|
965
974
|
h1.content {
|
966
975
|
margin-top: 2em;
|
967
976
|
line-height: 2.5em; }
|
968
|
-
h1 {
|
977
|
+
h1, .h1 {
|
969
978
|
font-size: 1.5em;
|
970
979
|
line-height: 1.5; }
|
971
|
-
h2 {
|
980
|
+
h2, .h2 {
|
972
981
|
font-size: 1.2em; }
|
973
|
-
h3 {
|
982
|
+
h3, .h3 {
|
974
983
|
font-size: 1em; }
|
975
984
|
.Note {
|
976
985
|
background-color: #fff495;
|
@@ -155,7 +155,7 @@ p.document-stage {
|
|
155
155
|
3.1 Titles
|
156
156
|
*/
|
157
157
|
|
158
|
-
h1,h2,h3,h4,h5,h6 {
|
158
|
+
h1,h2,h3,h4,h5,h6,.h1,.h2,.h3,.h4,.h5,.h6 {
|
159
159
|
font-family: $headerfont;
|
160
160
|
color: #C70039;
|
161
161
|
font-weight: 300;
|
@@ -163,29 +163,29 @@ p.document-stage {
|
|
163
163
|
margin-bottom: 0.3em;
|
164
164
|
}
|
165
165
|
|
166
|
-
h1 {
|
166
|
+
h1,.h1 {
|
167
167
|
font-size: 1.6em;
|
168
168
|
text-transform: uppercase;
|
169
169
|
margin-top: 2em;
|
170
170
|
}
|
171
171
|
|
172
|
-
h1#content {
|
172
|
+
h1#content,.h1#content {
|
173
173
|
margin-top: 2em;
|
174
174
|
}
|
175
175
|
|
176
|
-
h2 {
|
176
|
+
h2,.h2 {
|
177
177
|
margin-top: 1.3em;
|
178
178
|
font-size: 1.3em;
|
179
179
|
font-weight: 400;
|
180
180
|
}
|
181
181
|
|
182
|
-
h3 {
|
182
|
+
h3,.h3 {
|
183
183
|
margin-top: 1.1em;
|
184
184
|
font-size: 1.1em;
|
185
185
|
font-weight: 100;
|
186
186
|
}
|
187
187
|
|
188
|
-
.TermNum
|
188
|
+
.TermNum {
|
189
189
|
color: #C70039;
|
190
190
|
font-weight: 100;
|
191
191
|
}
|
@@ -471,7 +471,7 @@ p {
|
|
471
471
|
margin-bottom: 1em;
|
472
472
|
}
|
473
473
|
|
474
|
-
h2 p {
|
474
|
+
h2 p, .h2 p {
|
475
475
|
display: inline;
|
476
476
|
}
|
477
477
|
|
@@ -643,7 +643,7 @@ To top button
|
|
643
643
|
page-break-before: always;
|
644
644
|
}
|
645
645
|
|
646
|
-
h1, h2, h3, h4 {
|
646
|
+
h1, h2, h3, h4, .h1, .h2, .h3, .h4 {
|
647
647
|
page-break-after: avoid;
|
648
648
|
margin-top: 1.2em;
|
649
649
|
}
|
@@ -685,16 +685,16 @@ To top button
|
|
685
685
|
line-height: 2.5em;
|
686
686
|
}
|
687
687
|
|
688
|
-
h1 {
|
688
|
+
h1, .h1 {
|
689
689
|
font-size: 1.5em;
|
690
690
|
line-height: 1.5;
|
691
691
|
}
|
692
692
|
|
693
|
-
h2 {
|
693
|
+
h2, .h2 {
|
694
694
|
font-size: 1.2em
|
695
695
|
}
|
696
696
|
|
697
|
-
h3 {
|
697
|
+
h3, .h3 {
|
698
698
|
font-size: 1em;
|
699
699
|
}
|
700
700
|
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require "date"
|
2
|
+
require "nokogiri"
|
3
|
+
require "htmlentities"
|
4
|
+
require "json"
|
5
|
+
require "pathname"
|
6
|
+
require "isodoc"
|
7
|
+
require "relaton"
|
8
|
+
require "fileutils"
|
9
|
+
require "metanorma-utils"
|
10
|
+
require "isodoc/xslfo_convert"
|
11
|
+
require_relative "render"
|
12
|
+
|
13
|
+
module Metanorma
|
14
|
+
module Standoc
|
15
|
+
module Base
|
16
|
+
XML_ROOT_TAG = "standard-document".freeze
|
17
|
+
XML_NAMESPACE = "https://www.metanorma.org/ns/standoc".freeze
|
18
|
+
FONTS_MANIFEST = "fonts-manifest".freeze
|
19
|
+
|
20
|
+
def xml_root_tag
|
21
|
+
self.class::XML_ROOT_TAG
|
22
|
+
end
|
23
|
+
|
24
|
+
def xml_namespace
|
25
|
+
self.class::XML_NAMESPACE
|
26
|
+
end
|
27
|
+
|
28
|
+
def init(node)
|
29
|
+
@fn_number ||= 0
|
30
|
+
@draft = false
|
31
|
+
@refids = Set.new
|
32
|
+
@anchors = {}
|
33
|
+
@internal_eref_namespaces = []
|
34
|
+
@draft = node.attributes.has_key?("draft")
|
35
|
+
@novalid = node.attr("novalid")
|
36
|
+
@smartquotes = node.attr("smartquotes") != "false"
|
37
|
+
@keepasciimath = node.attr("mn-keep-asciimath") &&
|
38
|
+
node.attr("mn-keep-asciimath") != "false"
|
39
|
+
@fontheader = default_fonts(node)
|
40
|
+
@files_to_delete = []
|
41
|
+
@filename = if node.attr("docfile")
|
42
|
+
File.basename(node.attr("docfile"))&.gsub(/\.adoc$/, "")
|
43
|
+
else ""
|
44
|
+
end
|
45
|
+
@localdir = Metanorma::Utils::localdir(node)
|
46
|
+
@output_dir = outputdir node
|
47
|
+
@no_isobib_cache = node.attr("no-isobib-cache")
|
48
|
+
@no_isobib = node.attr("no-isobib")
|
49
|
+
@index_terms = node.attr("index-terms")
|
50
|
+
@sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
|
51
|
+
@sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
|
52
|
+
@bibdb = nil
|
53
|
+
@seen_headers = []
|
54
|
+
@datauriimage = node.attr("data-uri-image") != "false"
|
55
|
+
@boilerplateauthority = node.attr("boilerplate-authority")
|
56
|
+
@sourcecode_markup_start = node.attr("sourcecode-markup-start") || "{{{"
|
57
|
+
@sourcecode_markup_end = node.attr("sourcecode-markup-end") || "}}}"
|
58
|
+
@log = Metanorma::Utils::Log.new
|
59
|
+
init_bib_caches(node)
|
60
|
+
init_iev_caches(node)
|
61
|
+
@lang = (node.attr("language") || "en")
|
62
|
+
@script = (node.attr("script") ||
|
63
|
+
Metanorma::Utils.default_script(node.attr("language")))
|
64
|
+
@isodoc = isodoc(@lang, @script, node.attr("i18nyaml"))
|
65
|
+
@i18n = @isodoc.i18n
|
66
|
+
@htmltoclevels = node.attr("htmltoclevels")
|
67
|
+
@doctoclevels = node.attr("doctoclevels")
|
68
|
+
@toclevels = node.attr("toclevels")
|
69
|
+
end
|
70
|
+
|
71
|
+
def document(node)
|
72
|
+
init(node)
|
73
|
+
ret = makexml(node).to_xml(encoding: "US-ASCII", indent: 2)
|
74
|
+
outputs(node, ret) unless node.attr("nodoc") || !node.attr("docfile")
|
75
|
+
clean_exit
|
76
|
+
ret
|
77
|
+
rescue StandardError => e
|
78
|
+
@log.add("Fatal Error", nil, e.message)
|
79
|
+
clean_exit
|
80
|
+
raise e
|
81
|
+
end
|
82
|
+
|
83
|
+
def version
|
84
|
+
flavour = self.class.name.sub(/::Converter$/, "").sub(/^.+::/, "")
|
85
|
+
Metanorma.versioned(Metanorma, flavour)[-1]::VERSION
|
86
|
+
end
|
87
|
+
|
88
|
+
def clean_exit
|
89
|
+
@log.write("#{@output_dir}#{@filename}.err") unless @novalid
|
90
|
+
|
91
|
+
@files_to_delete.each { |f| FileUtils.rm f }
|
92
|
+
end
|
93
|
+
|
94
|
+
def clean_abort(msg, file = nil)
|
95
|
+
file and
|
96
|
+
File.open("#{@filename}.xml.abort", "w:UTF-8") { |f| f.write(file) }
|
97
|
+
clean_exit
|
98
|
+
abort(msg)
|
99
|
+
end
|
100
|
+
|
101
|
+
def makexml1(node)
|
102
|
+
result = ["<?xml version='1.0' encoding='UTF-8'?>",
|
103
|
+
"<#{xml_root_tag} type='semantic' version='#{version}'>"]
|
104
|
+
result << noko { |ixml| front node, ixml }
|
105
|
+
result << noko { |ixml| middle node, ixml }
|
106
|
+
result << "</#{xml_root_tag}>"
|
107
|
+
textcleanup(result)
|
108
|
+
end
|
109
|
+
|
110
|
+
def makexml(node)
|
111
|
+
result = makexml1(node)
|
112
|
+
ret1 = cleanup(Nokogiri::XML(result))
|
113
|
+
ret1.root.add_namespace(nil, xml_namespace)
|
114
|
+
validate(ret1) unless @novalid
|
115
|
+
ret1
|
116
|
+
end
|
117
|
+
|
118
|
+
def draft?
|
119
|
+
@draft
|
120
|
+
end
|
121
|
+
|
122
|
+
def doctype(node)
|
123
|
+
node.attr("doctype")&.gsub(/\s+/, "-")&.downcase
|
124
|
+
end
|
125
|
+
|
126
|
+
def front(node, xml)
|
127
|
+
xml.bibdata **attr_code(type: "standard") do |b|
|
128
|
+
metadata node, b
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def middle(node, xml)
|
133
|
+
xml.sections do |s|
|
134
|
+
s << node.content if node.blocks?
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
def outputdir(node)
|
141
|
+
if node.attr("output_dir").nil_or_empty?
|
142
|
+
Metanorma::Utils::localdir(node)
|
143
|
+
else
|
144
|
+
File.join(node.attr("output_dir"), "")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
File without changes
|
File without changes
|