metanorma-standoc 1.10.4.1 → 1.10.8
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/README.adoc +19 -23
- data/lib/asciidoctor/standoc/base.rb +11 -13
- data/lib/asciidoctor/standoc/basicdoc.rng +21 -4
- data/lib/asciidoctor/standoc/blocks.rb +27 -22
- data/lib/asciidoctor/standoc/blocks_notes.rb +17 -22
- data/lib/asciidoctor/standoc/cleanup.rb +38 -71
- data/lib/asciidoctor/standoc/cleanup_block.rb +5 -70
- data/lib/asciidoctor/standoc/cleanup_image.rb +6 -7
- data/lib/asciidoctor/standoc/cleanup_inline.rb +27 -98
- data/lib/asciidoctor/standoc/cleanup_maths.rb +113 -21
- data/lib/asciidoctor/standoc/cleanup_ref.rb +5 -0
- data/lib/asciidoctor/standoc/cleanup_reqt.rb +56 -18
- data/lib/asciidoctor/standoc/cleanup_section.rb +1 -0
- data/lib/asciidoctor/standoc/cleanup_section_names.rb +31 -14
- data/lib/asciidoctor/standoc/cleanup_table.rb +68 -0
- data/lib/asciidoctor/standoc/cleanup_terms.rb +1 -1
- data/lib/asciidoctor/standoc/cleanup_text.rb +73 -0
- data/lib/asciidoctor/standoc/cleanup_xref.rb +107 -0
- data/lib/asciidoctor/standoc/converter.rb +13 -0
- data/lib/asciidoctor/standoc/isodoc.rng +241 -61
- data/lib/asciidoctor/standoc/lists.rb +15 -15
- data/lib/asciidoctor/standoc/macros.rb +14 -43
- data/lib/asciidoctor/standoc/macros_note.rb +45 -0
- data/lib/asciidoctor/standoc/macros_terms.rb +33 -15
- data/lib/asciidoctor/standoc/reqt.rb +2 -2
- data/lib/asciidoctor/standoc/reqt.rng +23 -2
- data/lib/asciidoctor/standoc/table.rb +22 -20
- data/lib/asciidoctor/standoc/terms.rb +9 -1
- data/lib/asciidoctor/standoc/validate.rb +23 -14
- data/lib/asciidoctor/standoc/validate_section.rb +5 -2
- data/lib/metanorma/standoc/version.rb +1 -1
- data/metanorma-standoc.gemspec +1 -1
- data/spec/asciidoctor/base_spec.rb +0 -33
- data/spec/asciidoctor/blank_spec.rb +37 -0
- data/spec/asciidoctor/blocks_spec.rb +151 -30
- data/spec/asciidoctor/cleanup_blocks_spec.rb +1018 -0
- data/spec/asciidoctor/cleanup_sections_spec.rb +207 -0
- data/spec/asciidoctor/cleanup_spec.rb +193 -1078
- data/spec/asciidoctor/inline_spec.rb +36 -0
- data/spec/asciidoctor/isobib_cache_spec.rb +8 -8
- data/spec/asciidoctor/lists_spec.rb +6 -6
- data/spec/asciidoctor/macros_plantuml_spec.rb +1 -1
- data/spec/asciidoctor/macros_spec.rb +41 -26
- data/spec/asciidoctor/refs_dl_spec.rb +1 -1
- data/spec/asciidoctor/refs_spec.rb +220 -444
- data/spec/asciidoctor/section_spec.rb +1 -1
- data/spec/asciidoctor/validate_spec.rb +51 -0
- data/spec/assets/xref_error.adoc +1 -0
- data/spec/fixtures/datamodel_description_sections_tree.xml +24 -24
- data/spec/spec_helper.rb +5 -7
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec.yml +231 -143
- data/spec/vcr_cassettes/dated_iso_ref_joint_iso_iec1.yml +152 -0
- data/spec/vcr_cassettes/isobib_get_123.yml +52 -36
- data/spec/vcr_cassettes/isobib_get_123_1.yml +103 -71
- data/spec/vcr_cassettes/isobib_get_123_1_fr.yml +112 -80
- data/spec/vcr_cassettes/isobib_get_123_2001.yml +50 -34
- data/spec/vcr_cassettes/isobib_get_124.yml +51 -35
- data/spec/vcr_cassettes/rfcbib_get_rfc8341.yml +16 -16
- data/spec/vcr_cassettes/separates_iev_citations_by_top_level_clause.yml +70 -46
- metadata +11 -4
@@ -0,0 +1,73 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Standoc
|
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
|
11
|
+
|
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
|
+
def uninterrupt_quotes_around_xml(xmldoc)
|
32
|
+
xmldoc.xpath("//*[following::text()[1]"\
|
33
|
+
"[starts-with(., '\"') or starts-with(., \"'\")]]")
|
34
|
+
.each do |x|
|
35
|
+
next if !x.ancestors("pre, tt, sourcecode, stem, figure").empty?
|
36
|
+
|
37
|
+
uninterrupt_quotes_around_xml1(x)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def uninterrupt_quotes_around_xml1(elem)
|
42
|
+
prev = elem.at(".//preceding::text()[1]") or return
|
43
|
+
/\S$/.match?(prev.text) or return
|
44
|
+
foll = elem.at(".//following::text()[1]")
|
45
|
+
m = /^(["'][[:punct:]]*)(\s|$)/
|
46
|
+
.match(HTMLEntities.new.decode(foll&.text)) or return
|
47
|
+
foll.content = foll.text.sub(/^(["'][[:punct:]]*)/, "")
|
48
|
+
prev.content = "#{prev.text}#{m[1]}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def dumb2smart_quotes(xmldoc)
|
52
|
+
(xmldoc.xpath("//*[child::text()]") - xmldoc.xpath(IGNORE_DUMBQUOTES))
|
53
|
+
.each do |x|
|
54
|
+
x.children.each do |n|
|
55
|
+
next unless n.text?
|
56
|
+
|
57
|
+
/[-'"(<>]|\.\.|\dx/.match(n) or next
|
58
|
+
|
59
|
+
n.replace(Metanorma::Utils::smartformat(n.text))
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def dumbquote_cleanup(xmldoc)
|
65
|
+
xmldoc.traverse do |n|
|
66
|
+
next unless n.text?
|
67
|
+
|
68
|
+
n.replace(n.text.gsub(/(?<=\p{Alnum})\u2019(?=\p{Alpha})/, "'")) # .
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module Asciidoctor
|
2
|
+
module Standoc
|
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)
|
16
|
+
|
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
|
@@ -49,7 +49,9 @@ module Asciidoctor
|
|
49
49
|
inline_macro Asciidoctor::Standoc::FormSelectMacro
|
50
50
|
inline_macro Asciidoctor::Standoc::FormOptionMacro
|
51
51
|
inline_macro Asciidoctor::Standoc::ToCInlineMacro
|
52
|
+
inline_macro Asciidoctor::Standoc::PassInlineMacro
|
52
53
|
inline_macro Metanorma::Plugin::Lutaml::LutamlFigureInlineMacro
|
54
|
+
inline_macro Metanorma::Plugin::Lutaml::LutamlTableInlineMacro
|
53
55
|
block_macro Metanorma::Plugin::Lutaml::LutamlDiagramBlockMacro
|
54
56
|
block Asciidoctor::Standoc::ToDoAdmonitionBlock
|
55
57
|
treeprocessor Asciidoctor::Standoc::ToDoInlineAdmonitionBlock
|
@@ -97,6 +99,17 @@ module Asciidoctor
|
|
97
99
|
File.join(@libdir, "../../isodoc/html", file)
|
98
100
|
end
|
99
101
|
|
102
|
+
def content(node)
|
103
|
+
node.content
|
104
|
+
end
|
105
|
+
|
106
|
+
def skip(node, name = nil)
|
107
|
+
name = name || node.node_name
|
108
|
+
w = "converter missing for #{name} node in Metanorma backend"
|
109
|
+
@log.add("AsciiDoc Input", node, w)
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
|
100
113
|
alias_method :embedded, :content
|
101
114
|
alias_method :verse, :quote
|
102
115
|
alias_method :audio, :skip
|