pseudohikiparser 0.0.6.develop → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98aa9c74058bd6a6da9f43b9f2c7d73872db41c9
4
- data.tar.gz: d921304c72c05629e616d47899b28e09c7fc91ab
3
+ metadata.gz: d25782e47a5041970f1724029b8a048fd453c302
4
+ data.tar.gz: 8b2bfb67cf20795f7c43c8de5df1f7df986d72fd
5
5
  SHA512:
6
- metadata.gz: 4f1a030cee17f773f7f9489270874d462c4d1da7c6fa57b86830910a13018e5ee0757155d97e8e07de503cd2f22237bd515151de3583d187ac62aaf703120d37
7
- data.tar.gz: 793b3d2c14b5b36fc6ee964c838f9f630a017c3a78cc7e35ab2457fed631c405487ecf0c489da88fd2a5f3342ebb9425831eebd8bb28293682bfdf2834df8481
6
+ metadata.gz: c993101868e60327fe8ad381fb1e4a2999c812ce567d61bad8e018b7321dc075cfff7465ed93fea751886a133531a1afc9933fdfa67b909a77dd6b8a3fa628fe
7
+ data.tar.gz: 50ebcfe2480943bc124d38f854a2c5755ff071f745530f3e336fd2815df796310c91dd4735249027d4b189770e6b18ace56b305a4759a7fc87e0c2d565f590ac
@@ -39,21 +39,14 @@ module PseudoHiki
39
39
  end
40
40
 
41
41
  class BlockStack < TreeStack
42
- attr_reader :stack
43
-
44
- def pop_with_breaker(breaker=nil)
45
- current_node.parse_leafs(breaker)
46
- pop
47
- end
48
-
49
- def current_heading_level
50
- i = @stack.rindex {|node| node.kind_of? BlockElement::HeadingNode }
51
- @stack[i].level || 0
42
+ def pop
43
+ current_node.parse_leafs
44
+ super
52
45
  end
53
46
  end
54
47
 
55
48
  class BlockLeaf < BlockStack::Leaf
56
- attr_accessor :level, :node_id, :decorator
49
+ attr_accessor :level, :node_id
57
50
 
58
51
  class << self
59
52
  attr_accessor :head_re
@@ -89,7 +82,7 @@ module PseudoHiki
89
82
  super(stack)
90
83
  end
91
84
 
92
- def parse_leafs(breaker)
85
+ def parse_leafs
93
86
  parsed = InlineParser.parse(join)
94
87
  clear
95
88
  concat(parsed)
@@ -139,10 +132,6 @@ module PseudoHiki
139
132
  first.level if first # @cached_level ||= (first.level if first)
140
133
  end
141
134
 
142
- def decorator
143
- first.decorator if first
144
- end
145
-
146
135
  def push_self(stack)
147
136
  @stack = stack
148
137
  super(stack)
@@ -152,11 +141,11 @@ module PseudoHiki
152
141
  not (kind_of? breaker.block and level == breaker.level)
153
142
  end
154
143
 
155
- def parse_leafs(breaker); end
144
+ def parse_leafs; end
156
145
 
157
146
  def add_leaf(line, blockparser)
158
147
  leaf = create_leaf(line, blockparser)
159
- blockparser.stack.pop_with_breaker(leaf) while blockparser.breakable?(leaf)
148
+ blockparser.stack.pop while blockparser.breakable?(leaf)
160
149
  blockparser.stack.push leaf
161
150
  end
162
151
 
@@ -168,8 +157,8 @@ module PseudoHiki
168
157
  end
169
158
 
170
159
  class NonNestedBlockNode < BlockNode
171
- def parse_leafs(breaker)
172
- each {|leaf| leaf.parse_leafs(breaker) }
160
+ def parse_leafs
161
+ each {|leaf| leaf.parse_leafs }
173
162
  end
174
163
  end
175
164
 
@@ -187,15 +176,13 @@ module PseudoHiki
187
176
  end
188
177
  end
189
178
 
190
- class UnmatchedSectioningTagError < StandardError; end
191
-
192
179
  module BlockElement
