pseudohikiparser 0.0.5.develop → 0.0.5

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: 5be7e5cb75ef3ae2d601b8dbf03aa768c5d0e1c1
4
- data.tar.gz: 6d9de4c42fa1339e0922903764c07cd8edc13c5e
3
+ metadata.gz: 5ebc8c1ea077d8299c8d99b805fbed3ddc4f45e4
4
+ data.tar.gz: 02fc8e556784f1bbbe63c6e2a0bcf369c4b0ec04
5
5
  SHA512:
6
- metadata.gz: 2d5e5d27c733773551dc372df645933aa14d3db2c5c212d73646010db2fc59c6756ba13c37c662b9f5e56f48ebba4e98f014c853d8ab9c7e9cb53c628f645dbc
7
- data.tar.gz: 9bb79366e51c3ca3f0c6d51abdcdd7f399d905130113ae86d0311f16734258da159f3824727c436ca6551f3a233fb2cf50bd861f65233ec76d617e4e426a6445
6
+ metadata.gz: c48347a4e2cd673bbc426c0623255d8a64088d393730a5bdbba4962ca626b5ab8dad09bdb48abc64fd0fd307551d69dac7ae99a053ac7d230406ff9dc94ccc94
7
+ data.tar.gz: ca8187e15865fd7bd5e9d5def177dcf11f4ce843af06412f79e14b44cfdc649eece0487c7ab3f6397057afa1a2c45165b91153198697b79fceb9c4128f791c63
@@ -38,21 +38,14 @@ module PseudoHiki
38
38
  end
39
39
 
40
40
  class BlockStack < TreeStack
41
- attr_reader :stack
42
-
43
- def pop_with_breaker(breaker=nil)
44
- current_node.parse_leafs(breaker)
45
- pop
46
- end
47
-
48
- def current_heading_level
49
- i = @stack.rindex {|node| node.kind_of? BlockElement::HeadingNode }
50
- @stack[i].level || 0
41
+ def pop
42
+ current_node.parse_leafs
43
+ super
51
44
  end
52
45
  end
53
46
 
54
47
  class BlockLeaf < BlockStack::Leaf
55
- attr_accessor :level, :node_id, :decorator
48
+ attr_accessor :level, :node_id
56
49
 
57
50
  class << self
58
51
  attr_accessor :head_re
@@ -88,7 +81,7 @@ module PseudoHiki
88
81
  super(stack)
89
82
  end
90
83
 
91
- def parse_leafs(breaker)
84
+ def parse_leafs
92
85
  parsed = InlineParser.parse(join)
93
86
  clear
94
87
  concat(parsed)
@@ -138,10 +131,6 @@ module PseudoHiki
138
131
  first.level if first # @cached_level ||= (first.level if first)
139
132
  end
140
133
 
141
- def decorator
142
- first.decorator if first
143
- end
144
-
145
134
  def push_self(stack)
146
135
  @stack = stack
147
136
  super(stack)
@@ -151,11 +140,11 @@ module PseudoHiki
151
140
  not (kind_of? breaker.block and level == breaker.level)
152
141
  end
153
142
 
154
- def parse_leafs(breaker); end
143
+ def parse_leafs; end
155
144
 
156
145
  def add_leaf(line, blockparser)
157
146
  leaf = create_leaf(line, blockparser)
158
- blockparser.stack.pop_with_breaker(leaf) while blockparser.breakable?(leaf)
147
+ blockparser.stack.pop while blockparser.breakable?(leaf)
159
148
  blockparser.stack.push leaf
160
149
  end
161
150
 
@@ -167,8 +156,8 @@ module PseudoHiki
167
156
  end
168
157
 
169
158
  class NonNestedBlockNode < BlockNode
170
- def parse_leafs(breaker)
171
- each {|leaf| leaf.parse_leafs(breaker) }
159
+ def parse_leafs
160
+ each {|leaf| leaf.parse_leafs }
172
161
  end
173
162
  end
174
163
 
@@ -186,15 +175,13 @@ module PseudoHiki
186
175
  end
187
176
  end
188
177
 
189
- class UnmatchedSectioningTagError < StandardError; end
190
-
191
178
  module BlockElement
