pseudohikiparser 0.0.4.develop → 0.0.4

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: 685e26157a454005d4d71337bbe18cac722efa11
4
- data.tar.gz: a8edea51f0aa148d8e78647b0f36702226c742f0
3
+ metadata.gz: 38493340a4c48448be37a5e6d800bf6ad0fa8f8f
4
+ data.tar.gz: 43c9ef5c8dadb24c502d0bdb8f3dd47a511c3157
5
5
  SHA512:
6
- metadata.gz: 5b8daca9efc17ba0da4cb70aa5e6f44960ee6e2b82205e84e690106e765655c75079d49033b929a8f77e0e8db5be4df1216ce1bc0ba602ce4a81f9d9c22802f0
7
- data.tar.gz: 913060555b63ba9f2aff1e98ef2ee025a64dc442270a70285f9626ea87196be665bac45731c018e251cf9d86fe237844d3ba1c2b53fb8218e6772ddc247345ca
6
+ metadata.gz: 381ec4accb316ca35c4c82d49e9189657a330cfb318e12c0783f528b1c5b41a156352538c0297e232358cb43058c4a3ca90a6fefaf11bea378244a2b3da0c497
7
+ data.tar.gz: 552e791bf5fc72f022d499a069911b2705d121304c2a23381b3e6e7039287d6019a9dfea005f769c2fe05ea63ecfc99411ccf9bf1fdd8781a19645a23e761bc6
@@ -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,85 +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
-
230
- class DecoratorItem < Struct.new(:string, :type, :id, :value)
231
- def initialize(*args)
232
- super
233
- self.value = InlineParser.parse(self.value) if self.value
234
- end
235
- end
236
-
237
- def parse_leafs(breaker)
238
- decorator = {}
239
- breaker.decorator = decorator
240
- @stack.remove_current_node.each do |leaf|
241
- m = DECORATOR_PAT.match(leaf.join)
242
- return nil unless m
243
- item = DecoratorItem.new(*(m.to_a))
244
- decorator[item.type || :id] = item
245
- end
246
- end
247
-
248
- def breakable?(breaker)
249
- return super if breaker.kind_of? DecoratorLeaf
250
- parse_leafs(breaker)
251
- @stack.current_node.breakable?(breaker)
252
- end
253
- end
254
-
255
- class DecoratorLeaf
256
- def push_sectioning_node(stack, node_class)
257
- node = node_class.new
258
- m = DecoratorNode::DECORATOR_PAT.match(join)
259
- node.node_id = m[2]
260
- node.section_level = stack.current_heading_level if node.kind_of? SectioningNode
261
- stack.push(node)
262
- end
263
-
264
- def push_self(stack)
265
- decorator_type = self[0][0]
266
- if decorator_type.start_with? "begin[".freeze
267
- push_sectioning_node(stack, SectioningNode)
268
- elsif decorator_type.start_with? "end[".freeze
269
- push_sectioning_node(stack, SectioningNodeEnd)
270
- else
271
- super
272
- end
273
- end
274
- end
275
-
276
- class SectioningNode
277
- attr_accessor :section_level
278
-
279
- def breakable?(breaker)
280
- breaker.kind_of? HeadingLeaf and @section_level >= breaker.level
281
- end
282
- end
283
-
284
- class SectioningNodeEnd
285
- def push_self(stack)
286
- n = stack.stack.rindex do |node|
287
- node.kind_of? SectioningNode and node.node_id == node_id
288
- end
289
- raise UnmatchedSectioningTagError unless n
290
- stack.pop until stack.stack.length == n
291
- rescue UnmatchedSectioningTagError => e
292
- STDERR.puts "#{e}: The start tag for '#{node_id}' is not found."
293
- # FIXME: The handling of this error should be changed appropriately.
294
- end
295
- end
296
-
297
214
  class QuoteNode
298
- def parse_leafs(breaker)
215
+ def parse_leafs
299
216
  self[0] = BlockParser.parse(self[0], AutoLink::Off)
300
217
  end
301
218
  end
@@ -356,8 +273,7 @@ module PseudoHiki
356
273
  [HrLeaf, HrNode],
357
274
  [ListLeaf, ListNode],
358
275
  [EnumLeaf, EnumNode],
359
- [BlockNodeEnd, BlockNodeEnd], # special case
360
- [DecoratorLeaf, DecoratorNode]
276
+ [BlockNodeEnd, BlockNodeEnd] # special case
361
277
  ].each do |leaf, node|