193
180
  {
194
- BlockLeaf => %w(DescLeaf VerbatimLeaf TableLeaf CommentOutLeaf BlockNodeEnd HrLeaf DecoratorLeaf SectioningNodeEnd),
181
+ BlockLeaf => %w(DescLeaf VerbatimLeaf TableLeaf CommentOutLeaf BlockNodeEnd HrLeaf),
195
182
  NonNestedBlockLeaf => %w(QuoteLeaf ParagraphLeaf),
196
183
  NestedBlockLeaf => %w(HeadingLeaf),
197
184
  ListTypeLeaf => %w(ListLeaf EnumLeaf),
198
- BlockNode => %w(DescNode VerbatimNode TableNode CommentOutNode HrNode DecoratorNode SectioningNode),
185
+ BlockNode => %w(DescNode VerbatimNode TableNode CommentOutNode HrNode),
199
186
  NonNestedBlockNode => %w(QuoteNode ParagraphNode),
200
187
  NestedBlockNode => %w(HeadingNode),
201
188
  ListTypeBlockNode => %w(ListNode EnumNode),
@@ -218,100 +205,15 @@ module PseudoHiki
218
205
  attr_accessor :in_block_tag
219
206
 
220
207
  def add_leaf(line, blockparser)
221
- return @stack.pop_with_breaker if VERBATIM_END.match? line
208
+ return @stack.pop if VERBATIM_END.match? line
222
209
  return super(line, blockparser) unless @in_block_tag
223
210
  line = " #{line}" if BlockNodeEnd.head_re.match? line and not @in_block_tag
224
211
  @stack.push VerbatimLeaf.create(line, @in_block_tag)
225
212
  end
226
213
  end
227
214
 
228
- class DecoratorNode
229
- DECORATOR_PAT = /\A(?:([^\[\]:]+))?(?:\[([^\[\]]+)\])?(?::\s*(\S.*))?/o
230
- LABEL_SEP = [":"]
231
-
232
- class DecoratorItem < Struct.new(:string, :type, :id, :value)
233
- def self.create(leaf)
234
- m = DECORATOR_PAT.match(leaf.join)
235
- return nil unless m
236
- args = m.to_a
237
- if i = leaf.index(LABEL_SEP)
238
- value = leaf.dup
239
- value.shift(i + 1)
240
- args[-1] = lstrip_value!(value)
241
- end
242
- self.new(*args)
243
- end
244
-
245
- def self.lstrip_value!(value)
246
- head_val = value[0][0]
247
- if head_val.kind_of? String and head_val.start_with? " ".freeze
248
- value[0][0] = head_val.lstrip
249
- end
250
- value
251
- end
252
- end
253
-
254
- def parse_leafs(breaker)
255
- decorator = {}
256
- breaker.decorator = decorator
257
- @stack.remove_current_node.each do |leaf|
258
- if item = DecoratorItem.create(leaf)
259
- decorator[item.type || :id] = item
260
- end
261
- end
262
- end
263
-
264
- def breakable?(breaker)
265
- return super if breaker.kind_of? DecoratorLeaf
266
- parse_leafs(breaker)
267
- @stack.current_node.breakable?(breaker)
268
- end
269
- end
270
-
271
- class DecoratorLeaf
272
- def push_sectioning_node(stack, node_class)
273
- node = node_class.new
274
- m = DecoratorNode::DECORATOR_PAT.match(join)
275
- node.node_id = m[2]
276
- node.section_level = stack.current_heading_level if node.kind_of? SectioningNode
277
- stack.push(node)
278
- end
279
-
280
- def push_self(stack)
281
- decorator_type = self[0][0]
282
- if decorator_type.start_with? "begin[".freeze
283
- push_sectioning_node(stack, SectioningNode)
284
- elsif decorator_type.start_with? "end[".freeze
285
- push_sectioning_node(stack, SectioningNodeEnd)
286
- else
287
- super
288
- end
289
- end
290
- end
291
-
292
- class SectioningNode
293
- attr_accessor :section_level
294
-
295
- def breakable?(breaker)
296
- breaker.kind_of? HeadingLeaf and @section_level >= breaker.level
297
- end
298
- end
299
-
300
- class SectioningNodeEnd
301
- def push_self(stack)
302
- n = stack.stack.rindex do |node|
303
- node.kind_of? SectioningNode and node.node_id == node_id
304
- end
305
- raise UnmatchedSectioningTagError unless n
306
- stack.pop until stack.stack.length == n
307
- rescue UnmatchedSectioningTagError => e
308
- STDERR.puts "#{e}: The start tag for '#{node_id}' is not found."
309
- # FIXME: The handling of this error should be changed appropriately.
310
- end
311
- end
312
-
313
215
  class QuoteNode
314
- def parse_leafs(breaker)
216
+ def parse_leafs
315
217
  self[0] = BlockParser.parse(self[0], AutoLink::Off)
316
218
  end
317
219
  end
@@ -372,8 +274,7 @@ module PseudoHiki
372
274
  [HrLeaf, HrNode],
373
275
  [ListLeaf, ListNode],
374
276
  [EnumLeaf, EnumNode],
375
- [BlockNodeEnd, BlockNodeEnd], # special case
376
- [DecoratorLeaf, DecoratorNode]
277
+ [BlockNodeEnd, BlockNodeEnd] # special case
377
278
  ].each do |leaf, node|