192
179
  {
193
- BlockLeaf => %w(DescLeaf VerbatimLeaf TableLeaf CommentOutLeaf BlockNodeEnd HrLeaf DecoratorLeaf SectioningNodeEnd),
180
+ BlockLeaf => %w(DescLeaf VerbatimLeaf TableLeaf CommentOutLeaf BlockNodeEnd HrLeaf),
194
181
  NonNestedBlockLeaf => %w(QuoteLeaf ParagraphLeaf),
195
182
  NestedBlockLeaf => %w(HeadingLeaf),
196
183
  ListTypeLeaf => %w(ListLeaf EnumLeaf),
197
- BlockNode => %w(DescNode VerbatimNode TableNode CommentOutNode HrNode DecoratorNode SectioningNode),
184
+ BlockNode => %w(DescNode VerbatimNode TableNode CommentOutNode HrNode),
198
185
  NonNestedBlockNode => %w(QuoteNode ParagraphNode),
199
186
  NestedBlockNode => %w(HeadingNode),
200
187
  ListTypeBlockNode => %w(ListNode EnumNode),
@@ -217,100 +204,15 @@ module PseudoHiki
217
204
  attr_accessor :in_block_tag
218
205
 
219
206
  def add_leaf(line, blockparser)
220
- return @stack.pop_with_breaker if VERBATIM_END =~ line
207
+ return @stack.pop if VERBATIM_END =~ line
221
208
  return super(line, blockparser) unless @in_block_tag
222
209
  line = " #{line}" if BlockNodeEnd.head_re =~ line and not @in_block_tag
223
210
  @stack.push VerbatimLeaf.create(line, @in_block_tag)
224
211
  end
225
212
  end
226
213
 
227
- class DecoratorNode
228
- DECORATOR_PAT = /\A(?:([^\[\]:]+))?(?:\[([^\[\]]+)\])?(?::\s*(\S.*))?/o
229
- LABEL_SEP = [":"]
230
-
231
- class DecoratorItem < Struct.new(:string, :type, :id, :value)
232
- def self.create(leaf)
233
- m = DECORATOR_PAT.match(leaf.join)
234
- return nil unless m
235
- args = m.to_a
236
- if i = leaf.index(LABEL_SEP)
237
- value = leaf.dup
238
- value.shift(i + 1)
239
- args[-1] = lstrip_value!(value)
240
- end
241
- self.new(*args)
242
- end
243
-
244
- def self.lstrip_value!(value)
245
- head_val = value[0][0]
246
- if head_val.kind_of? String and head_val.start_with? " ".freeze
247
- value[0][0] = head_val.lstrip
248
- end
249
- value
250
- end
251
- end
252
-
253
- def parse_leafs(breaker)
254
- decorator = {}
255
- breaker.decorator = decorator
256
- @stack.remove_current_node.each do |leaf|
257
- if item = DecoratorItem.create(leaf)
258
- decorator[item.type || :id] = item
259
- end
260
- end
261
- end
262
-
263
- def breakable?(breaker)
264
- return super if breaker.kind_of? DecoratorLeaf
265
- parse_leafs(breaker)
266
- @stack.current_node.breakable?(breaker)
267
- end
268
- end
269
-
270
- class DecoratorLeaf
271
- def push_sectioning_node(stack, node_class)
272
- node = node_class.new
273
- m = DecoratorNode::DECORATOR_PAT.match(join)
274
- node.node_id = m[2]
275
- node.section_level = stack.current_heading_level if node.kind_of? SectioningNode
276
- stack.push(node)
277
- end
278
-
279
- def push_self(stack)
280
- decorator_type = self[0][0]
281
- if decorator_type.start_with? "begin[".freeze
282
- push_sectioning_node(stack, SectioningNode)
283
- elsif decorator_type.start_with? "end[".freeze
284
- push_sectioning_node(stack, SectioningNodeEnd)
285
- else
286
- super
287
- end
288
- end
289
- end
290
-
291
- class SectioningNode
292
- attr_accessor :section_level
293
-
294
- def breakable?(breaker)
295
- breaker.kind_of? HeadingLeaf and @section_level >= breaker.level
296
- end
297
- end
298
-
299
- class SectioningNodeEnd
300
- def push_self(stack)
301
- n = stack.stack.rindex do |node|
302
- node.kind_of? SectioningNode and node.node_id == node_id
303
- end
304
- raise UnmatchedSectioningTagError unless n
305
- stack.pop until stack.stack.length == n
306
- rescue UnmatchedSectioningTagError => e
307
- STDERR.puts "#{e}: The start tag for '#{node_id}' is not found."
308
- # FIXME: The handling of this error should be changed appropriately.
309
- end
310
- end
311
-
312
214
  class QuoteNode
313
- def parse_leafs(breaker)
215
+ def parse_leafs
314
216
  self[0] = BlockParser.parse(self[0], AutoLink::Off)
315
217
  end
316
218
  end
@@ -371,8 +273,7 @@ module PseudoHiki
371
273
  [HrLeaf, HrNode],
372
274
  [ListLeaf, ListNode],
373
275
  [EnumLeaf, EnumNode],
374
- [BlockNodeEnd, BlockNodeEnd], # special case
375
- [DecoratorLeaf, DecoratorNode]
276
+ [BlockNodeEnd, BlockNodeEnd] # special case
376
277
  ].each do |leaf, node|
377
278
  PARENT_NODE[leaf] = node
378
279
  end
