isodoc 1.7.3.1 → 1.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/isodoc.gemspec +1 -0
- data/lib/isodoc/convert.rb +1 -0
- data/lib/isodoc/function/blocks_example_note.rb +85 -79
- data/lib/isodoc/function/cleanup.rb +181 -175
- data/lib/isodoc/function/inline.rb +110 -108
- data/lib/isodoc/function/inline_simple.rb +55 -55
- data/lib/isodoc/function/lists.rb +75 -71
- data/lib/isodoc/function/references.rb +165 -160
- data/lib/isodoc/function/section.rb +140 -190
- data/lib/isodoc/function/section_titles.rb +82 -0
- data/lib/isodoc/function/table.rb +90 -87
- data/lib/isodoc/function/terms.rb +58 -56
- data/lib/isodoc/function/to_word_html.rb +1 -0
- data/lib/isodoc/html_function/mathvariant_to_plain.rb +5 -3
- data/lib/isodoc/presentation_function/math.rb +9 -0
- data/lib/isodoc/presentation_function/section.rb +12 -1
- data/lib/isodoc/presentation_xml_convert.rb +2 -0
- data/lib/isodoc/version.rb +1 -1
- data/lib/isodoc/word_function/body.rb +5 -5
- data/lib/isodoc/xslfo_convert.rb +2 -2
- data/spec/isodoc/blocks_spec.rb +147 -64
- data/spec/isodoc/inline_spec.rb +190 -89
- data/spec/isodoc/presentation_xml_spec.rb +84 -0
- data/spec/isodoc/section_spec.rb +639 -0
- metadata +17 -2
@@ -1,147 +1,149 @@
|
|
1
1
|
require_relative "inline_simple"
|
2
2
|
|
3
|
-
module IsoDoc
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
module IsoDoc
|
4
|
+
module Function
|
5
|
+
module Inline
|
6
|
+
def link_parse(node, out)
|
7
|
+
url = node["target"]
|
8
|
+
node["updatetype"] == "true" and url = suffix_url(url)
|
9
|
+
out.a **attr_code(href: url, title: node["alt"]) do |l|
|
10
|
+
if node.text.empty?
|
11
|
+
l << node["target"].sub(/^mailto:/, "")
|
12
|
+
else node.children.each { |n| parse(n, l) }
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
|
-
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def callout_parse(node, out)
|
18
|
+
out << " <#{node.text}>"
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def no_locality_parse(node, out)
|
22
|
+
node.children.each do |n|
|
23
|
+
parse(n, out) unless %w{locality localityStack}.include? n.name
|
24
|
+
end
|
23
25
|
end
|
24
|
-
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
def xref_parse(node, out)
|
28
|
+
target = if /#/.match?(node["target"])
|
29
|
+
node["target"].sub(/#/, ".html#")
|
30
|
+
else
|
31
|
+
"##{node['target']}"
|
32
|
+
end
|
33
|
+
out.a(**{ href: target }) { |l| no_locality_parse(node, l) }
|
34
|
+
end
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
36
|
+
def suffix_url(url)
|
37
|
+
return url if %r{^https?://}.match?(url)
|
38
|
+
return url unless File.extname(url).empty?
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
url.sub(/#{File.extname(url)}$/, ".html")
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
def eref_target(node)
|
44
|
+
href = "##{node['bibitemid']}"
|
45
|
+
url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\
|
46
|
+
"uri[@type = 'citation']"))
|
47
|
+
return href unless url
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
href = suffix_url(url.text)
|
50
|
+
anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
|
51
|
+
anchor and href += "##{anchor}"
|
52
|
+
href
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
def eref_parse(node, out)
|
56
|
+
href = eref_target(node)
|
57
|
+
if node["type"] == "footnote"
|
58
|
+
out.sup do |s|
|
59
|
+
s.a(**{ href: href }) { |l| no_locality_parse(node, l) }
|
60
|
+
end
|
61
|
+
else
|
62
|
+
out.a(**{ href: href }) { |l| no_locality_parse(node, l) }
|
59
63
|
end
|
60
|
-
else
|
61
|
-
out.a(**{ "href": href }) { |l| no_locality_parse(node, l) }
|
62
64
|
end
|
63
|
-
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
66
|
+
def origin_parse(node, out)
|
67
|
+
if t = node.at(ns("./termref"))
|
68
|
+
termrefelem_parse(t, out)
|
69
|
+
else
|
70
|
+
eref_parse(node, out)
|
71
|
+
end
|
70
72
|
end
|
71
|
-
end
|
72
73
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
def termrefelem_parse(node, out)
|
75
|
+
if node.text.strip.empty?
|
76
|
+
out << "Termbase #{node['base']}, term ID #{node['target']}"
|
77
|
+
else
|
78
|
+
node.children.each { |n| parse(n, out) }
|
79
|
+
end
|
78
80
|
end
|
79
|
-
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
def stem_parse(node, out)
|
83
|
+
ooml = case node["type"]
|
84
|
+
when "AsciiMath"
|
85
|
+
"#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
|
85
86
|
"#{@closemathdelim}"
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
when "MathML" then node.first_element_child.to_s
|
88
|
+
else HTMLEntities.new.encode(node.text)
|
89
|
+
end
|
90
|
+
out.span **{ class: "stem" } do |span|
|
91
|
+
span.parent.add_child ooml
|
92
|
+
end
|
91
93
|
end
|
92
|
-
end
|
93
94
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
def image_title_parse(out, caption)
|
96
|
+
unless caption.nil?
|
97
|
+
out.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
|
98
|
+
p.b { |b| b << caption.to_s }
|
99
|
+
end
|
98
100
|
end
|
99
101
|
end
|
100
|
-
end
|
101
102
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
103
|
+
def image_parse(node, out, caption)
|
104
|
+
attrs = { src: node["src"],
|
105
|
+
height: node["height"] || "auto",
|
106
|
+
width: node["width"] || "auto",
|
107
|
+
title: node["title"],
|
108
|
+
alt: node["alt"] }
|
109
|
+
out.img **attr_code(attrs)
|
110
|
+
image_title_parse(out, caption)
|
111
|
+
end
|
111
112
|
|
112
|
-
|
113
|
-
|
114
|
-
|
113
|
+
def smallcap_parse(node, xml)
|
114
|
+
xml.span **{ style: "font-variant:small-caps;" } do |s|
|
115
|
+
node.children.each { |n| parse(n, s) }
|
116
|
+
end
|
115
117
|
end
|
116
|
-
end
|
117
118
|
|
118
|
-
|
119
|
-
|
119
|
+
def text_parse(node, out)
|
120
|
+
return if node.nil? || node.text.nil?
|
120
121
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
122
|
+
text = node.to_s
|
123
|
+
if in_sourcecode
|
124
|
+
text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/> ")
|
125
|
+
.gsub(/ (?= )/, " ")
|
126
|
+
end
|
127
|
+
out << text
|
125
128
|
end
|
126
|
-
out << text
|
127
|
-
end
|
128
129
|
|
129
|
-
|
130
|
-
|
131
|
-
|
130
|
+
def add_parse(node, out)
|
131
|
+
out.span **{ class: "addition" } do |e|
|
132
|
+
node.children.each { |n| parse(n, e) }
|
133
|
+
end
|
132
134
|
end
|
133
|
-
end
|
134
135
|
|
135
|
-
|
136
|
-
|
137
|
-
|
136
|
+
def del_parse(node, out)
|
137
|
+
out.span **{ class: "deletion" } do |e|
|
138
|
+
node.children.each { |n| parse(n, e) }
|
139
|
+
end
|
138
140
|
end
|
139
|
-
end
|
140
141
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
def error_parse(node, out)
|
143
|
+
text = node.to_xml.gsub(/</, "<").gsub(/>/, ">")
|
144
|
+
out.para do |p|
|
145
|
+
p.b(**{ role: "strong" }) { |e| e << text }
|
146
|
+
end
|
145
147
|
end
|
146
148
|
end
|
147
149
|
end
|
@@ -1,80 +1,80 @@
|
|
1
|
-
module IsoDoc
|
2
|
-
module
|
3
|
-
|
4
|
-
body
|
5
|
-
|
1
|
+
module IsoDoc
|
2
|
+
module Function
|
3
|
+
module Inline
|
4
|
+
def section_break(body)
|
5
|
+
body.br
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def page_break(out)
|
9
|
+
out.br
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
def pagebreak_parse(_node, out)
|
13
|
+
out.br
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def hr_parse(_node, out)
|
17
|
+
out.hr
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def br_parse(_node, out)
|
21
|
+
out.br
|
22
|
+
end
|
22
23
|
|
23
|
-
|
24
|
-
end
|
24
|
+
def index_parse(node, out); end
|
25
25
|
|
26
|
-
|
27
|
-
end
|
26
|
+
def index_xref_parse(node, out); end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def bookmark_parse(node, out)
|
29
|
+
out.a **attr_code(id: node["id"])
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def keyword_parse(node, out)
|
33
|
+
out.span **{ class: "keyword" } do |s|
|
34
|
+
node.children.each { |n| parse(n, s) }
|
35
|
+
end
|
36
36
|
end
|
37
|
-
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
def em_parse(node, out)
|
39
|
+
out.i do |e|
|
40
|
+
node.children.each { |n| parse(n, e) }
|
41
|
+
end
|
42
42
|
end
|
43
|
-
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
def strong_parse(node, out)
|
45
|
+
out.b do |e|
|
46
|
+
node.children.each { |n| parse(n, e) }
|
47
|
+
end
|
48
48
|
end
|
49
|
-
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def sup_parse(node, out)
|
51
|
+
out.sup do |e|
|
52
|
+
node.children.each { |n| parse(n, e) }
|
53
|
+
end
|
54
54
|
end
|
55
|
-
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
def sub_parse(node, out)
|
57
|
+
out.sub do |e|
|
58
|
+
node.children.each { |n| parse(n, e) }
|
59
|
+
end
|
60
60
|
end
|
61
|
-
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
62
|
+
def tt_parse(node, out)
|
63
|
+
out.tt do |e|
|
64
|
+
node.children.each { |n| parse(n, e) }
|
65
|
+
end
|
66
66
|
end
|
67
|
-
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
def strike_parse(node, out)
|
69
|
+
out.s do |e|
|
70
|
+
node.children.each { |n| parse(n, e) }
|
71
|
+
end
|
72
72
|
end
|
73
|
-
end
|
74
73
|
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
def underline_parse(node, out)
|
75
|
+
out.u do |e|
|
76
|
+
node.children.each { |n| parse(n, e) }
|
77
|
+
end
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
@@ -1,95 +1,99 @@
|
|
1
|
-
module IsoDoc
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module IsoDoc
|
2
|
+
module Function
|
3
|
+
module Lists
|
4
|
+
def ul_attrs(node)
|
5
|
+
{ id: node["id"], style: keep_style(node) }
|
6
|
+
end
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
def ul_parse(node, out)
|
9
|
+
out.ul **attr_code(ul_attrs(node)) do |ul|
|
10
|
+
node.children.each { |n| parse(n, ul) }
|
11
|
+
end
|
10
12
|
end
|
11
|
-
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
OL_STYLE = {
|
15
|
+
arabic: "1",
|
16
|
+
roman: "i",
|
17
|
+
alphabet: "a",
|
18
|
+
roman_upper: "I",
|
19
|
+
alphabet_upper: "A",
|
20
|
+
}.freeze
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def ol_style(type)
|
23
|
+
type ||= :alphabet
|
24
|
+
OL_STYLE[type.to_sym]
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
# We don't really want users to specify type of ordered list;
|
28
|
+
# we will use a fixed hierarchy as practiced by ISO (though not
|
29
|
+
# fully spelled out): a) 1) i) A) I)
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
31
|
+
def ol_depth(node)
|
32
|
+
depth = node.ancestors("ul, ol").size + 1
|
33
|
+
type = :alphabet
|
34
|
+
type = :arabic if [2, 7].include? depth
|
35
|
+
type = :roman if [3, 8].include? depth
|
36
|
+
type = :alphabet_upper if [4, 9].include? depth
|
37
|
+
type = :roman_upper if [5, 10].include? depth
|
38
|
+
ol_style(type)
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def ol_attrs(node)
|
42
|
+
{ type: node["type"] ? ol_style(node["type"].to_sym) : ol_depth(node),
|
43
|
+
id: node["id"], style: keep_style(node) }
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
def ol_parse(node, out)
|
47
|
+
out.ol **attr_code(ol_attrs(node)) do |ol|
|
48
|
+
node.children.each { |n| parse(n, ol) }
|
49
|
+
end
|
48
50
|
end
|
49
|
-
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
def li_parse(node, out)
|
53
|
+
out.li **attr_code(id: node["id"]) do |li|
|
54
|
+
if node["uncheckedcheckbox"] == "true"
|
55
|
+
li << '<span class="zzMoveToFollowing">'\
|
56
|
+
'<input type="checkbox" checked="checked"/></span>'
|
57
|
+
elsif node["checkedcheckbox"] == "true"
|
58
|
+
li << '<span class="zzMoveToFollowing">'\
|
59
|
+
'<input type="checkbox"/></span>'
|
60
|
+
end
|
61
|
+
node.children.each { |n| parse(n, li) }
|
57
62
|
end
|
58
|
-
node.children.each { |n| parse(n, li) }
|
59
63
|
end
|
60
|
-
end
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
def dt_parse(dterm, term)
|
66
|
+
if dterm.elements.empty?
|
67
|
+
# term.p **attr_code(class: note? ? "Note" : nil) do |p|
|
68
|
+
term.p do |p|
|
69
|
+
p << dterm.text
|
70
|
+
end
|
71
|
+
else
|
72
|
+
dterm.children.each { |n| parse(n, term) }
|
67
73
|
end
|
68
|
-
else
|
69
|
-
dt.children.each { |n| parse(n, term) }
|
70
74
|
end
|
71
|
-
end
|
72
75
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
+
def dt_dd?(node)
|
77
|
+
%w{dt dd}.include? node.name
|
78
|
+
end
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
def dl_attrs(node)
|
81
|
+
attr_code(id: node["id"], style: keep_style(node))
|
82
|
+
end
|
80
83
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
84
|
+
def dl_parse(node, out)
|
85
|
+
out.dl **dl_attrs(node) do |v|
|
86
|
+
node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
|
87
|
+
v.dt **attr_code(id: dt["id"]) do |term|
|
88
|
+
dt_parse(dt, term)
|
89
|
+
end
|
90
|
+
v.dd **attr_code(id: dd["id"]) do |listitem|
|
91
|
+
dd.children.each { |n| parse(n, listitem) }
|
92
|
+
end
|
89
93
|
end
|
90
94
|
end
|
95
|
+
node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, out) }
|
91
96
|
end
|
92
|
-
node.elements.reject { |n| dt_dd? n }.each { |n| parse(n, out) }
|
93
97
|
end
|
94
98
|
end
|
95
99
|
end
|