pseudohikiparser 0.0.3.develop → 0.0.3

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: 4194b79f711194dc48b8b09a13302ec50dd9f20d
4
- data.tar.gz: 1b91b097c191eb63711aae1f62bf92788943310e
3
+ metadata.gz: 32c71494df02c4ef6701259bd2f7731e2ec14508
4
+ data.tar.gz: fb7bceffb5fc2f9d67c6959bd71485862e71bff2
5
5
  SHA512:
6
- metadata.gz: 7bc7d683db890fc147c1149480481af8df86ac9738e39958f251c9aee2eb5a6792ac2fe3e6465b7af798d31f1eccedda273a47ecba99608eda344772eb04548b
7
- data.tar.gz: a0b647bc3512f1ca38a3fadec0a2a77560c7d7b457a564a49cc40b901f00754d6eaa82c37c7f0a01e8234d341252d5e4ee9502adfc53f0a024feabad60bbcbf2
6
+ metadata.gz: 2a3a20edf96dba9d41d837dc44009f4b1bb6eb6136476abd08cfaf882bcde8a213ded999647f2a067548b7b3f089e768390399d7e8f69fdccdbb6f4bcdff871b
7
+ data.tar.gz: 14cb9c5b77e7e4cdc9f153e91c0c8d2f4ae85a292637dcfa5c55d0982ef5b3adb3faa92e140184f318e33b76c00e1106affabf252c270d38e3d4aeca1e369ca5
@@ -37,14 +37,14 @@ module PseudoHiki
37
37
  end
38
38
 
39
39
  class BlockStack < TreeStack
40
- def pop_with_breaker(breaker=nil)
41
- self.current_node.parse_leafs(breaker)
42
- pop
40
+ def pop
41
+ self.current_node.parse_leafs
42
+ super
43
43
  end
44
44
  end
45
45
 
46
46
  class BlockLeaf < BlockStack::Leaf
47
- attr_accessor :nominal_level, :node_id, :decorator
47
+ attr_accessor :nominal_level, :node_id
48
48
 
49
49
  def self.head_re=(head_regex)
50
50
  @self_head_re = head_regex
@@ -84,7 +84,7 @@ module PseudoHiki
84
84
  super(stack)
85
85
  end
86
86
 
87
- def parse_leafs(breaker)
87
+ def parse_leafs
88
88
  parsed = InlineParser.parse(self.join)
89
89
  self.clear
90
90
  self.concat(parsed)
@@ -134,10 +134,6 @@ module PseudoHiki
134
134
  first.nominal_level if first # @cached_nominal_level ||= (first.nominal_level if first)
135
135
  end
136
136
 
137
- def decorator
138
- first.decorator if first
139
- end
140
-
141
137
  def push_self(stack)
142
138
  @stack = stack
143
139
  super(stack)
@@ -147,7 +143,7 @@ module PseudoHiki
147
143
  not (kind_of?(breaker.block) and nominal_level == breaker.nominal_level)
148
144
  end
149
145
 
150
- def parse_leafs(breaker); end
146
+ def parse_leafs; end
151
147
 
152
148
  def in_link_tag?(preceding_str)
153
149
  preceding_str[-2, 2] == "[[".freeze or preceding_str[-1, 1] == "|".freeze
@@ -159,7 +155,7 @@ module PseudoHiki
159
155
 
160
156
  def add_leaf(line, blockparser)
161
157
  leaf = create_leaf(line, blockparser)
162
- blockparser.stack.pop_with_breaker(leaf) while blockparser.breakable?(leaf)
158
+ blockparser.stack.pop while blockparser.breakable?(leaf)
163
159
  blockparser.stack.push leaf
164
160
  end
165
161
 
@@ -171,8 +167,8 @@ module PseudoHiki
171
167
  end
172
168
 
173
169
  class NonNestedBlockNode < BlockNode
174
- def parse_leafs(breaker)
175
- self.each {|leaf| leaf.parse_leafs(breaker) }
170
+ def parse_leafs
171
+ self.each {|leaf| leaf.parse_leafs }
176
172
  end
177
173
  end
178
174
 
@@ -192,11 +188,11 @@ module PseudoHiki
192
188
 
193
189
  module BlockElement