@@ -385,7 +286,6 @@ module PseudoHiki
385
286
  ['!', HeadingLeaf],
386
287
  ['""', QuoteLeaf],
387
288
  ['||', TableLeaf],
388
- ['//@', DecoratorLeaf],
389
289
  ['//', CommentOutLeaf],
390
290
  ['----\s*$', HrLeaf]]
391
291
 
@@ -431,7 +331,7 @@ module PseudoHiki
431
331
  def read_lines(lines)
432
332
  each_line = lines.respond_to?(:each_line) ? :each_line : :each
433
333
  lines.send(each_line) {|line| @stack.current_node.add_leaf(line, self) }
434
- @stack.pop_with_breaker
334
+ @stack.pop
435
335
  end
436
336
  end
437
337
 
@@ -78,7 +78,6 @@ module PseudoHiki
78
78
 
79
79
  def visit(tree)
80
80
  htmlelement = create_element(tree)
81
- decorate(htmlelement, tree)
82
81
  push_visited_results(htmlelement, tree)
83
82
  htmlelement
84
83
  end
@@ -97,21 +96,6 @@ module PseudoHiki
97
96
  chunks.push tree
98
97
  end
99
98
 
100
- def decorate(htmlelement, tree)
101
- each_decorator(htmlelement, tree) do |elm, decorator|
102
- elm[CLASS] = HtmlElement.escape(decorator[CLASS].id) if decorator[CLASS]
103
- if id_item = decorator[ID] || decorator[:id]
104
- elm[ID] = HtmlElement.escape(id_item.id).upcase
105
- end
106
- end
107
- end
108
-
109
- def each_decorator(element, tree)
110
- return unless element.kind_of? HtmlElement
111
- return unless tree.kind_of? BlockParser::BlockNode and tree.decorator
112
- tree.decorator.tap {|decorator| yield element, decorator }
113
- end
114
-
115
99
  class ListLeafNodeFormatter < self
116
100
  def create_element(tree)
117
101
  super(tree).tap do |elm|
@@ -137,7 +121,6 @@ module PseudoHiki
137
121
  [EnumNode, "ol"],
138
122
  [TableLeaf, "tr"],
139
123
  [VerbatimNode, "pre"],
140
- [SectioningNode, "section"],
141
124
  [CommentOutNode, nil],
142
125
  [HeadingNode, "section"],
143
126
  [DescLeaf, DT],
@@ -206,23 +189,6 @@ module PseudoHiki
206
189
 
207
190
  # for BlockParser
208
191
 
209
- class << Formatter[TableNode]
210
- def decorate(htmlelement, tree)
211
- each_decorator(htmlelement, tree) do |elm, decorator|
212
- visited_value(decorator["summary"]) do |summary|
213
- htmlelement["summary"] = HtmlElement.escape(summary.join.chomp)
214
- end
215
- visited_value(decorator["caption"]) do |caption|
216
- htmlelement.push @generator.create("caption", caption)
217
- end
218
- end
219
- end
220
-
221
- def visited_value(decorator_item)
222
- yield visited_result(decorator_item.value) if decorator_item
223
- end
224
- end
225
-
226
192
  class << Formatter[VerbatimNode]
227
193
  def visit(tree)
228
194
  contents = add_link(@generator.escape(tree.join))
@@ -237,37 +203,6 @@ module PseudoHiki
237
203
  end
238
204
  end
239
205
 
240
- class << Formatter[SectioningNode]
241
- ID_MARK = "#"
242
-
243
- alias :orig_create_element :create_element
244
-
245
- def section_with_id(tree, node_id)
246
- orig_create_element(tree).tap do |elm|
247
- elm[ID] = node_id[1..-1] # remove the first charactor from node_id
248
- end
249
- end
250
-
251
- def section_for_class(tree, node_id)
252
- if HtmlElement::HTML5_TAGS.include? node_id
253
- @generator.create(node_id)
254
- else
255
- orig_create_element(tree).tap do |elm|
256
- elm[CLASS] = elm[CLASS] ? "#{elm[CLASS]} #{node_id}" : node_id
257
- end
258
- end
259
- end
260
-
261
- def create_element(tree)
262
- node_id = tree.node_id
263
- if node_id.start_with? ID_MARK
264
- section_with_id(tree, node_id)
265
- else
266
- section_for_class(tree, node_id)
267
- end
268
- end
269
- end
270
-
271
206
  class << Formatter[CommentOutNode]
272
207
  def visit(tree); BLANK; end
273
208
  end
@@ -275,14 +275,13 @@ module PseudoHiki
275
275
  class VerbatimNodeFormatter < self
276
276
  def visit(tree)
277
277
  element = super(tree)
278
- @language_name = language_name(tree)
279
278
  return gfm_verbatim(element) if @options.gfm_style
280
279
  md_verbatim(element)
281
280
  end
282
281
 
