marker 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright 2009 Ryan Blue.
2
+ # Copyright 2009-2011 Ryan Blue.
3
3
  # Distributed under the terms of the GNU General Public License (GPL).
4
4
  # See the LICENSE file for further information on the GPL.
5
5
  #++
@@ -7,13 +7,25 @@
7
7
  require 'marker/common'
8
8
 
9
9
  module Marker #:nodoc:
10
- class Paragraph < RecursiveList
10
+ class Paragraph < ParseNode
11
+ def to_html( options = {} )
12
+ if text.no_wrap?
13
+ text.to_html(options)
14
+ else
15
+ "<p>#{text.to_html(options)}</p>"
16
+ end
17
+ end
18
+
19
+ def to_s( options = {} )
20
+ text.to_s(options)
21
+ end
22
+ end
23
+
24
+ class TextBlock < RecursiveList
11
25
  def to_html( options = {} )
12
- '<p>' +
13
26
  to_a.map { |p|
14
27
  p.to_html(options)
15
- }.join(' ') +
16
- '</p>'
28
+ }.join(' ')
17
29
  end
18
30
 
19
31
  # TODO: add wordwrap
@@ -22,6 +34,11 @@ module Marker #:nodoc:
22
34
  p.to_s(options)
23
35
  }.join(' ')
24
36
  end
37
+
38
+ # returns true if this text block does not need to be wrapped in a paragraph
39
+ def no_wrap?
40
+ single? and h.no_wrap?
41
+ end
25
42
  end
26
43
 
27
44
  class Phrase < RecursiveList
@@ -44,6 +61,11 @@ module Marker #:nodoc:
44
61
  (ws and ws.present?) or (aws and aws.present?)
45
62
  end
46
63
 
64
+ # returns true if this phrase does not need to be wrapped in a paragraph
65
+ def no_wrap?
66
+ single? and h.is_a? Template
67
+ end
68
+
47
69
  #-- defaults ++
48
70
  def ws
49
71
  nil
@@ -74,6 +96,16 @@ module Marker #:nodoc:
74
96
  end
75
97
  end
76
98
 
99
+ class Escaped < ParseNode
100
+ def to_html( options = {} )
101
+ text_value.slice(-1,1)
102
+ end
103
+
104
+ def to_s( options = {} )
105
+ text_value.slice(-1,1)
106
+ end
107
+ end
108
+
77
109
  class HorizRule < ParseNode
78
110
  def to_html( options = {} )
79
111
  "<hr />" +
@@ -6,19 +6,19 @@ class EncodingsTest < Test::Unit::TestCase
6
6
  def test_linux_newlines
7
7
  text = "one\ntwo\n\nthree"
8
8
  markup = Marker.parse text
9
- assert_match("<p>one two</p>\n\n<p>three</p>", markup.to_html)
9
+ assert_match("<p>one two</p>\n<p>three</p>", markup.to_html)
10
10
  end
11
11
 
12
12
  def test_windows_newlines
13
13
  text = "one\r\ntwo\r\n\r\nthree"
14
14
  markup = Marker.parse text
15
- assert_match("<p>one two</p>\n\n<p>three</p>", markup.to_html)
15
+ assert_match("<p>one two</p>\n<p>three</p>", markup.to_html)
16
16
  end
17
17
 
18
18
  def test_mac_newlines
19
19
  text = "one\rtwo\r\rthree"
20
20
  markup = Marker.parse text
21
- assert_match("<p>one two</p>\n\n<p>three</p>", markup.to_html)
21
+ assert_match("<p>one two</p>\n<p>three</p>", markup.to_html)
22
22
  end
23
23
 
24
24
  end
@@ -69,7 +69,7 @@ class FormattingTest < Test::Unit::TestCase
69
69
  text = "paragraph 1\n\nparagraph 2\n\nparagraph 3"
70
70
  markup = Marker.parse text
71
71
 
72
- assert_match("<p>paragraph 1</p>\n\n<p>paragraph 2</p>\n\n<p>paragraph 3</p>", markup.to_html)
72
+ assert_match("<p>paragraph 1</p>\n<p>paragraph 2</p>\n<p>paragraph 3</p>", markup.to_html)
73
73
  end
74
74
 
75
75
  def test_newlines_in_paragraphs