362
278
  PARENT_NODE[leaf] = node
363
279
  end
@@ -370,7 +286,6 @@ module PseudoHiki
370
286
  ['!', HeadingLeaf],
371
287
  ['""', QuoteLeaf],
372
288
  ['||', TableLeaf],
373
- ['//@', DecoratorLeaf],
374
289
  ['//', CommentOutLeaf],
375
290
  ['----\s*$', HrLeaf]]
376
291
 
@@ -416,7 +331,7 @@ module PseudoHiki
416
331
  def read_lines(lines)
417
332
  each_line = lines.respond_to?(:each_line) ? :each_line : :each
418
333
  lines.send(each_line) {|line| @stack.current_node.add_leaf(line, self) }
419
- @stack.pop_with_breaker
334
+ @stack.pop
420
335
  end
421
336
  end
422
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,15 +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
- summary = decorator["summary"] && decorator["summary"].value.join
213
- htmlelement["summary"] = HtmlElement.escape(summary) if summary
214
- end
215
- end
216
- end
217
-
218
192
  class << Formatter[VerbatimNode]
219
193
  def visit(tree)
220
194
  contents = add_link(@generator.escape(tree.join))
@@ -229,37 +203,6 @@ module PseudoHiki
229
203
  end
230
204
  end
231
205
 
232
- class << Formatter[SectioningNode]
233
- ID_MARK = "#"
234
-
235
- alias :orig_create_element :create_element
236
-
237
- def section_with_id(tree, node_id)
238
- orig_create_element(tree).tap do |elm|
239
- elm[ID] = node_id[1..-1] # remove the first charactor from node_id
240
- end
241
- end
242
-
243
- def section_for_class(tree, node_id)
244
- if HtmlElement::HTML5_TAGS.include? node_id
245
- @generator.create(node_id)
246
- else
247
- orig_create_element(tree).tap do |elm|
248
- elm[CLASS] = elm[CLASS] ? "#{elm[CLASS]} #{node_id}" : node_id
249
- end
250
- end
251
- end
252
-
253
- def create_element(tree)
254
- node_id = tree.node_id
255
- if node_id.start_with? ID_MARK
256
- section_with_id(tree, node_id)
257
- else
258
- section_for_class(tree, node_id)
259
- end
260
- end
261
- end
262
-
263
206
  class << Formatter[CommentOutNode]
264
207
  def visit(tree); BLANK; end
265
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.4.develop"
2
+ VERSION = "0.0.4"
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
@@ -769,369 +769,6 @@ HTML
769
769
  assert_equal(xhtml, HtmlFormat.format(tree, {:auto_link_in_verbatim => false }).to_s)
770
770
  end
771
771
 