283
282
  def gfm_verbatim(element)
284
283
  element.tap do |lines|
285
- lines.unshift "```#{@language_name + $/}"
284
+ lines.unshift "```#{$/}"
286
285
  lines.push "```#{$/ * 2}"
287
286
  end
288
287
  end
@@ -290,12 +289,6 @@ module PseudoHiki
290
289
  def md_verbatim(element)
291
290
  element.join.gsub(/^/o, " ").sub(/ \Z/o, "").concat $/
292
291
  end
293
-
294
- def language_name(tree)
295
- tree.decorator.tap do |decorator|
296
- return decorator ? decorator["code"].id : ""
297
- end
298
- end
299
292
  end
300
293
 
301
294
  class QuoteNodeFormatter < self
@@ -1,3 +1,3 @@
1
1
  module PseudoHiki
2
- VERSION = "0.0.5.develop"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -150,5 +150,3 @@ module PseudoHiki
150
150
  end
151
151
  end
152
152
  end
153
-
154
- require 'pseudohiki/sinatra_helpers' if defined? Sinatra
@@ -311,73 +311,6 @@ TEXT
311
311
  assert_equal([[[["heading"]]]],parsed)
312
312
  end
313
313
 
314
-
315
- def test_decorator
316
- text = <<TEXT
317
- //@class[section_name]
318
- !!title of section
319
-
320
- //@summary: Summary of the table
321
- ||!header 1||! header 2
322
- ||cell 1||cell 2
323
-
324
- a paragraph.
325
-
326
- //@class[class_name]
327
- //@[id_name]
328
- another paragraph.
329
- TEXT
330
-
331
- tree = PseudoHiki::BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
332
- assert_equal(PseudoHiki::BlockParser::BlockNode, tree.class)
333
- assert_equal("section_name", tree[0].decorator["class"].id)
334
- assert_equal(PseudoHiki::BlockParser::BlockElement::HeadingNode, tree[0].class)
335
- assert_equal([[["title of section"]], [[[["header 1"]], [[" header 2"]]], [[["cell 1"]], [["cell 2"]]]], [[["a paragraph."]]], [[["another paragraph."]]]], tree[0])
336
- assert_equal([["Summary of the table"]], tree[0][1].decorator["summary"].value)
337
- assert_equal(PseudoHiki::BlockParser::BlockElement::TableNode, tree[0][1].class)
338
- assert_equal(nil, tree[0][2].decorator)
339
- assert_equal('id_name', tree[0][3].decorator[:id].id)
340
- assert_equal('class_name', tree[0][3].decorator["class"].id)
341
- end
342
-
343
- def test_sectioning_node
344
- text = <<TEXT
345
- ! Main title
346
-
347
- //@begin[header]
348
- !! first title in header
349
-
350
- paragraph
351
-
352
- !! second title in header
353
-
354
- paragraph2
355
-
356
- //@end[header]
357
-
358
- !! first subtitle in main part
359
-
360
- paragraph3
361
-
362
- TEXT
363
-
364
- expected_tree = [[[[" Main title\n"]],
365
- [
366
- [[[" first title in header\n"]],
367
- [[["paragraph\n"]]]],
368
- [[[" second title in header\n"]],
369
- [[["paragraph2\n"]]]]
370
- ],
371
- [[[" first subtitle in main part\n"]],
372
- [[["paragraph3\n"]]]]]]
373
-
374
-
375
- tree = PseudoHiki::BlockParser.parse(text)
376
- assert_equal(expected_tree, tree)
377
- assert_kind_of(PseudoHiki::BlockParser::BlockElement::SectioningNode, tree[0][1])
378
- assert_equal("header", tree[0][1].node_id)
379
- end
380
-
381
314
  def test_comment_out_followed_by_a_verbatim_block
382
315
  text = <<TEXT
383
316
  the first paragraph
@@ -135,19 +135,11 @@ table_with_col_header_text = <<TABLE
135
135
  ||!header1||col1-1||col2-1
136
136
  ||!header2||col1-2||col2-2
137
137
  ||!header3||col1-3||col2-3
138
- TABLE
139
-
140
- table_with_row_header_and_caption_text = <<TABLE
141
- //@caption: Caption
142
- ||!header1||!header2||!header3
143
- ||row1-1||row1-2||row1-3
144
- ||row2-1||row2-2||row2-3
145
138
  TABLE
146
139
 
147
140
  @table_manager = HtmlElement::Utils::TableManager.new
148
141
  @table_with_row_header = PseudoHiki::BlockParser.parse(table_with_row_header_text)
149
142
  @table_with_col_header = PseudoHiki::BlockParser.parse(table_with_col_header_text)
150
- @table_with_row_header_and_caption = PseudoHiki::BlockParser.parse(table_with_row_header_and_caption_text)
151
143
 
152
144
  end
153
145
 