@@ -0,0 +1,9 @@
1
+ # helper methods for tests
2
+
3
+ module MarkerTestHelpers
4
+ def assert_renders_html( expected_html, markup )
5
+ end
6
+
7
+ def assert_renders_text( expected_text, markup )
8
+ end
9
+ end
@@ -14,7 +14,7 @@ class ListTest < Test::Unit::TestCase
14
14
  text = "* List item 1\n** List item 2\n* List item 3"
15
15
  markup = Marker.parse text
16
16
 
17
- assert_match("<ul><li>List item 1</li><ul><li>List item 2</li></ul><li>List item 3</li></ul>", markup.to_html)
17
+ assert_match("<ul><li>List item 1<ul><li>List item 2</li></ul></li><li>List item 3</li></ul>", markup.to_html)
18
18
  end
19
19
 
20
20
  def test_numbered_list
@@ -28,7 +28,7 @@ class ListTest < Test::Unit::TestCase
28
28
  text = "# List item 1\n## List item 2\n# List item 3"
29
29
  markup = Marker.parse text
30
30
 
31
- assert_match("<ol><li>List item 1</li><ol><li>List item 2</li></ol><li>List item 3</li></ol>", markup.to_html)
31
+ assert_match("<ol><li>List item 1<ol><li>List item 2</li></ol></li><li>List item 3</li></ol>", markup.to_html)
32
32
  end
33
33
 
34
34
  def test_definition_list
@@ -59,15 +59,22 @@ class ListTest < Test::Unit::TestCase
59
59
  markup = Marker.parse text
60
60
 
61
61
  assert_match("<ol><li>List item 1</li></ol><ul><li>List item 2</li></ul><ol><li>List item 3</li></ol><dl><dt>List item 4</dt>" +
62
- "<dd>definition</dd></dl><div class='indent'><div>List item 5</div></div><ul><li>List item 6</li></ul>", markup.to_html)
62
+ "<dd>definition</dd></dl><div class='indent'><div class='indented_item'>List item 5</div></div><ul><li>List item 6</li></ul>", markup.to_html)
63
63
  end
64
64
 
65
65
  def test_nested_mixed_list
66
66
  text = "# List item 1\n#* List item 2\n# List item 3\n## List item 4\n#; List item 5 : definition\n#:List item 6"
67
67
  markup = Marker.parse text
68
68
 
69
- assert_match("<ol><li>List item 1</li><ul><li>List item 2</li></ul><li>List item 3</li><ol><li>List item 4</li></ol>" +
70
- "<dl><dt>List item 5</dt><dd>definition</dd></dl><div class='indent'><div>List item 6</div></div></ol>", markup.to_html)
69
+ assert_match("<ol><li>List item 1<ul><li>List item 2</li></ul></li><li>List item 3<ol><li>List item 4</li></ol>" +
70
+ "<dl><dt>List item 5</dt><dd>definition</dd></dl><div class='indent'><div class='indented_item'>List item 6</div></div></li></ol>", markup.to_html)
71
+ end
72
+
73
+ def test_bare_nested_list
74
+ text = "*** item"
75
+ markup = Marker.parse text
76
+
77
+ assert_match("<ul><li><ul><li><ul><li>item</li></ul></li></ul></li></ul>", markup.to_html)
71
78
  end
72
79
 
73
80
  end
@@ -1,55 +1,170 @@
1
1
  require File.expand_path( File.dirname( __FILE__ ) + '/test_helper' )
2
2
  require 'marker'
3
3
 
4
- class TemplatesTest < Test::Unit::TestCase
4
+ class TemplatesTest < MarkerTest
5
+
6
+ DEFAULT_OPTIONS = '{:link_base=>"", :footnotes=>}'
5
7
 
6
8
  def test_basic_template
7
9
  text = "{{ template }}"
8
- markup = Marker.parse text
10
+ markup = parse_with_assertions text
11
+ html = markup.to_html
9
12
 
10
- assert_match("<p>render:template( :html, [], {} )</p>", markup.to_html)
13
+ assert_match("render:template( :html, [], {}, #{DEFAULT_OPTIONS} )", html, text)
14
+ assert_no_match(/<div/, html, text)
11
15
  end
12
16
 