378
279
  PARENT_NODE[leaf] = node
379
280
  end
@@ -386,7 +287,6 @@ module PseudoHiki
386
287
  ['!', HeadingLeaf],
387
288
  ['""', QuoteLeaf],
388
289
  ['||', TableLeaf],
389
- ['//@', DecoratorLeaf],
390
290
  ['//', CommentOutLeaf],
391
291
  ['----\s*$', HrLeaf]]
392
292
 
@@ -432,7 +332,7 @@ module PseudoHiki
432
332
  def read_lines(lines)
433
333
  each_line = lines.respond_to?(:each_line) ? :each_line : :each
434
334
  lines.send(each_line) {|line| @stack.current_node.add_leaf(line, self) }
435
- @stack.pop_with_breaker
335
+ @stack.pop
436
336
  end
437
337
  end
438
338
 
@@ -78,7 +78,6 @@ module PseudoHiki
78
78
 
79
79
  def visit(tree, memo)
80
80
  htmlelement = create_element(tree)
81
- decorate(htmlelement, tree)
82
81
  push_visited_results(htmlelement, tree, memo)
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, memo=nil)
211
- each_decorator(htmlelement, tree) do |elm, decorator|
212
- visited_value(decorator["summary"], memo) do |summary|
213
- htmlelement["summary"] = HtmlElement.escape(summary.join.chomp)
214
- end
215
- visited_value(decorator["caption"], memo) do |caption|
216
- htmlelement.push @generator.create("caption", caption)
217
- end
218
- end
219
- end
220
-
221
- def visited_value(decorator_item, memo)
222
- yield visited_result(decorator_item.value, memo) if decorator_item
223
- end
224
- end
225
-
226
192
  class << Formatter[VerbatimNode]
227
193
  def visit(tree, memo)
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, memo); BLANK; end
273
208
  end
@@ -275,14 +275,13 @@ module PseudoHiki
275
275
  class VerbatimNodeFormatter < self
276
276
  def visit(tree, memo)
277
277
  element = super(tree, memo)
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.6.develop"
2
+ VERSION = "0.0.6"
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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudohikiparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6.develop
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -91,7 +91,6 @@ files:
91
91
  - lib/pseudohiki/markdownformat.rb
92
92
  - lib/pseudohiki/plaintextformat.rb
93
93
  - lib/pseudohiki/shim.rb
94
- - lib/pseudohiki/sinatra_helpers.rb
95
94
  - lib/pseudohiki/treestack.rb
96
95
  - lib/pseudohiki/utils.rb
97
96
  - lib/pseudohiki/version.rb
@@ -126,9 +125,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
125
  version: 1.8.7
127
126
  required_rubygems_version: !ruby/object:Gem::Requirement
128
127
  requirements:
129
- - - ">"
128
+ - - ">="
130
129
  - !ruby/object:Gem::Version
131
- version: 1.3.1
130
+ version: '0'
132
131
  requirements: []
133
132
  rubyforge_project:
134
133
  rubygems_version: 2.6.6
@@ -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