@@ -157,9 +149,6 @@ TABLE
157
149
 
158
150
  html_table = PseudoHiki::HtmlFormat.format(@table_with_col_header)[0]
159
151
  assert_equal("row", @table_manager.guess_header_scope(html_table))
160
-
161
- html_table = PseudoHiki::HtmlFormat.format(@table_with_row_header_and_caption)[0]
162
- assert_equal("col", @table_manager.guess_header_scope(html_table))
163
152
  end
164
153
 
165
154
  def test_assign_scope
@@ -775,419 +775,6 @@ HTML
775
775
  assert_equal(xhtml, HtmlFormat.format(tree, {:auto_link_in_verbatim => false }).to_s)
776
776
  end
777
777
 
778
- def test_decorator
779
- text = <<TEXT
780
- //@class[section_type]
781
- !!title of section
782
-
783
- a paragraph.
784
-
785
- //@class[class_name]
786
- //@id[id_name]
787
- another paragraph.
788
- TEXT
789
-
790
- xhtml = <<HTML
791
- <div class="section_type">
792
- <h2>title of section</h2>
793
- <p>
794
- a paragraph.</p>
795
- <p class="class_name" id="ID_NAME">
796
- another paragraph.</p>
797
- <!-- end of section_type -->
798
- </div>
799
- HTML
800
- tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
801
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
802
- end
803
-
804
- def test_decorator_for_table
805
- text = <<TEXT
806
- //@summary: Summary of the table
807
- ||!header 1||! header 2
808
- ||cell 1||cell 2
809
- TEXT
810
-
811
- xhtml = <<HTML
812
- <table summary="Summary of the table">
813
- <tr><th>header 1</th><th> header 2</th></tr>
814
- <tr><td>cell 1</td><td>cell 2</td></tr>
815
- </table>
816
- HTML
817
- tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
818
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
819
- end
820
-
821
- def test_decorator_for_table_summary
822
- text = <<TEXT
823
- //@summary: Summary of the table
824
- ||!header 1||! header 2
825
- TEXT
826
-
827
- xhtml = <<HTML
828
- <table summary="Summary of the table">
829
- <tr><th>header 1</th><th> header 2
830
- </th></tr>
831
- </table>
832
- HTML
833
- tree = BlockParser.parse(text.lines.to_a.map {|line| line })
834
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
835
- end
836
-
837
- def test_decorator_for_table_caption
838
- text = <<TEXT
839
- //@caption: Caption of ''the table''
840
- ||!header 1||! header 2
841
- ||cell 1||cell 2
842
- TEXT
843
-
844
- xhtml = <<HTML
845
- <table>
846
- <caption>Caption of <em>the table</em></caption>
847
- <tr><th>header 1</th><th> header 2</th></tr>
848
- <tr><td>cell 1</td><td>cell 2</td></tr>
849
- </table>
850
- HTML
851
- tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
852
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
853
- end
854
-
855
- def test_decorator_for_table_caption_with_tags
856
- text = <<TEXT
857
- //@caption: [[''Table caption''that begins with a link|http://www.example.org/]] and contains other strings
858
- ||!header 1||! header 2
859
- TEXT
860
-
861
- xhtml = <<HTML
862
- <table>
863
- <caption><a href="http://www.example.org/"><em>Table caption</em>that begins with a link</a> and contains other strings</caption>
864
- <tr><th>header 1</th><th> header 2</th></tr>
865
- </table>
866
- HTML
867
- tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
868
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
869
- end
870
-
871
- def test_decorator_for_verbatim
872
- text = <<TEXT
873
- //@code[ruby]
874
- def bonjour!
875
- puts "Bonjour!"
876
- end
877
- TEXT
878
-
879
- xhtml = <<HTML
880
- <pre>
881
- def bonjour!
882
- puts &quot;Bonjour!&quot;
883
- end
884
- </pre>
885
- HTML
886
-
887
- tree = BlockParser.parse(text.lines.to_a)
888
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
889
- end
890
-
891
- def test_sectioning_node
892
- text = <<TEXT
893
- ! Main title
894
-
895
- //@begin[header]
896
- !! first title in header
897
-
898
- paragraph
899
-
900
- !! second title in header
901
-
902
- paragraph2
903
-
904
- //@end[header]
905
-
906
- !! first subtitle in main part
907
-
908
- paragraph3
909
-
910
- //@begin[#footer]
911
-
912
- paragraph4
913
-
914
- //@end[#footer]
915
-
916
- TEXT
917
-
918
- expected_html = <<HTML
919
- <div class="section h1">
920
- <h1> Main title
921
- </h1>
922
- <div class="header">
923
- <div class="section h2">
924
- <h2> first title in header
925
- </h2>
926
- <p>
927
- paragraph
928
- </p>
929
- <!-- end of section h2 -->
930
- </div>
931
- <div class="section h2">
932
- <h2> second title in header
933
- </h2>
934
- <p>
935
- paragraph2
936
- </p>
937
- <!-- end of section h2 -->
938
- </div>
939
- <!-- end of header -->
940
- </div>
941
- <div class="section h2">
942
- <h2> first subtitle in main part
943
- </h2>
944
- <p>
945
- paragraph3
946
- </p>
947
- <div class="section" id="footer">
948
- <p>
949
- paragraph4
950
- </p>
951
- <!-- end of footer -->
952
- </div>
953
- <!-- end of section h2 -->
954
- </div>
955
- <!-- end of section h1 -->
956
- </div>
957
- HTML
958
-
959
- tree = BlockParser.parse(text.lines.to_a)
960
- assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
961
- end
962
-
963
- def test_sectioning_node_for_html5
964
- text = <<TEXT
965
- ! Main title
966
-
967
- //@begin[header]
968
- !! first title in header
969
-
970
- paragraph
971
-
972
- !! second title in header
973
-
974
- paragraph2
975
-
976
- //@end[header]
977
-
978
- !! first subtitle in main part
979
-
980
- paragraph3
981
-
982
- //@begin[#footer]
983
-
984
- paragraph4
985
-
986
- //@end[#footer]
987
-
988
- TEXT
989
-
990
- expected_html = <<HTML
991
- <section class="h1">
992
- <h1> Main title
993
- </h1>
994
- <header>
995
- <section class="h2">
996
- <h2> first title in header
997
- </h2>
998
- <p>
999
- paragraph
1000
- </p>
1001
- <!-- end of h2 -->
1002
- </section>
1003
- <section class="h2">
1004
- <h2> second title in header
1005
- </h2>
1006
- <p>
1007
- paragraph2
1008
- </p>
1009
- <!-- end of h2 -->
1010
- </section>
1011
- </header>
1012
- <section class="h2">
1013
- <h2> first subtitle in main part
1014
- </h2>
1015
- <p>
1016
- paragraph3
1017
- </p>
1018
- <section id="footer">
1019
- <p>
1020
- paragraph4
1021
- </p>
1022
- <!-- end of footer -->
1023
- </section>
1024
- <!-- end of h2 -->
1025
- </section>
1026
- <!-- end of h1 -->
1027
- </section>
1028
- HTML
1029
-
1030
- tree = BlockParser.parse(text.lines.to_a)
1031
- assert_equal(expected_html, Xhtml5Format.format(tree).to_s)
1032
- end
1033
-
1034
- def test_sectioning_node_when_end_tag_is_omitted
1035
- text = <<TEXT
1036
- !! First part
1037
-
1038
- paragraph1
1039
-
1040
- //@begin[first_sub_part]
1041
- !!! first title in first sub-part
1042
-
1043
- paragraph2
1044
-
1045
- !!! second title in first sub-part
1046
-
1047
- paragraph3
1048
-
1049
- //you should put //@end[first_sub_part] here.
1050
-
1051
- !! Second part
1052
-
1053
- paragraph4
1054
-
1055
- //@begin[#footer]
1056
-
1057
- paragraph5
1058
-
1059
- //@end[#footer]
1060
-
1061
- TEXT
1062
-
1063
- expected_html = <<HTML
1064
- <div class=\"section h2\">
1065
- <h2> First part
1066
- </h2>
1067
- <p>
1068
- paragraph1
1069
- </p>
1070
- <div class=\"section first_sub_part\">
1071
- <div class=\"section h3\">
1072
- <h3> first title in first sub-part
1073
- </h3>
1074
- <p>
1075
- paragraph2
1076
- </p>
1077
- <!-- end of section h3 -->
1078
- </div>
1079
- <div class=\"section h3\">
1080
- <h3> second title in first sub-part
1081
- </h3>
1082
- <p>
1083
- paragraph3
1084
- </p>
1085
- <!-- end of section h3 -->
1086
- </div>
1087
- <!-- end of section first_sub_part -->
1088
- </div>
1089
- <!-- end of section h2 -->
1090
- </div>
1091
- <div class=\"section h2\">
1092
- <h2> Second part
1093
- </h2>
1094
- <p>
1095
- paragraph4
1096
- </p>
1097
- <div class=\"section\" id=\"footer\">
1098
- <p>
1099
- paragraph5
1100
- </p>
1101
- <!-- end of footer -->
1102
- </div>
1103
- <!-- end of section h2 -->
1104
- </div>
1105
- HTML
1106
-
1107
- tree = BlockParser.parse(text.lines.to_a)
1108
- assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
1109
- end
1110
-
1111
- def test_sectioning_node_when_end_tag_is_wrongly_placed
1112
- text = <<TEXT
1113
- !! First part
1114
-
1115
- paragraph1
1116
-
1117
- //@begin[first_sub_part]
1118
- !!! first title in first sub-part
1119
-
1120
- paragraph2
1121
-
1122
- !!! second title in first sub-part
1123
-
1124
- paragraph3
1125
-
1126
- //you should put //@end[first_sub_part] here.
1127
-
1128
- !! Second part
1129
-
1130
- paragraph4
1131
-
1132
-
1133
- //@end[first_sub_part] this end tag is wrongly placed.
1134
-
1135
- //@begin[#footer]
1136
-
1137
- paragraph5
1138
-
1139
- //@end[#footer]
1140
-
1141
- TEXT
1142
-
1143
- expected_html = <<HTML
1144
- <div class=\"section h2\">
1145
- <h2> First part
1146
- </h2>
1147
- <p>
1148
- paragraph1
1149
- </p>
1150
- <div class=\"section first_sub_part\">
1151
- <div class=\"section h3\">
1152
- <h3> first title in first sub-part
1153
- </h3>
1154
- <p>
1155
- paragraph2
1156
- </p>
1157
- <!-- end of section h3 -->
1158
- </div>
1159
- <div class=\"section h3\">
1160
- <h3> second title in first sub-part
1161
- </h3>
1162
- <p>
1163
- paragraph3
1164
- </p>
1165
- <!-- end of section h3 -->
1166
- </div>
1167
- <!-- end of section first_sub_part -->
1168
- </div>
1169
- <!-- end of section h2 -->
1170
- </div>
1171
- <div class=\"section h2\">
1172
- <h2> Second part
1173
- </h2>
1174
- <p>
1175
- paragraph4
1176
- </p>
1177
- <div class=\"section\" id=\"footer\">
1178
- <p>
1179
- paragraph5
1180
- </p>
1181
- <!-- end of footer -->
1182
- </div>
1183
- <!-- end of section h2 -->
1184
- </div>
1185
- HTML
1186
-
1187
- tree = BlockParser.parse(text.lines.to_a)
1188
- assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
1189
- end
1190
-
1191
778
  def test_comment_out_followed_by_a_verbatim_block
