nora_mark 0.2beta10 → 0.2beta11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nora_mark/generator.rb +0 -0
- data/lib/nora_mark/html/default_transformer.rb +125 -121
- data/lib/nora_mark/html/generator.rb +3 -2
- data/lib/nora_mark/html/tag_writer.rb +5 -0
- data/lib/nora_mark/version.rb +1 -1
- data/spec/fixtures/test-plugins/nora_mark_tester.rb +14 -0
- data/spec/nora_mark_spec.rb +12 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bff53f9401fc6525a0bdd225bb589f4a23190307
|
4
|
+
data.tar.gz: 4c13e03922f95694c20a95f50c5f16df14254f5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 196f90eafc13171a5fcd7c59c126ffc5e5ef83f0329d7d6630aa25afdf6c1800e9045b6cc20c93a4d7db23ec3b0ea347526c1d7dc165ab9b48683d793cc7e658
|
7
|
+
data.tar.gz: 2cbf86b01d093cb5a3745495a84fb76e1e17ffa3e473a0e7f71db274499984c0e333b0adbbf240d6248fc10f58f52aa5f7085ef031834dce538d5d42e3065532
|
File without changes
|
@@ -1,151 +1,155 @@
|
|
1
1
|
module NoraMark
|
2
2
|
module Html
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
def self.default_transformer
|
4
|
+
transformer = TransformerFactory.create do
|
5
|
+
rename 'd', 'div'
|
6
|
+
rename 'art', 'article'
|
7
|
+
rename 'arti', 'article'
|
8
|
+
rename 'sec', 'section'
|
9
|
+
rename 'sect', 'section'
|
10
|
+
rename 'sp', 'span'
|
11
|
+
|
12
|
+
modify({type: :Root}) do
|
13
|
+
if (@options[:render_parameter] ||= {})[:nonpaged]
|
14
|
+
first_page = @node.first_child.remove
|
15
|
+
@node.children.each do |node|
|
16
|
+
if node.class == NoraMark::Page
|
17
|
+
first_page.append_child block('hr', classes: ['page-break'], body_empty: true)
|
18
|
+
node.remove
|
19
|
+
node.children.each do |cn|
|
20
|
+
first_page.append_child cn
|
21
|
+
end
|
22
|
+
else
|
23
|
+
first_page.append_child node
|
20
24
|
end
|
21
|
-
else
|
22
|
-
first_page.append_child node
|
23
25
|
end
|
26
|
+
@node.prepend_child first_page
|
24
27
|
end
|
25
|
-
@node.prepend_child first_page
|
26
28
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
29
|
+
modify(/\A(l|link)\Z/) do
|
30
|
+
@node.name = 'a'
|
31
|
+
(@node.attrs ||= {}).merge!({href: [@node.params[0].text]})
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
modify 'ruby' do
|
35
|
+
@node.append_child inline 'rp', '('
|
36
|
+
@node.append_child inline 'rt', escape_html(@node.params[0].text.strip)
|
37
|
+
@node.append_child inline 'rp', ')'
|
38
|
+
end
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
modify 'tcy' do
|
41
|
+
@node.name = 'span'
|
42
|
+
@node.classes = ['tcy']
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
modify 'img' do
|
46
|
+
@node.body_empty = true
|
47
|
+
(@node.attrs ||= {}).merge!({src: [@node.params[0].text ]})
|
48
|
+
@node.attrs.merge!({alt: [ escape_html(@node.params[1].text.strip)]}) if (@node.p.size > 1 && @node.params[1].text.size > 0)
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
replace 'image' do
|
52
|
+
newnode = block('figure',
|
53
|
+
class_if_empty:'img-wrap',
|
54
|
+
ids: @node.ids,
|
55
|
+
children: [ inline('img', nil, attrs: {src: [ @node.params[0].text.strip], alt: [ (@node.params[1].text ||'').strip ] }) ],
|
56
|
+
template: @node)
|
57
|
+
if !@node.children_empty?
|
58
|
+
if @node.n[:caption_before]
|
59
|
+
newnode.prepend_child inline('figcaption', @node.children)
|
60
|
+
else
|
61
|
+
newnode.append_child inline('figcaption', @node.children)
|
62
|
+
end
|
61
63
|
end
|
64
|
+
newnode
|
62
65
|
end
|
63
|
-
newnode
|
64
|
-
end
|
65
66
|
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
replace({type: :OrderedList}) do
|
68
|
+
block('ol', template: @node)
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
-
|
72
|
-
|
71
|
+
replace({type: :UnorderedList}) do
|
72
|
+
block('ul', template: @node)
|
73
|
+
end
|
73
74
|
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
replace({type: :UlItem}) do
|
76
|
+
block('li', template: @node)
|
77
|
+
end
|
77
78
|
|
78
|
-
|
79
|
-
|
80
|
-
|
79
|
+
replace({type: :OlItem}) do
|
80
|
+
block('li', template: @node)
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
replace({type: :DefinitionList}) do
|
84
|
+
block('dl', template: @node)
|
85
|
+
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
87
|
+
replace({type: :DLItem}) do
|
88
|
+
[
|
89
|
+
block('dt', @node.p[0], n: {chop_last_space: true}),
|
90
|
+
block('dd', @node.children)
|
91
|
+
]
|
92
|
+
end
|
92
93
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
replace({type: :Breakline}) do
|
95
|
+
newnode = block('br')
|
96
|
+
newnode.body_empty = true
|
97
|
+
newnode
|
98
|
+
end
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
replace({type: :HeadedSection}) do
|
101
|
+
block('section', [ block("h#{@node.level}", @node.heading, ids: @node.n[:heading_id], n: {chop_last_space: true}) ] + @node.children, template: @node)
|
102
|
+
end
|
102
103
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
104
|
+
replace ({type: :CodeInline}) do
|
105
|
+
inline('code', @node.content, line_no: @node.line_no, template: @node)
|
106
|
+
end
|
107
|
+
|
108
|
+
replace ({type: :PreformattedBlock}) do
|
109
|
+
new_node = block('pre')
|
110
|
+
if @node.codelanguage
|
111
|
+
new_node.attrs = @node.attrs
|
112
|
+
new_node.add_attr 'data-code-language' => [@node.codelanguage]
|
113
|
+
new_node.classes = (@node.classes ||[]) << "code-#{@node.codelanguage}"
|
114
|
+
end
|
115
|
+
if @node.name == 'code'
|
116
|
+
code = block('code', text(@node.content.join("\n"), raw_text: true))
|
117
|
+
new_node.children = [ code ]
|
118
|
+
else
|
119
|
+
new_node.children = [ text(@node.content.join("\n"), raw_text: true) ]
|
120
|
+
end
|
121
|
+
if (@node.p || []).size> 0
|
122
|
+
method = @node.n[:caption_after] ? :prepend : :append
|
123
|
+
new_node = new_node.wrap block('div', classes: ['pre'], children: [ block('p', children: @node.p.shift, classes: ['caption']) ]), method
|
124
|
+
end
|
125
|
+
new_node
|
126
|
+
end
|
125
127
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
128
|
+
modify 'video' do
|
129
|
+
@node.attrs ||= {}
|
130
|
+
@node.attrs.merge!({src: [@node.p.shift.text]})
|
131
|
+
@node.attrs.merge!({poster: [@node.n[:poster]]}) unless @node.n[:poster].nil?
|
130
132
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
133
|
+
options = @node.p.map { |opt| opt.text.strip }
|
134
|
+
['autoplay', 'controls', 'loop', 'muted'].each do
|
135
|
+
|attr|
|
136
|
+
@node.attrs.merge!({attr.to_sym => true}) if options.member? attr
|
137
|
+
end
|
135
138
|
end
|
136
|
-
end
|
137
139
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
140
|
+
modify 'audio' do
|
141
|
+
@node.attrs ||= {}
|
142
|
+
@node.attrs.merge!({src: [@node.p.shift.text]})
|
143
|
+
@node.attrs.merge!({volume: [@node.n[:volume]]}) unless @node.n[:volume].nil?
|
144
|
+
options = @node.p.map { |opt| opt.text.strip }
|
145
|
+
['autoplay', 'controls', 'loop', 'muted'].each do
|
146
|
+
|attr|
|
147
|
+
@node.attrs.merge!({attr.to_sym => true}) if options.member? attr
|
148
|
+
end
|
146
149
|
end
|
147
150
|
end
|
151
|
+
transformer.extend Util
|
152
|
+
transformer
|
148
153
|
end
|
149
|
-
DEFAULT_TRANSFORMER.extend Util
|
150
154
|
end
|
151
155
|
end
|
@@ -78,8 +78,9 @@ module NoraMark
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def convert(parsed_result, render_parameter = {})
|
81
|
-
|
82
|
-
|
81
|
+
transformer = Html.default_transformer
|
82
|
+
transformer.options[:render_parameter] = render_parameter
|
83
|
+
@parsed_result = transformer.transform parsed_result
|
83
84
|
assign_id_to_headings
|
84
85
|
|
85
86
|
children = parsed_result.children
|
@@ -57,6 +57,11 @@ module NoraMark
|
|
57
57
|
ids = node.ids || []
|
58
58
|
classes = node.classes || []
|
59
59
|
attr = node.attrs || {}
|
60
|
+
node.n.each { |k,v|
|
61
|
+
if k.to_s.start_with? 'data-'
|
62
|
+
attr.merge!({ k => [ v ] })
|
63
|
+
end
|
64
|
+
}
|
60
65
|
tag_name = @tag_name || node.name
|
61
66
|
@context << "<#{tag_name}#{ids_string(ids)}#{class_string(classes)}#{attr_string(attr)}"
|
62
67
|
if node.body_empty
|
data/lib/nora_mark/version.rb
CHANGED
data/spec/nora_mark_spec.rb
CHANGED
@@ -149,6 +149,18 @@ describe NoraMark::Document do
|
|
149
149
|
)
|
150
150
|
end
|
151
151
|
end
|
152
|
+
describe 'attribute handling' do
|
153
|
+
it 'accept data- named parameter as attributes' do
|
154
|
+
noramark = NoraMark::Document.parse('[span[data-type:foobar]{lorem ipsum}]')
|
155
|
+
converted = noramark.html
|
156
|
+
body = Nokogiri::XML::Document.parse(converted[0]).root.at_xpath('xmlns:body')
|
157
|
+
expect(body.element_children[0].selector_and_children)
|
158
|
+
.to eq(
|
159
|
+
['p',
|
160
|
+
["span[data-type='foobar']", 'lorem ipsum']]
|
161
|
+
)
|
162
|
+
end
|
163
|
+
end
|
152
164
|
describe 'divs and hN headers' do
|
153
165
|
it 'parse paragraph with header' do
|
154
166
|
text = "h1: タイトルです。\r\nここから、パラグラフがはじまります。\n\nh2.column:ふたつめの見出しです。\n ここから、次のパラグラフです。\nh3.third.foo: クラスが複数ある見出しです"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nora_mark
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2beta11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- KOJIMA Satoshi
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/nora_mark.rb
|
106
106
|
- lib/nora_mark/document.rb
|
107
107
|
- lib/nora_mark/extensions.rb
|
108
|
+
- lib/nora_mark/generator.rb
|
108
109
|
- lib/nora_mark/html/abstract_node_writer.rb
|
109
110
|
- lib/nora_mark/html/context.rb
|
110
111
|
- lib/nora_mark/html/default_transformer.rb
|
@@ -202,6 +203,7 @@ files:
|
|
202
203
|
- spec/epub30-schemas/package-30.rnc
|
203
204
|
- spec/epub30-schemas/package-30.sch
|
204
205
|
- spec/extensions_spec.rb
|
206
|
+
- spec/fixtures/test-plugins/nora_mark_tester.rb
|
205
207
|
- spec/jing-20091111/bin/jing.jar
|
206
208
|
- spec/node_spec.rb
|
207
209
|
- spec/nokogiri_test_helper.rb
|
@@ -311,6 +313,7 @@ test_files:
|
|
311
313
|
- spec/epub30-schemas/package-30.rnc
|
312
314
|
- spec/epub30-schemas/package-30.sch
|
313
315
|
- spec/extensions_spec.rb
|
316
|
+
- spec/fixtures/test-plugins/nora_mark_tester.rb
|
314
317
|
- spec/jing-20091111/bin/jing.jar
|
315
318
|
- spec/node_spec.rb
|
316
319
|
- spec/nokogiri_test_helper.rb
|