hparser 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,29 +8,31 @@ module HParser
8
8
  # Some formats have common structure.
9
9
  #
10
10
  # Qutoe is defined as
11
- # >>quoted string<<
11
+ # >>
12
+ # quoted string
13
+ # <<
12
14
  #
13
15
  # Pre is defiend as
14
- # >|plain text|<
16
+ # >|
17
+ # plain text
18
+ # |<
15
19
  #
16
20
  # In short,some format is different in begining/ending string.
17
21
  # So this class have basic structure for that format.
22
+ #
23
+ # Remark:Strictly,quote is defined as "from the line that contain only '>>' to
24
+ # the line that contain only '<<'"
18
25
  class Pair
19
26
  def self.get(scanner,from,to)
20
27
  from_q = Regexp.quote from
21
28
  to_q = Regexp.quote to
22
- if scanner.scan(/\A#{from_q}(.*)#{to_q}\Z/) then
23
- content = scanner.matched
24
- return content[from.length...-to.length].strip
25
- elsif scanner.scan(/\A#{from_q}/)
26
- content = scanner.matched[from.length..-1]
27
- until scanner.scan(/#{to_q}\Z/) do
28
- content += "\n"+ scanner.scan(/./)
29
+ if scanner.scan(/^#{from_q}$/)
30
+ content = ''
31
+ until scanner.scan(/^#{to_q}$/) do
32
+ content += "\n"+ scanner.scan(/.*/)
29
33
  end
30
- content += "\n"+scanner.matched[0...-to.length]
31
34
  return content.strip
32
35
  end
33
- return nil
34
36
  end
35
37
 
36
38
  # make parser by begin/end-ing string
@@ -32,10 +32,8 @@ module HParser
32
32
  end
33
33
 
34
34
  class Empty
35
- include Hatena
36
- private
37
- def hatena_content
38
- ""
35
+ def to_hatena
36
+ ''
39
37
  end
40
38
  end
41
39
 
@@ -55,7 +53,7 @@ module HParser
55
53
  include Hatena
56
54
  alias_method :hatena_content,:content
57
55
  def hatena_filter c
58
- '>>'+c+'<<'
56
+ ">>\n"+c+"\n<<"
59
57
  end
60
58
  end
61
59
 
@@ -63,7 +61,7 @@ module HParser
63
61
  include Hatena
64
62
  alias_method :hatena_content,:content
65
63
  def hatena_filter c
66
- '>|'+c+'|<'
64
+ ">|\n"+c+"\n|<"
67
65
  end
68
66
  end
69
67
 
@@ -71,7 +69,7 @@ module HParser
71
69
  include Hatena
72
70
  alias_method :hatena_content,:content
73
71
  def hatena_filter c
74
- '>||'+c+'||<'
72
+ ">||\n"+c+"\n||<"
75
73
  end
76
74
  end
77
75
 
@@ -14,7 +14,7 @@ module HParser
14
14
  end
15
15
 
16
16
  def self.parse(scanner)
17
- if scanner.scan(%r!<a.*</a>!) or scanner.scan(/./)
17
+ if scanner.scan(%r!<a.*</a>!) or scanner.scan(/./m)
18
18
  Text.new(scanner.matched)
19
19
  end
20
20
  end
data/test/test_hatena.rb CHANGED
@@ -22,17 +22,17 @@ class HatenaTest < Test::Unit::TestCase
22
22
  end
23
23
 
24
24
  def test_empty
25
- assert_hatena "",Empty.new
25
+ assert_equal "",Empty.new.to_hatena
26
26
  end
27
27
 
28
28
  def test_pre
29
- assert_hatena '>|foobar|<',Pre.new([Text.new('foobar')])
30
- assert_hatena '>||foobar||<',SuperPre.new('foobar')
31
- assert_hatena ">|foobar\nbar|<",Pre.new([Text.new("foobar\nbar")])
29
+ assert_hatena ">|\nfoobar\n|<",Pre.new([Text.new('foobar')])
30
+ assert_hatena ">||\nfoobar\n||<",SuperPre.new('foobar')
31
+ assert_hatena ">|\nfoobar\nbar\n|<",Pre.new([Text.new("foobar\nbar")])
32
32
  end
33
33
 
34
34
  def test_quote
35
- assert_hatena '>>foobar<<',Quote.new([Text.new('foobar')])
35
+ assert_hatena ">>\nfoobar\n<<",Quote.new([Text.new('foobar')])
36
36
  end
37
37
 
38
38
  def test_table
data/test/test_inline.rb CHANGED
@@ -16,5 +16,6 @@ class InlineTest < Test::Unit::TestCase
16
16
 
17
17
  def test_text
18
18
  assert_equal [Text.new("foo is bar")],parse("foo is bar")
19
+ assert_equal [Text.new("foo\nbar")],parse("foo\nbar")
19
20
  end
20
21
  end
data/test/test_pair.rb CHANGED
@@ -8,7 +8,7 @@ class QuoteTest < Test::Unit::TestCase
8
8
  include HParser::Inline
9
9
 
10
10
  def setup
11
- @parser = HParser::Parser.new [SuperPre,Pre,Quote]
11
+ @parser = HParser::Parser.new [SuperPre,Pre,Quote,P]
12
12
  end
13
13
 
14
14
  def parse str
@@ -16,8 +16,15 @@ class QuoteTest < Test::Unit::TestCase
16
16
  end
17
17
 
18
18
  def assert_pair(from,to,klass)
19
- assert_equal [klass.new([Text.new("aaa")])], parse("#{from}aaa#{to}")
19
+ assert_equal [P.new([Text.new("#{from}aaa#{to}")])], parse("#{from}aaa#{to}")
20
20
  assert_equal [klass.new([Text.new("aaa")])], parse("#{from}\naaa\n#{to}")
21
+ assert_equal [klass.new([Text.new("aaa\n\nbbb")])],parse(<<-"END")
22
+ #{from}
23
+ aaa
24
+
25
+ bbb
26
+ #{to}
27
+ END
21
28
  end
22
29
 
23
30
  def test_quote
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: hparser
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2006-08-05 00:00:00 +09:00
6
+ version: 0.2.1
7
+ date: 2006-08-09 00:00:00 +09:00
8
8
  summary: Hatena Format Parser
9
9
  require_paths:
10
10
  - lib