1192
779
  text = <<TEXT
1193
780
  the first paragraph
@@ -518,159 +518,6 @@ TEXT
518
518
  assert_equal(md_text, @formatter.format(tree).to_s)
519
519
  end
520
520
 
521
- def test_decorator_for_verbatim
522
- text = <<TEXT
523
- //@code[ruby]
524
- def bonjour!
525
- puts "Bonjour!"
526
- end
527
- TEXT
528
-
529
- gfm_text =<<TEXT
530
- ```ruby
531
- def bonjour!
532
- puts "Bonjour!"
533
- end
534
- ```
535
-
536
- TEXT
537
-
538
- md_text = <<TEXT
539
- def bonjour!
540
- puts "Bonjour!"
541
- end
542
-
543
- TEXT
544
-
545
- tree = BlockParser.parse(text.lines.to_a)
546
- assert_equal(gfm_text, @gfm_formatter.format(tree).to_s)
547
- assert_equal(md_text, @formatter.format(tree).to_s)
548
- end
549
-
550
- def test_decorator_for_verbatim_block
551
- text = <<TEXT
552
- //@code[ruby]
553
- <<<
554
- def bonjour!
555
- puts "Bonjour!"
556
- end
557
- >>>
558
- TEXT
559
-
560
- gfm_text =<<TEXT
561
- ```ruby
562
- def bonjour!
563
- puts "Bonjour!"
564
- end
565
- ```
566
-
567
- TEXT
568
-
569
- md_text = <<TEXT
570
- def bonjour!
571
- puts "Bonjour!"
572
- end
573
-
574
- TEXT
575
-
576
- tree = BlockParser.parse(text.lines.to_a)
577
- assert_equal(gfm_text, @gfm_formatter.format(tree).to_s)
578
- assert_equal(md_text, @formatter.format(tree).to_s)
579
- end
580
-
581
- def test_without_sectioning_node
582
- text = <<TEXT
583
- ! Main title
584
-
585
- !! first title in header
586
-
587
- paragraph
588
-
589
- !! second title in header
590
-
591
- paragraph2
592
-
593
- !! first subtitle in main part
594
-
595
- paragraph3
596
-
597
- paragraph4
598
-
599
- TEXT
600
-
601
- expected_text = <<HTML
602
- # Main title
603
-
604
- ## first title in header
605
-
606
- paragraph
607
-
608
- ## second title in header
609
-
610
- paragraph2
611
-
612
- ## first subtitle in main part
613
-
614
- paragraph3
615
-
616
- paragraph4
617
-
618
- HTML
619
-
620
- tree = BlockParser.parse(text.lines.to_a)
621
- assert_equal(expected_text, @gfm_formatter.format(tree).to_s)
622
- end
623
-
624
- def test_sectioning_node
625
- text = <<TEXT
626
- ! Main title
627
-
628
- //@begin[header]
629
- !! first title in header
630
-
631
- paragraph
632
-
633
- !! second title in header
634
-
635
- paragraph2
636
-
637
- //@end[header]
638
-
639
- !! first subtitle in main part
640
-
641
- paragraph3
642
-
643
- //@begin[#footer]
644
-
645
- paragraph4
646
-
647
- //@end[#footer]
648
-
649
- TEXT
650
-
651
- expected_text = <<HTML
652
- # Main title
653
-
654
- ## first title in header
655
-
656
- paragraph
657
-
658
- ## second title in header
659
-
660
- paragraph2
661
-
662
- ## first subtitle in main part
663
-
664
- paragraph3
665
-
666
- paragraph4
667
-
668
- HTML
669
-
670
- tree = BlockParser.parse(text.lines.to_a)
671
- assert_equal(expected_text, @gfm_formatter.format(tree).to_s)
672
- end
673
-
674
521
  def test_collect_headings