772
- def test_decorator
773
- text = <<TEXT
774
- //@class[section_type]
775
- !!title of section
776
-
777
- a paragraph.
778
-
779
- //@class[class_name]
780
- //@id[id_name]
781
- another paragraph.
782
- TEXT
783
-
784
- xhtml = <<HTML
785
- <div class="section_type">
786
- <h2>title of section</h2>
787
- <p>
788
- a paragraph.</p>
789
- <p class="class_name" id="ID_NAME">
790
- another paragraph.</p>
791
- <!-- end of section_type -->
792
- </div>
793
- HTML
794
- tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
795
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
796
- end
797
-
798
- def test_decorator_for_table
799
- text = <<TEXT
800
- //@summary: Summary of the table
801
- ||!header 1||! header 2
802
- ||cell 1||cell 2
803
- TEXT
804
-
805
- xhtml = <<HTML
806
- <table summary="Summary of the table">
807
- <tr><th>header 1</th><th> header 2</th></tr>
808
- <tr><td>cell 1</td><td>cell 2</td></tr>
809
- </table>
810
- HTML
811
- tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
812
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
813
- end
814
-
815
- def test_decorator_for_verbatim
816
- text = <<TEXT
817
- //@code[ruby]
818
- def bonjour!
819
- puts "Bonjour!"
820
- end
821
- TEXT
822
-
823
- xhtml = <<HTML
824
- <pre>
825
- def bonjour!
826
- puts &quot;Bonjour!&quot;
827
- end
828
- </pre>
829
- HTML
830
-
831
- tree = BlockParser.parse(text.lines.to_a)
832
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
833
- end
834
-
835
- def test_sectioning_node
836
- text = <<TEXT
837
- ! Main title
838
-
839
- //@begin[header]
840
- !! first title in header
841
-
842
- paragraph
843
-
844
- !! second title in header
845
-
846
- paragraph2
847
-
848
- //@end[header]
849
-
850
- !! first subtitle in main part
851
-
852
- paragraph3
853
-
854
- //@begin[#footer]
855
-
856
- paragraph4
857
-
858
- //@end[#footer]
859
-
860
- TEXT
861
-
862
- expected_html = <<HTML
863
- <div class="section h1">
864
- <h1> Main title
865
- </h1>
866
- <div class="header">
867
- <div class="section h2">
868
- <h2> first title in header
869
- </h2>
870
- <p>
871
- paragraph
872
- </p>
873
- <!-- end of section h2 -->
874
- </div>
875
- <div class="section h2">
876
- <h2> second title in header
877
- </h2>
878
- <p>
879
- paragraph2
880
- </p>
881
- <!-- end of section h2 -->
882
- </div>
883
- <!-- end of header -->
884
- </div>
885
- <div class="section h2">
886
- <h2> first subtitle in main part
887
- </h2>
888
- <p>
889
- paragraph3
890
- </p>
891
- <div class="section" id="footer">
892
- <p>
893
- paragraph4
894
- </p>
895
- <!-- end of footer -->
896
- </div>
897
- <!-- end of section h2 -->
898
- </div>
899
- <!-- end of section h1 -->
900
- </div>
901
- HTML
902
-
903
- tree = BlockParser.parse(text.lines.to_a)
904
- assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
905
- end
906
-
907
- def test_sectioning_node_for_html5
908
- text = <<TEXT
909
- ! Main title
910
-
911
- //@begin[header]
912
- !! first title in header
913
-
914
- paragraph
915
-
916
- !! second title in header
917
-
918
- paragraph2
919
-
920
- //@end[header]
921
-
922
- !! first subtitle in main part
923
-
924
- paragraph3
925
-
926
- //@begin[#footer]
927
-
928
- paragraph4
929
-
930
- //@end[#footer]
931
-
932
- TEXT
933
-
934
- expected_html = <<HTML
935
- <section class="h1">
936
- <h1> Main title
937
- </h1>
938
- <header>
939
- <section class="h2">
940
- <h2> first title in header
941
- </h2>
942
- <p>
943
- paragraph
944
- </p>
945
- <!-- end of h2 -->
946
- </section>
947
- <section class="h2">
948
- <h2> second title in header
949
- </h2>
950
- <p>
951
- paragraph2
952
- </p>
953
- <!-- end of h2 -->
954
- </section>
955
- </header>
956
- <section class="h2">
957
- <h2> first subtitle in main part
958
- </h2>
959
- <p>
960
- paragraph3
961
- </p>
962
- <section id="footer">
963
- <p>
964
- paragraph4
965
- </p>
966
- <!-- end of footer -->
967
- </section>
968
- <!-- end of h2 -->
969
- </section>
970
- <!-- end of h1 -->
971
- </section>
972
- HTML
973
-
974
- tree = BlockParser.parse(text.lines.to_a)
975
- assert_equal(expected_html, Xhtml5Format.format(tree).to_s)
976
- end
977
-
978
- def test_sectioning_node_when_end_tag_is_omitted
979
- text = <<TEXT
980
- !! First part
981
-
982
- paragraph1
983
-
984
- //@begin[first_sub_part]
985
- !!! first title in first sub-part
986
-
987
- paragraph2
988
-
989
- !!! second title in first sub-part
990
-
991
- paragraph3
992
-
993
- //you should put //@end[first_sub_part] here.
994
-
995
- !! Second part
996
-
997
- paragraph4
998
-
999
- //@begin[#footer]
1000
-
1001
- paragraph5
1002
-
1003
- //@end[#footer]
1004
-
1005
- TEXT
1006
-
1007
- expected_html = <<HTML
1008
- <div class=\"section h2\">
1009
- <h2> First part
1010
- </h2>
1011
- <p>
1012
- paragraph1
1013
- </p>
1014
- <div class=\"section first_sub_part\">
1015
- <div class=\"section h3\">
1016
- <h3> first title in first sub-part
1017
- </h3>
1018
- <p>
1019
- paragraph2
1020
- </p>
1021
- <!-- end of section h3 -->
1022
- </div>
1023
- <div class=\"section h3\">
1024
- <h3> second title in first sub-part
1025
- </h3>
1026
- <p>
1027
- paragraph3
1028
- </p>
1029
- <!-- end of section h3 -->
1030
- </div>
1031
- <!-- end of section first_sub_part -->
1032
- </div>
1033
- <!-- end of section h2 -->
1034
- </div>
1035
- <div class=\"section h2\">
1036
- <h2> Second part
1037
- </h2>
1038
- <p>
1039
- paragraph4
1040
- </p>
1041
- <div class=\"section\" id=\"footer\">
1042
- <p>
1043
- paragraph5
1044
- </p>
1045
- <!-- end of footer -->
1046
- </div>
1047
- <!-- end of section h2 -->
1048
- </div>
1049
- HTML
1050
-
1051
- tree = BlockParser.parse(text.lines.to_a)
1052
- assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
1053
- end
1054
-
1055
- def test_sectioning_node_when_end_tag_is_wrongly_placed
1056
- text = <<TEXT
1057
- !! First part
1058
-
1059
- paragraph1
1060
-
1061
- //@begin[first_sub_part]
1062
- !!! first title in first sub-part
1063
-
1064
- paragraph2
1065
-
1066
- !!! second title in first sub-part
1067
-
1068
- paragraph3
1069
-
1070
- //you should put //@end[first_sub_part] here.
1071
-
1072
- !! Second part
1073
-
1074
- paragraph4
1075
-
1076
-
1077
- //@end[first_sub_part] this end tag is wrongly placed.
1078
-
1079
- //@begin[#footer]
1080
-
1081
- paragraph5
1082
-
1083
- //@end[#footer]
1084
-
1085
- TEXT
1086
-
1087
- expected_html = <<HTML
1088
- <div class=\"section h2\">
1089
- <h2> First part
1090
- </h2>
1091
- <p>
1092
- paragraph1
1093
- </p>
1094
- <div class=\"section first_sub_part\">
1095
- <div class=\"section h3\">
1096
- <h3> first title in first sub-part
1097
- </h3>
1098
- <p>
1099
- paragraph2
1100
- </p>
1101
- <!-- end of section h3 -->
1102
- </div>
1103
- <div class=\"section h3\">
1104
- <h3> second title in first sub-part
1105
- </h3>
1106
- <p>
1107
- paragraph3
1108
- </p>
1109
- <!-- end of section h3 -->
1110
- </div>
1111
- <!-- end of section first_sub_part -->
1112
- </div>
1113
- <!-- end of section h2 -->
1114
- </div>
1115
- <div class=\"section h2\">
1116
- <h2> Second part
1117
- </h2>
1118
- <p>
1119
- paragraph4
1120
- </p>
1121
- <div class=\"section\" id=\"footer\">
1122
- <p>
1123
- paragraph5
1124
- </p>
1125
- <!-- end of footer -->
1126
- </div>
1127
- <!-- end of section h2 -->
1128
- </div>
1129
- HTML
1130
-
1131
- tree = BlockParser.parse(text.lines.to_a)
1132
- assert_equal(expected_html, XhtmlFormat.format(tree).to_s)
1133
- end
1134
-
1135
772
  def test_comment_out_followed_by_a_verbatim_block
1136
773
  text = <<TEXT
1137
774
  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.4.develop
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki
@@ -89,7 +89,6 @@ files:
89
89
  - lib/pseudohiki/inlineparser.rb
90
90
  - lib/pseudohiki/markdownformat.rb
91
91
  - lib/pseudohiki/plaintextformat.rb
92
- - lib/pseudohiki/sinatra_helpers.rb
93
92
  - lib/pseudohiki/treestack.rb
94
93
  - lib/pseudohiki/utils.rb
95
94
  - lib/pseudohiki/version.rb
@@ -123,9 +122,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
122
  version: 1.8.7
124
123
  required_rubygems_version: !ruby/object:Gem::Requirement
125
124
  requirements:
126
- - - ">"
125
+ - - ">="
127
126
  - !ruby/object:Gem::Version
128
- version: 1.3.1
127
+ version: '0'
129
128
  requirements: []
130
129
  rubyforge_project:
131
130
  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