194
190
  {
195
- BlockLeaf => %w(DescLeaf VerbatimLeaf TableLeaf CommentOutLeaf BlockNodeEnd HrLeaf DecoratorLeaf),
191
+ BlockLeaf => %w(DescLeaf VerbatimLeaf TableLeaf CommentOutLeaf BlockNodeEnd HrLeaf),
196
192
  NonNestedBlockLeaf => %w(QuoteLeaf ParagraphLeaf),
197
193
  NestedBlockLeaf => %w(HeadingLeaf),
198
194
  ListTypeLeaf => %w(ListLeaf EnumLeaf),
199
- BlockNode => %w(DescNode VerbatimNode TableNode CommentOutNode HrNode DecoratorNode),
195
+ BlockNode => %w(DescNode VerbatimNode TableNode CommentOutNode HrNode),
200
196
  NonNestedBlockNode => %w(QuoteNode ParagraphNode),
201
197
  NestedBlockNode => %w(HeadingNode),
202
198
  ListTypeBlockNode => %w(ListNode EnumNode),
@@ -221,43 +217,15 @@ module PseudoHiki
221
217
  attr_accessor :in_block_tag
222
218
 
223
219
  def add_leaf(line, blockparser)
224
- return @stack.pop_with_breaker if LINE_PAT::VERBATIM_END =~ line
220
+ return @stack.pop if LINE_PAT::VERBATIM_END =~ line
225
221
  return super(line, blockparser) unless @in_block_tag
226
222
  line = " ".concat(line) if BlockElement::BlockNodeEnd.head_re =~ line and not @in_block_tag
227
223
  @stack.push BlockElement::VerbatimLeaf.create(line, @in_block_tag)
228
224
  end
229
225
  end
230
226
 
231
- class BlockElement::DecoratorNode
232
- DECORATOR_PAT = /\A(?:([^\[\]:]+))?(?:\[([^\[\]]+)\])?(?::\s*(\S.*))?/o
233
-
234
- class DecoratorItem < Struct.new(:string, :type, :id, :value)
235
- def initialize(*args)
236
- super
237
- self.value = InlineParser.parse(self.value) if self.value
238
- end
239
- end
240
-
241
- def parse_leafs(breaker)
242
- decorator = {}
243
- breaker.decorator = decorator
244
- @stack.remove_current_node.each do |leaf|
245
- m = DECORATOR_PAT.match(leaf.join)
246
- return nil unless m
247
- item = DecoratorItem.new(*(m.to_a))
248
- decorator[item.type||:id] = item
249
- end
250
- end
251
-
252
- def breakable?(breaker)
253
- return super if breaker.kind_of?(BlockElement::DecoratorLeaf)
254
- parse_leafs(breaker)
255
- @stack.current_node.breakable?(breaker)
256
- end
257
- end
258
-
259
227
  class BlockElement::QuoteNode
260
- def parse_leafs(breaker)
228
+ def parse_leafs
261
229
  self[0] = BlockParser.parse(self[0])
262
230
  end
263
231
  end
@@ -315,8 +283,7 @@ module PseudoHiki
315
283
  [ParagraphLeaf, ParagraphNode],
316
284
  [HrLeaf, HrNode],
317
285
  [ListLeaf, ListNode],
318
- [EnumLeaf, EnumNode],
319
- [DecoratorLeaf, DecoratorNode]
286
+ [EnumLeaf, EnumNode]
320
287
  ].each do |leaf, node|
321
288
  ParentNode[leaf] = node
322
289
  end
@@ -334,7 +301,6 @@ module PseudoHiki
334
301
  ['!', HeadingLeaf],
335
302
  ['""', QuoteLeaf],
336
303
  ['||', TableLeaf],
337
- ['//@', DecoratorLeaf],
338
304
  ['//', CommentOutLeaf],
339
305
  ['----\s*$', HrLeaf]
340
306
  ].each do |head, leaf|
@@ -373,7 +339,7 @@ module PseudoHiki
373
339
  def read_lines(lines)
374
340
  each_line = lines.respond_to?(:each_line) ? :each_line : :each
375
341
  lines.send(each_line) {|line| @stack.current_node.add_leaf(line, self) }
376
- @stack.pop_with_breaker
342
+ @stack.pop
377
343
  end
378
344
  end
379
345
  end
@@ -61,7 +61,6 @@ module PseudoHiki
61
61
 
62
62
  def visit(tree)
63
63
  htmlelement = create_self_element(tree)
64
- decorate(htmlelement, tree)
65
64
  push_visited_results(htmlelement, tree)
66
65
  htmlelement
67
66
  end
@@ -79,21 +78,6 @@ module PseudoHiki
79
78
  chunks.push tree
80
79
  end
81
80
 
82
- def decorate(htmlelement, tree)
83
- each_decorator(htmlelement, tree) do |element, decorator|
84
- element[CLASS] = HtmlElement.escape(decorator[CLASS].id) if decorator[CLASS]
85
- if id_item = decorator[ID]||decorator[:id]
86
- element[ID] = HtmlElement.escape(id_item.id).upcase
87
- end
88
- end
89
- end
90
-
91
- def each_decorator(element, tree)
92
- return unless element.kind_of? HtmlElement
93
- return unless tree.kind_of? BlockParser::BlockNode and tree.decorator
94
- tree.decorator.tap {|decorator| yield element, decorator }
95
- end
96
-
97
81
  class ListLeafNodeFormatter < self
98
82
  def create_self_element(tree)
99
83
  super(tree).tap do |element|
@@ -192,14 +176,6 @@ module PseudoHiki
192
176
 
193
177
  #for BlockParser
194
178
 