675
522
  text = <<TEXT
676
523
  !![main-heading] heading
@@ -265,89 +265,4 @@ TEXT
265
265
  assert_equal(expected_text_in_verbose_mode, PlainTextFormat.format(tree, { :verbose_mode => true }).to_s)
266
266
  assert_equal(expected_text, PlainTextFormat.format(tree, { :verbose_mode => false }).to_s)
267
267
  end
268
-
269
- def test_without_sectioning_node
270
- text = <<TEXT
271
- ! Main title
272
-
273
- !! first title in header
274
-
275
- paragraph
276
-
277
- !! second title in header
278
-
279
- paragraph2
280
-
281
- !! first subtitle in main part
282
-
283
- paragraph3
284
-
285
- paragraph4
286
-
287
- TEXT
288
-
289
- expected_text = <<HTML
290
- Main title
291
- first title in header
292
- paragraph
293
-
294
- second title in header
295
- paragraph2
296
-
297
- first subtitle in main part
298
- paragraph3
299
-
300
- paragraph4
301
-
302
- HTML
303
-
304
- tree = BlockParser.parse(text.lines.to_a)
305
- assert_equal(expected_text, PlainTextFormat.format(tree, { :verbose_mode => false }).to_s)
306
- end
307
-
308
- def test_sectioning_node
309
- text = <<TEXT
310
- ! Main title
311
-
312
- //@begin[header]
313
- !! first title in header
314
-
315
- paragraph
316
-
317
- !! second title in header
318
-
319
- paragraph2
320
-
321
- //@end[header]
322
-
323
- !! first subtitle in main part
324
-
325
- paragraph3
326
-
327
- //@begin[#footer]
328
-
329
- paragraph4
330
-
331
- //@end[#footer]
332
-
333
- TEXT
334
-
335
- expected_text = <<HTML
336
- Main title
337
- first title in header
338
- paragraph
339
-
340
- second title in header
341
- paragraph2
342
-
343
- first subtitle in main part
344
- paragraph3
345
-
346
- paragraph4
347
-
348
- HTML
349
-
350
- tree = BlockParser.parse(text.lines.to_a)
351
- assert_equal(expected_text, PlainTextFormat.format(tree, { :verbose_mode => false }).to_s)
352
- end
353
268
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudohikiparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5.develop
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki
@@ -90,7 +90,6 @@ files:
90
90
  - lib/pseudohiki/inlineparser.rb
