asciidoctor-iso 0.10.1 → 0.10.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/asciidoctor-iso.gemspec +1 -0
- data/lib/asciidoctor/iso/base.rb +1 -146
- data/lib/asciidoctor/iso/cleanup.rb +26 -233
- data/lib/asciidoctor/iso/converter.rb +2 -38
- data/lib/asciidoctor/iso/front.rb +2 -32
- data/lib/asciidoctor/iso/isodoc.rng +43 -25
- data/lib/asciidoctor/iso/isostandard.rng +8 -8
- data/lib/asciidoctor/iso/section.rb +2 -117
- data/lib/asciidoctor/iso/validate.rb +4 -45
- data/lib/asciidoctor/iso/validate_requirements.rb +2 -2
- data/lib/asciidoctor/iso/validate_section.rb +12 -6
- data/lib/asciidoctor/iso/validate_style.rb +2 -9
- data/lib/asciidoctor/iso/version.rb +1 -1
- data/spec/asciidoctor-iso/base_spec.rb +2 -0
- data/spec/asciidoctor-iso/macros_spec.rb +1 -1
- data/spec/asciidoctor-iso/refs_spec.rb +1 -1
- data/spec/asciidoctor-iso/validate_spec.rb +1 -12
- data/spec/assets/iso.doc +7 -7
- data/spec/spec_helper.rb +1 -0
- metadata +16 -13
- data/lib/asciidoctor/iso/blocks.rb +0 -190
- data/lib/asciidoctor/iso/cleanup_block.rb +0 -193
- data/lib/asciidoctor/iso/cleanup_footnotes.rb +0 -96
- data/lib/asciidoctor/iso/cleanup_ref.rb +0 -125
- data/lib/asciidoctor/iso/inline.rb +0 -134
- data/lib/asciidoctor/iso/isostandard_diff.rnc +0 -279
- data/lib/asciidoctor/iso/lists.rb +0 -87
- data/lib/asciidoctor/iso/macros.rb +0 -95
- data/lib/asciidoctor/iso/ref.rb +0 -187
- data/lib/asciidoctor/iso/table.rb +0 -61
- data/lib/asciidoctor/iso/utils.rb +0 -127
data/lib/asciidoctor/iso/ref.rb
DELETED
@@ -1,187 +0,0 @@
|
|
1
|
-
require "pp"
|
2
|
-
|
3
|
-
module Asciidoctor
|
4
|
-
module ISO
|
5
|
-
module Lists
|
6
|
-
def iso_publisher(t, code)
|
7
|
-
code.sub(/ .*$/, "").split(/\//).each do |abbrev|
|
8
|
-
t.contributor do |c|
|
9
|
-
c.role **{ type: "publisher" }
|
10
|
-
c.organization do |org|
|
11
|
-
organization(org, abbrev)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def plaintxt
|
18
|
-
{ format: "text/plain" }
|
19
|
-
end
|
20
|
-
|
21
|
-
def ref_attributes(m)
|
22
|
-
{ id: m[:anchor], type: "standard" }
|
23
|
-
end
|
24
|
-
|
25
|
-
def set_date_range(date, text)
|
26
|
-
matched = /^(?<from>[0-9]+)(-+(?<to>[0-9]+))?$/.match text
|
27
|
-
return unless matched[:from]
|
28
|
-
if matched[:to]
|
29
|
-
date.from matched[:from]
|
30
|
-
date.to matched[:to]
|
31
|
-
else
|
32
|
-
date.on matched[:from]
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def use_my_anchor(ref, id)
|
37
|
-
ref.parent.elements.last["id"] = id
|
38
|
-
ref
|
39
|
-
end
|
40
|
-
|
41
|
-
def isorefmatches(xml, m)
|
42
|
-
ref = fetch_ref xml, m[:code], m[:year]
|
43
|
-
return use_my_anchor(ref, m[:anchor]) if ref
|
44
|
-
xml.bibitem **attr_code(ref_attributes(m)) do |t|
|
45
|
-
t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
|
46
|
-
t.docidentifier m[:code]
|
47
|
-
m[:year] and t.date **{ type: "published" } do |d|
|
48
|
-
set_date_range(d, m[:year])
|
49
|
-
end
|
50
|
-
iso_publisher(t, m[:code])
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def isorefmatches2(xml, m)
|
55
|
-
ref = fetch_ref xml, m[:code], nil, no_year: true, note: m[:fn]
|
56
|
-
return use_my_anchor(ref, m[:anchor]) if ref
|
57
|
-
xml.bibitem **attr_code(ref_attributes(m)) do |t|
|
58
|
-
t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
|
59
|
-
t.docidentifier m[:code]
|
60
|
-
t.date **{ type: "published" } do |d|
|
61
|
-
d.on "--"
|
62
|
-
end
|
63
|
-
iso_publisher(t, m[:code])
|
64
|
-
t.note(**plaintxt) { |p| p << "ISO DATE: #{m[:fn]}" }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def isorefmatches3(xml, m)
|
69
|
-
hasyr = m.names.include?("year")
|
70
|
-
ref = fetch_ref xml, m[:code], hasyr ? m[:year] : nil, all_parts: true
|
71
|
-
return use_my_anchor(ref, m[:anchor]) if ref
|
72
|
-
xml.bibitem(**attr_code(ref_attributes(m))) do |t|
|
73
|
-
t.title(**plaintxt) { |i| i << ref_normalise(m[:text]) }
|
74
|
-
t.docidentifier "#{m[:code]}"
|
75
|
-
hasyr and
|
76
|
-
t.date(**{ type: "published" }) { |d| set_date_range(d, m[:year]) }
|
77
|
-
iso_publisher(t, m[:code])
|
78
|
-
t.allParts "true"
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def fetch_ref(xml, code, year, **opts)
|
83
|
-
hit = @bibdb&.fetch(code, year, opts)
|
84
|
-
return nil if hit.nil?
|
85
|
-
xml.parent.add_child(hit.to_xml)
|
86
|
-
xml
|
87
|
-
rescue Algolia::AlgoliaProtocolError
|
88
|
-
nil # Render reference without an Internet connection.
|
89
|
-
end
|
90
|
-
|
91
|
-
def refitem_render(xml, m)
|
92
|
-
xml.bibitem **attr_code(id: m[:anchor]) do |t|
|
93
|
-
t.formattedref **{ format: "application/x-isodoc+xml" } do |i|
|
94
|
-
i << ref_normalise_no_format(m[:text])
|
95
|
-
end
|
96
|
-
t.docidentifier(/^\d+$/.match(m[:code]) ? "[#{m[:code]}]" : m[:code])
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
# TODO: alternative where only title is available
|
101
|
-
def refitem(xml, item, node)
|
102
|
-
unless m = NON_ISO_REF.match(item)
|
103
|
-
Utils::warning(node, "no anchor on reference", item)
|
104
|
-
return
|
105
|
-
end
|
106
|
-
unless m[:code] && /^\d+$/.match(m[:code])
|
107
|
-
ref = fetch_ref xml, m[:code],
|
108
|
-
m.names.include?("year") ? m[:year] : nil, {}
|
109
|
-
return use_my_anchor(ref, m[:anchor]) if ref
|
110
|
-
end
|
111
|
-
refitem_render(xml, m)
|
112
|
-
end
|
113
|
-
|
114
|
-
def ref_normalise(ref)
|
115
|
-
ref.
|
116
|
-
# gsub(/ — /, " -- ").
|
117
|
-
gsub(/&amp;/, "&").
|
118
|
-
gsub(%r{^<em>(.*)</em>}, "\\1")
|
119
|
-
end
|
120
|
-
|
121
|
-
def ref_normalise_no_format(ref)
|
122
|
-
ref.
|
123
|
-
# gsub(/ — /, " -- ").
|
124
|
-
gsub(/&amp;/, "&")
|
125
|
-
end
|
126
|
-
|
127
|
-
ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
128
|
-
\[(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+|IEV)
|
129
|
-
(:(?<year>[0-9][0-9-]+))?\]</ref>,?\s
|
130
|
-
(?<text>.*)$}xm
|
131
|
-
|
132
|
-
ISO_REF_NO_YEAR = %r{^<ref\sid="(?<anchor>[^"]+)">
|
133
|
-
\[(?<code>(ISO|IEC)[^0-9]*\s[0-9-]+):--\]</ref>,?\s?
|
134
|
-
<fn[^>]*>\s*<p>(?<fn>[^\]]+)</p>\s*</fn>,?\s?(?<text>.*)$}xm
|
135
|
-
|
136
|
-
ISO_REF_ALL_PARTS = %r{^<ref\sid="(?<anchor>[^"]+)">
|
137
|
-
\[(?<code>(ISO|IEC)[^0-9]*\s[0-9]+)(:(?<year>[0-9][0-9-]+))?\s
|
138
|
-
\(all\sparts\)\]</ref>,?\s
|
139
|
-
(?<text>.*)$}xm
|
140
|
-
|
141
|
-
NON_ISO_REF = %r{^<ref\sid="(?<anchor>[^"]+)">
|
142
|
-
\[(?<code>[^\]]+?)([:-](?<year>(19|20)[0-9][0-9]))?\]</ref>,?\s
|
143
|
-
(?<text>.*)$}xm
|
144
|
-
|
145
|
-
# @param item [String]
|
146
|
-
# @return [Array<MatchData>]
|
147
|
-
def reference1_matches(item)
|
148
|
-
matched = ISO_REF.match item
|
149
|
-
matched2 = ISO_REF_NO_YEAR.match item
|
150
|
-
matched3 = ISO_REF_ALL_PARTS.match item
|
151
|
-
[matched, matched2, matched3]
|
152
|
-
end
|
153
|
-
|
154
|
-
# @param node [Asciidoctor::List]
|
155
|
-
# @param item [String]
|
156
|
-
# @param xml [Nokogiri::XML::Builder]
|
157
|
-
def reference1(node, item, xml)
|
158
|
-
matched, matched2, matched3 = reference1_matches(item)
|
159
|
-
if matched3.nil? && matched2.nil? && matched.nil?
|
160
|
-
refitem(xml, item, node)
|
161
|
-
# elsif fetch_ref(matched3 || matched2 || matched, xml)
|
162
|
-
elsif !matched.nil? then isorefmatches(xml, matched)
|
163
|
-
elsif !matched2.nil? then isorefmatches2(xml, matched2)
|
164
|
-
elsif !matched3.nil? then isorefmatches3(xml, matched3)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def reference(node)
|
169
|
-
noko do |xml|
|
170
|
-
node.items.each do |item|
|
171
|
-
reference1(node, item.text, xml)
|
172
|
-
end
|
173
|
-
end.join("\n")
|
174
|
-
end
|
175
|
-
|
176
|
-
def bibliocache_name(global)
|
177
|
-
global ? "#{Dir.home}/.relaton-bib.pstore" :
|
178
|
-
"#{@filename}.relaton.pstore"
|
179
|
-
end
|
180
|
-
|
181
|
-
def ievcache_name(global)
|
182
|
-
global ? "#{Dir.home}/.iev.pstore" :
|
183
|
-
"#{@filename}.iev.pstore"
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
module Asciidoctor
|
2
|
-
module ISO
|
3
|
-
module Table
|
4
|
-
def table_attrs(node)
|
5
|
-
{ id: Utils::anchor_or_uuid(node),
|
6
|
-
headerrows: node.attr("headerrows") }
|
7
|
-
end
|
8
|
-
|
9
|
-
def table(node)
|
10
|
-
@table_fn_number = "a"
|
11
|
-
noko do |xml|
|
12
|
-
xml.table **attr_code(table_attrs(node)) do |xml_table|
|
13
|
-
table_name(node, xml_table)
|
14
|
-
%i(head body foot).reject do |tblsec|
|
15
|
-
node.rows[tblsec].empty?
|
16
|
-
end
|
17
|
-
table_head_body_and_foot node, xml_table
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def table_name(node, xml_table)
|
25
|
-
if node.title?
|
26
|
-
xml_table.name node.title
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def table_cell1(cell, thd)
|
31
|
-
if cell.style == :asciidoc
|
32
|
-
thd << cell.content
|
33
|
-
else
|
34
|
-
thd << cell.text
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def table_cell(c, xml_tr, tblsec)
|
39
|
-
cell_attributes = { id: c.id, colspan: c.colspan,
|
40
|
-
rowspan: c.rowspan, align: c.attr("halign") }
|
41
|
-
cell_tag = "td"
|
42
|
-
cell_tag = "th" if tblsec == :head || c.style == :header
|
43
|
-
xml_tr.send cell_tag, **attr_code(cell_attributes) do |thd|
|
44
|
-
table_cell1(c, thd)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def table_head_body_and_foot(node, xml)
|
49
|
-
%i(head body foot).reject { |s| node.rows[s].empty? }.each do |s|
|
50
|
-
xml.send "t#{s}" do |xml_tblsec|
|
51
|
-
node.rows[s].each do |row|
|
52
|
-
xml_tblsec.tr do |xml_tr|
|
53
|
-
row.each { |cell| table_cell(cell, xml_tr, s) }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
require "date"
|
2
|
-
require "nokogiri"
|
3
|
-
require "htmlentities"
|
4
|
-
require "json"
|
5
|
-
require "pathname"
|
6
|
-
require "open-uri"
|
7
|
-
require "uuidtools"
|
8
|
-
require "pp"
|
9
|
-
|
10
|
-
module Asciidoctor
|
11
|
-
module ISO
|
12
|
-
module Utils
|
13
|
-
class << self
|
14
|
-
def anchor_or_uuid(node = nil)
|
15
|
-
uuid = UUIDTools::UUID.random_create
|
16
|
-
node.nil? || node.id.nil? || node.id.empty? ? "_" + uuid : node.id
|
17
|
-
end
|
18
|
-
|
19
|
-
def current_location(n)
|
20
|
-
return "Line #{n.lineno}" if n.respond_to?(:lineno) &&
|
21
|
-
!n.lineno.nil? && !n.lineno.empty?
|
22
|
-
return "Line #{n.line}" if n.respond_to?(:line) &&
|
23
|
-
!n.line.nil?
|
24
|
-
return "ID #{n.id}" if n.respond_to?(:id) && !n.id.nil?
|
25
|
-
while !n.nil? &&
|
26
|
-
(!n.respond_to?(:level) || n.level.positive?) &&
|
27
|
-
(!n.respond_to?(:context) || n.context != :section)
|
28
|
-
n = n.parent
|
29
|
-
return "Section: #{n.title}" if n&.respond_to?(:context) &&
|
30
|
-
n&.context == :section
|
31
|
-
end
|
32
|
-
"??"
|
33
|
-
end
|
34
|
-
|
35
|
-
def warning(node, msg, text)
|
36
|
-
return if @novalid
|
37
|
-
warntext = "asciidoctor: WARNING"\
|
38
|
-
"(#{current_location(node)}): #{msg}"
|
39
|
-
warntext += ": #{text}" if text
|
40
|
-
warn warntext
|
41
|
-
end
|
42
|
-
|
43
|
-
def flatten_rawtext_lines(node, result)
|
44
|
-
node.lines.each do |x|
|
45
|
-
if node.respond_to?(:context) && (node.context == :literal ||
|
46
|
-
node.context == :listing)
|
47
|
-
result << x.gsub(/</, "<").gsub(/>/, ">")
|
48
|
-
else
|
49
|
-
# strip not only HTML <tag>, and Asciidoc xrefs <<xref>>
|
50
|
-
result << x.gsub(/<[^>]*>+/, "")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
result
|
54
|
-
end
|
55
|
-
|
56
|
-
# if node contains blocks, flatten them into a single line;
|
57
|
-
# and extract only raw text
|
58
|
-
def flatten_rawtext(node)
|
59
|
-
result = []
|
60
|
-
if node.respond_to?(:blocks) && node.blocks?
|
61
|
-
node.blocks.each { |b| result << flatten_rawtext(b) }
|
62
|
-
elsif node.respond_to?(:lines)
|
63
|
-
result = flatten_rawtext_lines(node, result)
|
64
|
-
elsif node.respond_to?(:text)
|
65
|
-
result << node.text.gsub(/<[^>]*>+/, "")
|
66
|
-
else
|
67
|
-
result << node.content.gsub(/<[^>]*>+/, "")
|
68
|
-
end
|
69
|
-
result.reject(&:empty?)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def convert(node, transform = nil, opts = {})
|
74
|
-
transform ||= node.node_name
|
75
|
-
opts.empty? ? (send transform, node) : (send transform, node, opts)
|
76
|
-
end
|
77
|
-
|
78
|
-
def document_ns_attributes(_doc)
|
79
|
-
nil
|
80
|
-
end
|
81
|
-
|
82
|
-
NOKOHEAD = <<~HERE.freeze
|
83
|
-
<!DOCTYPE html SYSTEM
|
84
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
85
|
-
<html xmlns="http://www.w3.org/1999/xhtml">
|
86
|
-
<head> <title></title> <meta charset="UTF-8" /> </head>
|
87
|
-
<body> </body> </html>
|
88
|
-
HERE
|
89
|
-
|
90
|
-
# block for processing XML document fragments as XHTML,
|
91
|
-
# to allow for HTMLentities
|
92
|
-
def noko(&block)
|
93
|
-
doc = ::Nokogiri::XML.parse(NOKOHEAD)
|
94
|
-
fragment = doc.fragment("")
|
95
|
-
::Nokogiri::XML::Builder.with fragment, &block
|
96
|
-
fragment.to_xml(encoding: "US-ASCII").lines.map do |l|
|
97
|
-
l.gsub(/\s*\n/, "")
|
98
|
-
end
|
99
|
-
=begin
|
100
|
-
f = fragment.to_xml(encoding: "US-ASCII")
|
101
|
-
byebug if @xxxxxx
|
102
|
-
@xxxxxx = false
|
103
|
-
[f]
|
104
|
-
=end
|
105
|
-
end
|
106
|
-
|
107
|
-
def attr_code(attributes)
|
108
|
-
attributes = attributes.reject { |_, val| val.nil? }.map
|
109
|
-
attributes.map do |k, v|
|
110
|
-
[k, (v.is_a? String) ? HTMLEntities.new.decode(v) : v]
|
111
|
-
end.to_h
|
112
|
-
end
|
113
|
-
|
114
|
-
# if the contents of node are blocks, output them to out;
|
115
|
-
# else, wrap them in <p>
|
116
|
-
def wrap_in_para(node, out)
|
117
|
-
if node.blocks? then out << node.content
|
118
|
-
else
|
119
|
-
out.p { |p| p << node.content }
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
SUBCLAUSE_XPATH = "//clause[ancestor::clause or ancestor::annex or "\
|
124
|
-
"ancestor::introduction]".freeze
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|