13
- def test_positional_args
17
+ def test_ordered_args
14
18
  text = "{{ template | one | two | three }}"
15
- markup = Marker.parse text
16
-
17
- assert_match("<p>render:template( :html, [\"one\", \"two\", \"three\"], {} )</p>", markup.to_html)
19
+ markup = parse_with_assertions text
20
+ html = markup.to_html
21
+
22
+ assert_match("render:template( :html, [\"one\", \"two\", \"three\"], {}, #{DEFAULT_OPTIONS} )", html, text)
23
+ assert_no_match(/<div/, html, text)
18
24
  end
19
25
 
20
26
  def test_named_args
21
27
  text = "{{ template | one=1 | two = 2 }}"
22
- markup = Marker.parse text
23
-
24
- # might want to fix this assertion, the hash could come out in any order
25
- assert_match("<p>render:template( :html, [], {", markup.to_html)
26
- assert_match("\"two\"=>\"2\"", markup.to_html)
27
- assert_match("\"one\"=>\"1\"", markup.to_html)
28
- assert_match("} )</p>", markup.to_html)
28
+ markup = parse_with_assertions text
29
+ html = markup.to_html
30
+
31
+ assert_match("render:template( :html, [], {", html, text)
32
+ assert_match("\"two\"=>\"2\"", html, text)
33
+ assert_match("\"one\"=>\"1\"", html, text)
34
+ assert_match("}, #{DEFAULT_OPTIONS} )", html, text)
35
+ assert_no_match(/<div/, html, text)
29
36
  end
30
37
 
31
38
  def test_mixed_args
32
39
  text = "{{ template | one | two = 2 | three }}"
33
- markup = Marker.parse text
34
-
35
- assert_match("<p>render:template( :html, [\"one\", \"three\"], {\"two\"=>\"2\"} )</p>", markup.to_html)
40
+ markup = parse_with_assertions text
41
+ html = markup.to_html
42
+
43
+ assert_match("render:template( :html, [\"one\", \"three\"], {\"two\"=>\"2\"}, #{DEFAULT_OPTIONS} )", html, text)
44
+ assert_no_match(/<div/, html, text)
36
45
  end
37
46
 
38
47
  def test_empty_args
39
48
  text = "{{ template | }}"
40
- markup = Marker.parse text
41
- assert_match("<p>render:template( :html, [\"\"], {} )</p>", markup.to_html)
49
+ markup = parse_with_assertions text
50
+ html = markup.to_html
51
+ assert_match("render:template( :html, [\"\"], {}, #{DEFAULT_OPTIONS} )", html, text)
52
+ assert_no_match(/<div/, html, text)
42
53
 
43
54
  text = "{{ template | | }}"
44
- markup = Marker.parse text
45
- assert_match("<p>render:template( :html, [\"\", \"\"], {} )</p>", markup.to_html)
55
+ markup = parse_with_assertions text
56
+ html = markup.to_html
57
+ assert_match("render:template( :html, [\"\", \"\"], {}, #{DEFAULT_OPTIONS} )", html, text)
58
+ assert_no_match(/<div/, html, text)
46
59
  end
47
60
 
48
61
  def test_rendered_args
49
62
  text = "{{ template | [http://www.example.com Example] }}"