91
91
  - lib/pseudohiki/markdownformat.rb
92
92
  - lib/pseudohiki/plaintextformat.rb
93
- - lib/pseudohiki/sinatra_helpers.rb
94
93
  - lib/pseudohiki/treestack.rb
95
94
  - lib/pseudohiki/utils.rb
96
95
  - lib/pseudohiki/version.rb
@@ -125,9 +124,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
124
  version: 1.8.7
126
125
  required_rubygems_version: !ruby/object:Gem::Requirement
127
126
  requirements:
128
- - - ">"
127
+ - - ">="
129
128
  - !ruby/object:Gem::Version
130
- version: 1.3.1
129
+ version: '0'
131
130
  requirements: []
132
131
  rubyforge_project:
133
132
  rubygems_version: 2.2.3
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- begin
4
- module Sinatra
5
- module PseudoHikiParserHelpers
6
- XHTML5_CONTENT_TYPE = 'application/xhtml+xml'
7
- def phiki(hiki_data, &block)
8
- case content_type
9
- when XHTML5_CONTENT_TYPE
10
- PseudoHiki::Format.to_html5(hiki_data, &block)
11
- else
12
- PseudoHiki::Format.to_xhtml(hiki_data, &block)
13
- end
14
- end
15
- end
16
-
17
- class Base
18
- helpers PseudoHikiParserHelpers
19
- end
20
- end
21
- rescue
22
- #Sinatra is not available
23
- end