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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4cb60bf7b99ba880fc50c450c13da3a3f4c8ef4
4
- data.tar.gz: 762296379f74928c54b2daa1bf3c4cedf685854f
3
+ metadata.gz: bff53f9401fc6525a0bdd225bb589f4a23190307
4
+ data.tar.gz: 4c13e03922f95694c20a95f50c5f16df14254f5a
5
5
  SHA512:
6
- metadata.gz: 48b43c7cba357974da9da825abd4bf38885dadd75e5483d635e9d0dcc40c189f438b52df70272fed52a83777fcc9a88641f3ddcca1e14973b13bc40602abb46a
7
- data.tar.gz: 913a7304a51222df8a98efb8c999070a5dc3beea8bbd8fa8b66fb8d4a69681e0aa741ffef4160bff08c2e2b3eac09d22c69736c85753ae05f5db3894be65becf
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
- DEFAULT_TRANSFORMER = TransformerFactory.create do
4
- rename 'd', 'div'
5
- rename 'art', 'article'
6
- rename 'arti', 'article'
7
- rename 'sec', 'section'
8
- rename 'sect', 'section'
9
- rename 'sp', 'span'
10
-
11
- modify({type: :Root}) do
12
- if (@options[:render_parameter] ||= {})[:nonpaged]
13
- first_page = @node.first_child.remove
14
- @node.children.each do |node|
15
- if node.class == NoraMark::Page
16
- first_page.append_child block('hr', classes: ['page-break'], body_empty: true)
17
- node.remove
18
- node.children.each do |cn|
19
- first_page.append_child cn
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
- end
28
- modify(/\A(l|link)\Z/) do
29
- @node.name = 'a'
30
- (@node.attrs ||= {}).merge!({href: [@node.params[0].text]})
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
- modify 'ruby' do
34
- @node.append_child inline 'rp', '('
35
- @node.append_child inline 'rt', escape_html(@node.params[0].text.strip)
36
- @node.append_child inline 'rp', ')'
37
- end
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
- modify 'tcy' do
40
- @node.name = 'span'
41
- @node.classes = ['tcy']
42
- end
40
+ modify 'tcy' do
41
+ @node.name = 'span'
42
+ @node.classes = ['tcy']
43
+ end
43
44
 
44
- modify 'img' do
45
- @node.body_empty = true
46
- (@node.attrs ||= {}).merge!({src: [@node.params[0].text ]})
47
- @node.attrs.merge!({alt: [ escape_html(@node.params[1].text.strip)]}) if (@node.p.size > 1 && @node.params[1].text.size > 0)
48
- end
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
- replace 'image' do
51
- newnode = block('figure',
52
- class_if_empty:'img-wrap',
53
- ids: @node.ids,
54
- children: [ inline('img', nil, attrs: {src: [ @node.params[0].text.strip], alt: [ (@node.params[1].text ||'').strip ] }) ],
55
- template: @node)
56
- if !@node.children_empty?
57
- if @node.n[:caption_before]
58
- newnode.prepend_child inline('figcaption', @node.children)
59
- else
60
- newnode.append_child inline('figcaption', @node.children)
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
- replace({type: :OrderedList}) do
67
- block('ol', template: @node)
68
- end
67
+ replace({type: :OrderedList}) do
68
+ block('ol', template: @node)
69
+ end
69
70
 
70
- replace({type: :UnorderedList}) do
71
- block('ul', template: @node)
72
- end
71
+ replace({type: :UnorderedList}) do
72
+ block('ul', template: @node)
73
+ end
73
74
 
74
- replace({type: :UlItem}) do
75
- block('li', template: @node)
76
- end
75
+ replace({type: :UlItem}) do
76
+ block('li', template: @node)
77
+ end
77
78
 
78
- replace({type: :OlItem}) do
79
- block('li', template: @node)
80
- end
79
+ replace({type: :OlItem}) do
80
+ block('li', template: @node)
81
+ end
81
82
 
82
- replace({type: :DefinitionList}) do
83
- block('dl', template: @node)
84
- end
83
+ replace({type: :DefinitionList}) do
84
+ block('dl', template: @node)
85
+ end
85
86
 
86
- replace({type: :DLItem}) do
87
- [
88
- block('dt', @node.p[0], n: {chop_last_space: true}),
89
- block('dd', @node.children)
90
- ]
91
- end
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
- replace({type: :Breakline}) do
94
- newnode = block('br')
95
- newnode.body_empty = true
96
- newnode
97
- end
94
+ replace({type: :Breakline}) do
95
+ newnode = block('br')
96
+ newnode.body_empty = true
97
+ newnode
98
+ end
98
99
 
99
- replace({type: :HeadedSection}) do
100
- block('section', [ block("h#{@node.level}", @node.heading, ids: @node.n[:heading_id], n: {chop_last_space: true}) ] + @node.children, template: @node)
101
- end
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
- replace ({type: :CodeInline}) do
104
- inline('code', @node.content, line_no: @node.line_no, template: @node)
105
- end
106
-
107
- replace ({type: :PreformattedBlock}) do
108
- new_node = block('pre')
109
- if @node.codelanguage
110
- new_node.attrs = {'data-code-language' => [@node.codelanguage]}
111
- new_node.classes = (@node.classes ||[]) << "code-#{@node.codelanguage}"
112
- end
113
- if @node.name == 'code'
114
- code = block('code', text(@node.content.join("\n"), raw_text: true))
115
- new_node.children = [ code ]
116
- else
117
- new_node.children = [ text(@node.content.join("\n"), raw_text: true) ]
118
- end
119
- if (@node.p || []).size> 0
120
- method = @node.n[:caption_after] ? :prepend : :append
121
- new_node = new_node.wrap block('div', classes: ['pre'], children: [ block('p', children: @node.p.shift, classes: ['caption']) ]), method
122
- end
123
- new_node
124
- end
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
- modify 'video' do
127
- @node.attrs ||= {}
128
- @node.attrs.merge!({src: [@node.p.shift.text]})
129
- @node.attrs.merge!({poster: [@node.n[:poster]]}) unless @node.n[:poster].nil?
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
- options = @node.p.map { |opt| opt.text.strip }
132
- ['autoplay', 'controls', 'loop', 'muted'].each do
133
- |attr|
134
- @node.attrs.merge!({attr.to_sym => true}) if options.member? attr
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
- modify 'audio' do
139
- @node.attrs ||= {}
140
- @node.attrs.merge!({src: [@node.p.shift.text]})
141
- @node.attrs.merge!({volume: [@node.n[:volume]]}) unless @node.n[:volume].nil?
142
- options = @node.p.map { |opt| opt.text.strip }
143
- ['autoplay', 'controls', 'loop', 'muted'].each do
144
- |attr|
145
- @node.attrs.merge!({attr.to_sym => true}) if options.member? attr
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
- DEFAULT_TRANSFORMER.options[:render_parameter] = render_parameter
82
- @parsed_result = DEFAULT_TRANSFORMER.transform parsed_result
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
@@ -1,3 +1,3 @@
1
1
  module NoraMark
2
- VERSION = "0.2beta10"
2
+ VERSION = "0.2beta11"
3
3
  end
@@ -0,0 +1,14 @@
1
+ module NoraMark
2
+ module Tester
3
+ class Generator
4
+ def self.name
5
+ :tester
6
+ end
7
+ def initialize(param = {})
8
+ end
9
+ def convert(parsed_result, render_parameter = {})
10
+ 'it is just a test.'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -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.2beta10
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