50
- markup = Marker.parse text
63
+ markup = parse_with_assertions text
64
+ html = markup.to_html
65
+
66
+ assert_match("render:template( :html, [\"<a href='http://www.example.com'>Example</a>\"], {}, #{DEFAULT_OPTIONS} )", html, text)
67
+ assert_no_match(/<div/, html, text)
68
+ end
69
+
70
+ def test_escaped_characters
71
+ # keep in mind here that the default template rendering (that produces
72
+ # "render:name(*args)") inserts the template arguments by using
73
+ # String#inspect, so everything that is produced will be escaped.
74
+ text = '{{ template | \| | a \= b | \|a, b\| }}'
75
+ markup = parse_with_assertions text
76
+ html = markup.to_html
77
+
78
+ # escaping delimiters is not supported (and may not ever be)
79
+ #assert_match("render:template( :html, [\"|\", \"a = b\", \"|a, b|\"], {}, #{DEFAULT_OPTIONS} )", html, text)
80
+ assert_no_match(/<div/, html, text)
81
+ end
82
+
83
+ def test_line_anchored_markup_inside_templates
84
+ text = "{{ ruby code |\n puts 'hello'\n}}"
85
+ markup = parse_with_assertions text
86
+ html = markup.to_html
87
+
88
+ assert_match("render:ruby_code( :html, [\"<pre>\\nputs 'hello'\\n</pre>\"], {}, #{DEFAULT_OPTIONS} )", html, text)
89
+ assert_match(/<div/, html, text)
90
+ end
91
+
92
+ def test_verbatim_arg_without_final_newline
93
+ text = "{{ ruby code |\n puts 'hello'}}"
94
+ markup = parse_with_assertions text
95
+ html = markup.to_html
96
+
97
+ assert_match("render:ruby_code( :html, [\"<pre>\\nputs 'hello'\\n</pre>\"], {}, #{DEFAULT_OPTIONS} )", html, text)
98
+ assert_match(/<div/, html, text)
99
+ end
100
+
101
+ def test_verbatim_arg_without_newline_before_pipe
102
+ text = "{{ ruby code |\n puts 'hello'| another arg }}"
103
+ markup = parse_with_assertions text
104
+ html = markup.to_html
105
+
106
+ assert_match("render:ruby_code( :html, [\"<pre>\\nputs 'hello'\\n</pre>\", \"another arg\"], {}, #{DEFAULT_OPTIONS} )", html, text)
107
+ assert_match(/<div/, html, text)
108
+ end
109
+
110
+ def test_line_anchored_markup_inside_templates_with_blank_lines
111
+ text = "{{ ruby code |\n puts 'hello'\n\n* list}}"
112
+ markup = parse_with_assertions text
113
+ html = markup.to_html
114
+
115
+ assert_match("render:ruby_code( :html, [\"<pre>\\nputs 'hello'\\n</pre>\\n<ul><li>list</li></ul>\"], {}, #{DEFAULT_OPTIONS} )", html, text)
116
+ assert_match(/<div/, html, text)
117
+ end
118
+
119
+ def test_multiline_inline_arguments
120
+ text = "this is a {{bold|paragraph\nwith some bold text}} in it."
121
+ markup = parse_with_assertions text
122
+ html = markup.to_html
123
+
124
+ assert_match("this is a render:bold( :html, [\"paragraph with some bold text\"], {}, #{DEFAULT_OPTIONS} ) in it.", html, text)
125
+ assert_no_match(/<div/, html, text)
126
+ end
127
+
128
+ def test_multiparagraph_inline_arguments
129
+ text = "this is a {{bold|paragraph\n\nwith some bold text}} in it."
130
+ markup = parse_with_assertions text
131
+ html = markup.to_html
132
+
133
+ assert_match("this is a <div class=\'bold\'>render:bold( :html, [\"<p>paragraph</p>\\n<p>with some bold text</p>\"], {}, #{DEFAULT_OPTIONS} )</div> in it.", html, text)
134
+ assert_match(/<div/, html, text)
135
+ end
136
+
137
+ def test_list_with_starting_newline
138
+ text = "{{ inner list |\n* list item 1\n*list item 2}}"
139
+ markup = parse_with_assertions text
140
+ html = markup.to_html
141
+
142
+ assert_match("render:inner_list( :html, [\"<ul><li>list item 1</li><li>list item 2</li></ul>\"], {}, #{DEFAULT_OPTIONS} )", html, text)
143
+ assert_match(/<div/, html, text)
144
+ end
145
+
146
+ def test_list_with_starting_unsafe_text
147
+ # you might expect this to render as a two-item list, but this is one of
148
+ # the ways Marker differs with MediaWiki. For consistency, Marker will not
149
+ # treat any text that doesn't appear at the start a line as line anchored
150
+ # markup. Otherwise, cases like this would behave strangely:
151
+ # {{ template | should this be verbatim? }}
152
+ #
153
+ text = "{{ inner list |* list item 1\n*list item 2}}"
154
+ markup = parse_with_assertions text
155
+ html = markup.to_html
156
+
157
+ assert_match("render:inner_list( :html, [\"<p>* list item 1</p>\\n<ul><li>list item 2</li></ul>\"], {}, #{DEFAULT_OPTIONS} )", html, text)
158
+ assert_match(/<div/, html, text)
159
+ end
160
+
161
+ def test_forced_block_argument
162
+ text = "{{ block |\nnormal text}}"
163
+ markup = parse_with_assertions text
164
+ html = markup.to_html
51
165
 