195
- class << Formatter[TableNode]
196
- def decorate(htmlelement, tree)
197
- each_decorator(htmlelement, tree) do |element, decorator|
198
- htmlelement["summary"] = HtmlElement.escape(decorator["summary"].value.join) if decorator["summary"]
199
- end
200
- end
201
- end
202
-
203
179
  class << Formatter[VerbatimNode]
204
180
  def visit(tree)
205
181
  create_self_element.tap do |element|
@@ -284,14 +284,13 @@ module PseudoHiki
284
284
  class VerbatimNodeFormatter < self
285
285
  def visit(tree)
286
286
  element = super(tree)
287
- @language_name = language_name(tree)
288
287
  return gfm_verbatim(element) if @options.gfm_style
289
288
  md_verbatim(element)
290
289
  end
291
290
 
292
291
  def gfm_verbatim(element)
293
292
  element.tap do |lines|
294
- lines.unshift "```#{@language_name + $/}"
293
+ lines.unshift "```#{$/}"
295
294
  lines.push "```#{$/ * 2}"
296
295
  end
297
296
  end
@@ -299,12 +298,6 @@ module PseudoHiki
299
298
  def md_verbatim(element)
300
299
  element.join.gsub(/^/o, " ").sub(/ \Z/o, "").concat $/
301
300
  end
302
-
303
- def language_name(tree)
304
- tree.decorator.tap do |decorator|
305
- return decorator ? decorator["code"].id : ""
306
- end
307
- end
308
301
  end
309
302
 
310
303
  class QuoteNodeFormatter < self
@@ -1,3 +1,3 @@
1
1
  module PseudoHiki
2
- VERSION = "0.0.3.develop"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -131,5 +131,3 @@ module PseudoHiki
131
131
  end
132
132
  end
133
133
  end
134
-
135
- require 'pseudohiki/sinatra_helpers'if defined? Sinatra
@@ -311,35 +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
314
  def test_comment_out_followed_by_a_verbatim_block
344
315
  text = <<TEXT
345
316
  the first paragraph
@@ -696,69 +696,6 @@ HTML
696
696
  assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
697
697
  end
698
698
 
699
- def test_decorator
700
- text = <<TEXT
701
- //@class[section_type]
702
- !!title of section
703
-
704
- a paragraph.
705
-
706
- //@class[class_name]
707
- //@id[id_name]
708
- another paragraph.
709
- TEXT
710
-
711
- xhtml = <<HTML
712
- <div class="section_type">
713
- <h2>title of section</h2>
714
- <p>
715
- a paragraph.</p>
716
- <p class="class_name" id="ID_NAME">
717
- another paragraph.</p>
718
- <!-- end of section_type -->
719
- </div>
720
- HTML
721
- tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
722
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
723
- end
724
-
725
- def test_decorator_for_table
726
- text = <<TEXT
727
- //@summary: Summary of the table
728
- ||!header 1||! header 2
729
- ||cell 1||cell 2
730
- TEXT
731
-
732
- xhtml = <<HTML
733
- <table summary="Summary of the table">
734
- <tr><th>header 1</th><th> header 2</th></tr>
735
- <tr><td>cell 1</td><td>cell 2</td></tr>
736
- </table>
737
- HTML
738
- tree = BlockParser.parse(text.lines.to_a.map {|line| line.chomp })
739
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
740
- end
741
-
742
- def test_decorator_for_verbatim
743
- text = <<TEXT
744
- //@code[ruby]
745
- def bonjour!
746
- puts "Bonjour!"
747
- end
748
- TEXT
749
-
750
- xhtml = <<HTML
751
- <pre>
752
- def bonjour!
753
- puts &quot;Bonjour!&quot;
754
- end
755
- </pre>
756
- HTML
757
-
758
- tree = BlockParser.parse(text.lines.to_a)
759
- assert_equal(xhtml, XhtmlFormat.format(tree).to_s)
760
- end
761
-
762
699
  def test_comment_out_followed_by_a_verbatim_block
763
700
  text = <<TEXT
764
701
  the first paragraph
@@ -518,66 +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
521
  def test_collect_headings
582
522
  text = <<TEXT
583
523
  !![main-heading] heading
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.3.develop
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - HASHIMOTO, Naoki
@@ -74,7 +74,6 @@ files:
74
74
  - lib/pseudohiki/inlineparser.rb
75
75
  - lib/pseudohiki/markdownformat.rb
76
76
  - lib/pseudohiki/plaintextformat.rb
77
- - lib/pseudohiki/sinatra_helpers.rb
78
77
  - lib/pseudohiki/treestack.rb
79
78
  - lib/pseudohiki/utils.rb
80
79
  - lib/pseudohiki/version.rb
@@ -107,9 +106,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
106
  version: 1.8.7
108
107
  required_rubygems_version: !ruby/object:Gem::Requirement
109
108
  requirements:
110
- - - ">"
109
+ - - ">="
111
110
  - !ruby/object:Gem::Version
112
- version: 1.3.1
111
+ version: '0'
113
112
  requirements: []
114
113
  rubyforge_project:
115
114
  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