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.
@@ -1,147 +1,149 @@
1
1
  require_relative "inline_simple"
2
2
 
3
- module IsoDoc::Function
4
- module Inline
5
- def link_parse(node, out)
6
- url = node["target"]
7
- node["updatetype"] == "true" and url = suffix_url(url)
8
- out.a **attr_code(href: url, title: node["alt"]) do |l|
9
- if node.text.empty?
10
- l << node["target"].sub(/^mailto:/, "")
11
- else node.children.each { |n| parse(n, l) }
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
- def callout_parse(node, out)
17
- out << " &lt;#{node.text}&gt;"
18
- end
17
+ def callout_parse(node, out)
18
+ out << " &lt;#{node.text}&gt;"
19
+ end
19
20
 
20
- def no_locality_parse(node, out)
21
- node.children.each do |n|
22
- parse(n, out) unless %w{locality localityStack}.include? n.name
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
- def xref_parse(node, out)
27
- target = if /#/.match?(node["target"])
28
- node["target"].sub(/#/, ".html#")
29
- else
30
- "##{node['target']}"
31
- end
32
- out.a(**{ "href": target }) { |l| no_locality_parse(node, l) }
33
- end
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
- def suffix_url(url)
36
- return url if %r{^https?://}.match?(url)
37
- return url unless File.extname(url).empty?
36
+ def suffix_url(url)
37
+ return url if %r{^https?://}.match?(url)
38
+ return url unless File.extname(url).empty?
38
39
 
39
- url.sub(/#{File.extname(url)}$/, ".html")
40
- end
40
+ url.sub(/#{File.extname(url)}$/, ".html")
41
+ end
41
42
 
42
- def eref_target(node)
43
- href = "##{node['bibitemid']}"
44
- url = node.at(ns("//bibitem[@id = '#{node['bibitemid']}']/"\
45
- "uri[@type = 'citation']"))
46
- return href unless url
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
- href = suffix_url(url.text)
49
- anchor = node&.at(ns(".//locality[@type = 'anchor']"))&.text&.strip
50
- anchor and href += "##{anchor}"
51
- href
52
- end
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
- def eref_parse(node, out)
55
- href = eref_target(node)
56
- if node["type"] == "footnote"
57
- out.sup do |s|
58
- s.a(**{ "href": href }) { |l| no_locality_parse(node, l) }
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
- def origin_parse(node, out)
66
- if t = node.at(ns("./termref"))
67
- termrefelem_parse(t, out)
68
- else
69
- eref_parse(node, out)
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
- def termrefelem_parse(node, out)
74
- if node.text.strip.empty?
75
- out << "Termbase #{node['base']}, term ID #{node['target']}"
76
- else
77
- node.children.each { |n| parse(n, out) }
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
- def stem_parse(node, out)
82
- ooml = case node["type"]
83
- when "AsciiMath"
84
- "#{@openmathdelim}#{HTMLEntities.new.encode(node.text)}"\
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
- when "MathML" then node.first_element_child.to_s
87
- else HTMLEntities.new.encode(node.text)
88
- end
89
- out.span **{ class: "stem" } do |span|
90
- span.parent.add_child ooml
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
- def image_title_parse(out, caption)
95
- unless caption.nil?
96
- out.p **{ class: "FigureTitle", style: "text-align:center;" } do |p|
97
- p.b { |b| b << caption.to_s }
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
- def image_parse(node, out, caption)
103
- attrs = { src: node["src"],
104
- height: node["height"] || "auto",
105
- width: node["width"] || "auto",
106
- title: node["title"],
107
- alt: node["alt"] }
108
- out.img **attr_code(attrs)
109
- image_title_parse(out, caption)
110
- end
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
- def smallcap_parse(node, xml)
113
- xml.span **{ style: "font-variant:small-caps;" } do |s|
114
- node.children.each { |n| parse(n, s) }
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
- def text_parse(node, out)
119
- return if node.nil? || node.text.nil?
119
+ def text_parse(node, out)
120
+ return if node.nil? || node.text.nil?
120
121
 
121
- text = node.to_s
122
- if in_sourcecode
123
- text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/>&nbsp;")
124
- .gsub(/ (?= )/, "&nbsp;")
122
+ text = node.to_s
123
+ if in_sourcecode
124
+ text = text.gsub("\n", "<br/>").gsub("<br/> ", "<br/>&nbsp;")
125
+ .gsub(/ (?= )/, "&nbsp;")
126
+ end
127
+ out << text
125
128
  end
126
- out << text
127
- end
128
129
 
129
- def add_parse(node, out)
130
- out.span **{ class: "addition" } do |e|
131
- node.children.each { |n| parse(n, e) }
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
- def del_parse(node, out)
136
- out.span **{ class: "deletion" } do |e|
137
- node.children.each { |n| parse(n, e) }
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
- def error_parse(node, out)
142
- text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
143
- out.para do |p|
144
- p.b(**{ role: "strong" }) { |e| e << text }
142
+ def error_parse(node, out)
143
+ text = node.to_xml.gsub(/</, "&lt;").gsub(/>/, "&gt;")
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::Function
2
- module Inline
3
- def section_break(body)
4
- body.br
5
- end
1
+ module IsoDoc
2
+ module Function
3
+ module Inline
4
+ def section_break(body)
5
+ body.br
6
+ end
6
7
 
7
- def page_break(out)
8
- out.br
9
- end
8
+ def page_break(out)
9
+ out.br
10
+ end
10
11
 
11
- def pagebreak_parse(_node, out)
12
- out.br
13
- end
12
+ def pagebreak_parse(_node, out)
13
+ out.br
14
+ end
14
15
 
15
- def hr_parse(node, out)
16
- out.hr
17
- end
16
+ def hr_parse(_node, out)
17
+ out.hr
18
+ end
18
19
 
19
- def br_parse(node, out)
20
- out.br
21
- end
20
+ def br_parse(_node, out)
21
+ out.br
22
+ end
22
23
 
23
- def index_parse(node, out)
24
- end
24
+ def index_parse(node, out); end
25
25
 
26
- def index_xref_parse(node, out)
27
- end
26
+ def index_xref_parse(node, out); end
28
27
 
29
- def bookmark_parse(node, out)
30
- out.a **attr_code(id: node["id"])
31
- end
28
+ def bookmark_parse(node, out)
29
+ out.a **attr_code(id: node["id"])
30
+ end
32
31
 
33
- def keyword_parse(node, out)
34
- out.span **{ class: "keyword" } do |s|
35
- node.children.each { |n| parse(n, s) }
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
- def em_parse(node, out)
40
- out.i do |e|
41
- node.children.each { |n| parse(n, e) }
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
- def strong_parse(node, out)
46
- out.b do |e|
47
- node.children.each { |n| parse(n, e) }
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
- def sup_parse(node, out)
52
- out.sup do |e|
53
- node.children.each { |n| parse(n, e) }
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
- def sub_parse(node, out)
58
- out.sub do |e|
59
- node.children.each { |n| parse(n, e) }
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
- def tt_parse(node, out)
64
- out.tt do |e|
65
- node.children.each { |n| parse(n, e) }
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
- def strike_parse(node, out)
70
- out.s do |e|
71
- node.children.each { |n| parse(n, e) }
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
- def underline_parse(node, out)
76
- out.u do |e|
77
- node.children.each { |n| parse(n, e) }
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::Function
2
- module Lists
3
- def ul_attrs(node)
4
- { id: node["id"], style: keep_style(node) }
5
- end
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
- def ul_parse(node, out)
8
- out.ul **attr_code(ul_attrs(node)) do |ul|
9
- node.children.each { |n| parse(n, ul) }
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
- OL_STYLE = {
14
- arabic: "1",
15
- roman: "i",
16
- alphabet: "a",
17
- roman_upper: "I",
18
- alphabet_upper: "A",
19
- }.freeze
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
- def ol_style(type)
22
- type = :alphabet unless type
23
- OL_STYLE[type.to_sym]
24
- end
22
+ def ol_style(type)
23
+ type ||= :alphabet
24
+ OL_STYLE[type.to_sym]
25
+ end
25
26
 
26
- # We don't really want users to specify type of ordered list;
27
- # we will use a fixed hierarchy as practiced by ISO (though not
28
- # fully spelled out): a) 1) i) A) I)
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
- def ol_depth(node)
31
- depth = node.ancestors("ul, ol").size + 1
32
- type = :alphabet
33
- type = :arabic if [2, 7].include? depth
34
- type = :roman if [3, 8].include? depth
35
- type = :alphabet_upper if [4, 9].include? depth
36
- type = :roman_upper if [5, 10].include? depth
37
- ol_style(type)
38
- end
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
- def ol_attrs(node)
41
- { type: node["type"] ? ol_style(node["type"].to_sym) : ol_depth(node),
42
- id: node["id"], style: keep_style(node) }
43
- end
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
- def ol_parse(node, out)
46
- out.ol **attr_code(ol_attrs(node)) do |ol|
47
- node.children.each { |n| parse(n, ol) }
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
- def li_parse(node, out)
52
- out.li **attr_code(id: node["id"]) do |li|
53
- if node["uncheckedcheckbox"] == "true"
54
- li << '<span class="zzMoveToFollowing"><input type="checkbox" checked="checked"/></span>'
55
- elsif node["checkedcheckbox"] == "true"
56
- li << '<span class="zzMoveToFollowing"><input type="checkbox"/></span>'
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
- def dt_parse(dt, term)
63
- if dt.elements.empty?
64
- #term.p **attr_code(class: note? ? "Note" : nil) do |p|
65
- term.p do |p|
66
- p << dt.text
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
- def dt_dd?(n)
74
- %w{dt dd}.include? n.name
75
- end
76
+ def dt_dd?(node)
77
+ %w{dt dd}.include? node.name
78
+ end
76
79
 
77
- def dl_attrs(node)
78
- attr_code(id: node["id"], style: keep_style(node))
79
- end
80
+ def dl_attrs(node)
81
+ attr_code(id: node["id"], style: keep_style(node))
82
+ end
80
83
 
81
- def dl_parse(node, out)
82
- out.dl **dl_attrs(node) do |v|
83
- node.elements.select { |n| dt_dd? n }.each_slice(2) do |dt, dd|
84
- v.dt **attr_code(id: dt["id"]) do |term|
85
- dt_parse(dt, term)
86
- end
87
- v.dd **attr_code(id: dd["id"]) do |listitem|
88
- dd.children.each { |n| parse(n, listitem) }
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