52
- assert_match("<p>render:template( :html, [\"<a href='http://www.example.com'>Example</a>\"], {} )</p>", markup.to_html)
166
+ assert_match("render:block( :html, [\"<p>normal text</p>\"], {}, #{DEFAULT_OPTIONS} )", html, text)
167
+ assert_match(/<div/, html, text)
53
168
  end
54
169
 
55
170
  end
@@ -1,2 +1,13 @@
1
1
  require 'test/unit'
2
- $LOAD_PATH << File.expand_path( File.dirname(__FILE__) + '/../lib' )
2
+ $LOAD_PATH.unshift File.expand_path( File.dirname(__FILE__) + '/../lib' )
3
+
4
+ class MarkerTest < Test::Unit::TestCase
5
+ def parse_with_assertions( text )
6
+ tree = nil
7
+ assert_nothing_raised do
8
+ tree = Marker.parse( text )
9
+ end
10
+ assert_not_nil( tree, Marker.parser.failure_reason )
11
+ tree
12
+ end
13
+ end
metadata CHANGED
@@ -1,95 +1,94 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: marker
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 3
9
- version: 0.3.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Ryan Blue
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-06-03 00:00:00 +02:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: treetop
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 4
30
- - 2
31
- version: 1.4.2
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.4'
32
22
  type: :runtime
33
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.4'
34
30
  description:
35
31
  email: rdblue@gmail.com
36
- executables:
32
+ executables:
37
33
  - marker
38
34
  extensions: []
39
-
40
- extra_rdoc_files:
35
+ extra_rdoc_files:
41
36
  - README
42
37
  - LICENSE
43
- files:
38
+ files:
44
39
  - bin/marker
40
+ - lib/marker.rb
41
+ - lib/marker/links.rb
45
42
  - lib/marker/common.rb
43
+ - lib/marker/templates.rb
46
44
  - lib/marker/lists.rb
47
- - lib/marker/headings.rb
48
- - lib/marker/text.rb
49
45
  - lib/marker/markup.rb
46
+ - lib/marker/text.rb
47
+ - lib/marker/headings.rb
50
48
  - lib/marker/verbatim.rb
51
- - lib/marker/links.rb
52
- - lib/marker/templates.rb
53
- - lib/marker.rb
54
49
  - lib/marker/language.treetop
55
50
  - README
56
51
  - LICENSE
57
- has_rdoc: true
52
+ - test/encodings_test.rb
53
+ - test/headings_test.rb
54
+ - test/formatting_test.rb
55
+ - test/lists_test.rb
56
+ - test/links_test.rb
57
+ - test/test_helper.rb
58
+ - test/templates_test.rb
59
+ - test/verbatim_test.rb
60
+ - test/helper.rb
58
61
  homepage: http://github.com/rdblue/marker
59
62
  licenses: []
60
-
61
63
  post_install_message:
62
64
  rdoc_options: []
63
-
64
- require_paths:
65
+ require_paths:
65
66
  - lib
66
- required_ruby_version: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- segments:
71
- - 0
72
- version: "0"
73
- required_rubygems_version: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- segments:
78
- - 0
79
- version: "0"
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
80
79
  requirements: []
81
-
82
80
  rubyforge_project:
83
- rubygems_version: 1.3.6
81
+ rubygems_version: 1.8.24
84
82
  signing_key:
85
83
  specification_version: 3
86
84
  summary: A markup parser that outputs html and text. Syntax is similar to MediaWiki.
87
- test_files:
88
- - test/verbatim_test.rb
85
+ test_files:
86
+ - test/encodings_test.rb
89
87
  - test/headings_test.rb
90
- - test/links_test.rb
91
- - test/test_helper.rb
92
88
  - test/formatting_test.rb
93
- - test/encodings_test.rb
94
89
  - test/lists_test.rb
90
+ - test/links_test.rb
91
+ - test/test_helper.rb
95
92
  - test/templates_test.rb
93
+ - test/verbatim_test.rb
94
+ - test/helper.rb