wikitext 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/ext/parser.c CHANGED
@@ -42,6 +42,7 @@ typedef struct
42
42
  int base_indent; // controlled by the :indent option to Wikitext::Parser#parse
43
43
  int current_indent; // fluctuates according to currently nested structures
44
44
  str_t *tabulation; // caching buffer for emitting indentation
45
+ int base_heading_level;
45
46
  } parser_t;
46
47
 
47
48
  const char escaped_no_wiki_start[] = "<nowiki>";
@@ -289,6 +290,16 @@ void _Wikitext_pop_from_stack(parser_t *parser, VALUE target)
289
290
  return;
290
291
  if (NIL_P(target))
291
292
  target = parser->output;
293
+
294
+ // for headings, take base_heading_level into account
295
+ if (top >= H1_START && top <= H6_START)
296
+ {
297
+ top += parser->base_heading_level;
298
+ // no need to check for underflow (base_heading_level is never negative)
299
+ if (top > H6_START)
300
+ top = H6_START;
301
+ }
302
+
292
303
  switch (top)
293
304
  {
294
305
  case PRE:
@@ -883,6 +894,7 @@ VALUE Wikitext_parser_initialize(int argc, VALUE *argv, VALUE self)
883
894
  VALUE img_prefix = rb_str_new2("/images/");
884
895
  VALUE space_to_underscore = Qtrue;
885
896
  VALUE minimum_fulltext_token_length = INT2NUM(3);
897
+ VALUE base_heading_level = INT2NUM(0);
886
898
 
887
899
  // process options hash (override defaults)
888
900
  if (!NIL_P(options) && TYPE(options) == T_HASH)
@@ -897,6 +909,7 @@ VALUE Wikitext_parser_initialize(int argc, VALUE *argv, VALUE self)
897
909
  img_prefix = OVERRIDE_IF_SET(img_prefix);
898
910
  space_to_underscore = OVERRIDE_IF_SET(space_to_underscore);
899
911
  minimum_fulltext_token_length = OVERRIDE_IF_SET(minimum_fulltext_token_length);
912
+ base_heading_level = OVERRIDE_IF_SET(base_heading_level);
900
913
  }
901
914
 
902
915
  // no need to call super here; rb_call_super()
@@ -908,6 +921,7 @@ VALUE Wikitext_parser_initialize(int argc, VALUE *argv, VALUE self)
908
921
  rb_iv_set(self, "@img_prefix", img_prefix);
909
922
  rb_iv_set(self, "@space_to_underscore", space_to_underscore);
910
923
  rb_iv_set(self, "@minimum_fulltext_token_length", minimum_fulltext_token_length);
924
+ rb_iv_set(self, "@base_heading_level", base_heading_level);
911
925
  return self;
912
926
  }
913
927
 
@@ -930,18 +944,28 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
930
944
 
931
945
  // process options hash
932
946
  int base_indent = 0;
933
- VALUE indent = Qnil;
947
+ int base_heading_level = NUM2INT(rb_iv_get(self, "@base_heading_level"));
934
948
  if (!NIL_P(options) && TYPE(options) == T_HASH)
935
949
  {
950
+ // :indent => 0 (or more)
936
951
  if (rb_funcall(options, rb_intern("has_key?"), 1, ID2SYM(rb_intern("indent"))) == Qtrue)
937
952
  {
938
- indent = rb_hash_aref(options, ID2SYM(rb_intern("indent")));
939
- base_indent = NUM2INT(indent);
953
+ base_indent = NUM2INT(rb_hash_aref(options, ID2SYM(rb_intern("indent"))));
940
954
  if (base_indent < 0)
941
955
  base_indent = 0;
942
956
  }
957
+
958
+ // :base_heading_level => 0/1/2/3/4/5/6
959
+ if (rb_funcall(options, rb_intern("has_key?"), 1, ID2SYM(rb_intern("base_heading_level"))) == Qtrue)
960
+ base_heading_level = NUM2INT(rb_hash_aref(options, ID2SYM(rb_intern("base_heading_level"))));
943
961
  }
944
962
 
963
+ // normalize, regardless of whether this came from instance variable or override
964
+ if (base_heading_level < 0)
965
+ base_heading_level = 0;
966
+ if (base_heading_level > 6)
967
+ base_heading_level = 6;
968
+
945
969
  // set up scanner
946
970
  char *p = RSTRING_PTR(string);
947
971
  long len = RSTRING_LEN(string);
@@ -981,6 +1005,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
981
1005
  parser->current_indent = 0;
982
1006
  parser->tabulation = str_new();
983
1007
  GC_WRAP_STR(parser->tabulation, tabulation_gc);
1008
+ parser->base_heading_level = base_heading_level;
984
1009
 
985
1010
  // this simple looping design leads to a single enormous function,
986
1011
  // but it's faster than doing actual recursive descent and also secure in the face of
@@ -1716,6 +1741,11 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
1716
1741
  ary_push(parser->scope, type);
1717
1742
  _Wikitext_indent(parser);
1718
1743
 
1744
+ // take base_heading_level into account
1745
+ type += base_heading_level;
1746
+ if (type > H6_START) // no need to check for underflow (base_heading_level never negative)
1747
+ type = H6_START;
1748
+
1719
1749
  // rather than repeat all that code for each kind of heading, share it and use a conditional here
1720
1750
  if (type == H6_START)
1721
1751
  rb_str_cat(parser->output, h6_start, sizeof(h6_start) - 1);
data/ext/token.c CHANGED
@@ -49,18 +49,18 @@ VALUE Wikitext_parser_token_types(VALUE self)
49
49
  SET_TOKEN_TYPE(TT);
50
50
  SET_TOKEN_TYPE(OL);
51
51
  SET_TOKEN_TYPE(UL);
52
- SET_TOKEN_TYPE(H6_START);
53
- SET_TOKEN_TYPE(H5_START);
54
- SET_TOKEN_TYPE(H4_START);
55
- SET_TOKEN_TYPE(H3_START);
56
- SET_TOKEN_TYPE(H2_START);
57
52
  SET_TOKEN_TYPE(H1_START);
58
- SET_TOKEN_TYPE(H6_END);
59
- SET_TOKEN_TYPE(H5_END);
60
- SET_TOKEN_TYPE(H4_END);
61
- SET_TOKEN_TYPE(H3_END);
62
- SET_TOKEN_TYPE(H2_END);
53
+ SET_TOKEN_TYPE(H2_START);
54
+ SET_TOKEN_TYPE(H3_START);
55
+ SET_TOKEN_TYPE(H4_START);
56
+ SET_TOKEN_TYPE(H5_START);
57
+ SET_TOKEN_TYPE(H6_START);
63
58
  SET_TOKEN_TYPE(H1_END);
59
+ SET_TOKEN_TYPE(H2_END);
60
+ SET_TOKEN_TYPE(H3_END);
61
+ SET_TOKEN_TYPE(H4_END);
62
+ SET_TOKEN_TYPE(H5_END);
63
+ SET_TOKEN_TYPE(H6_END);
64
64
  SET_TOKEN_TYPE(URI);
65
65
  SET_TOKEN_TYPE(MAIL);
66
66
  SET_TOKEN_TYPE(PATH);
data/ext/token.h CHANGED
@@ -55,18 +55,24 @@ enum token_types {
55
55
  TT,
56
56
  OL,
57
57
  UL,
58
- H6_START,
59
- H5_START,
60
- H4_START,
61
- H3_START,
62
- H2_START,
58
+
59
+ // keep these consecutive, and in ascending order
60
+ // (the arithmetic for the base_heading_level feature assumes this)
63
61
  H1_START,
64
- H6_END,
65
- H5_END,
66
- H4_END,
67
- H3_END,
68
- H2_END,
62
+ H2_START,
63
+ H3_START,
64
+ H4_START,
65
+ H5_START,
66
+ H6_START,
67
+
68
+ // likewise for the H*_END tokens
69
69
  H1_END,
70
+ H2_END,
71
+ H3_END,
72
+ H4_END,
73
+ H5_END,
74
+ H6_END,
75
+
70
76
  URI,
71
77
  MAIL,
72
78
  PATH,
data/ext/wikitext.c CHANGED
@@ -44,6 +44,7 @@ void Init_wikitext()
44
44
  rb_define_attr(cWikitextParser, "autolink", Qtrue, Qtrue);
45
45
  rb_define_attr(cWikitextParser, "space_to_underscore", Qtrue, Qtrue);
46
46
  rb_define_attr(cWikitextParser, "minimum_fulltext_token_length", Qtrue, Qtrue);
47
+ rb_define_attr(cWikitextParser, "base_heading_level", Qtrue, Qtrue);
47
48
 
48
49
  // Wikitext::Parser::Error
49
50
  eWikitextParserError = rb_define_class_under(cWikitextParser, "Error", rb_eException);
@@ -13,5 +13,5 @@
13
13
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
14
14
 
15
15
  module Wikitext
16
- VERSION = '1.4.1'
16
+ VERSION = '1.5.0'
17
17
  end # module Wikitext
@@ -0,0 +1,334 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright 2009 Wincent Colaiuta
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+
16
+ require File.join(File.dirname(__FILE__), 'spec_helper.rb')
17
+ require 'wikitext/parser'
18
+
19
+ describe Wikitext::Parser, 'base_heading_level' do
20
+ before do
21
+ @parser = Wikitext::Parser.new
22
+ end
23
+
24
+ it 'should default to 0' do
25
+ @parser.base_heading_level.should == 0
26
+ end
27
+
28
+ it 'should be settable after initialization' do
29
+ @parser.base_heading_level = 4
30
+ @parser.base_heading_level.should == 4
31
+ end
32
+
33
+ it 'should be overrideable at initialization time' do
34
+ parser = Wikitext::Parser.new :base_heading_level => 3
35
+ parser.base_heading_level.should == 3
36
+ end
37
+
38
+ it 'should be overrideable at parse time' do
39
+ lambda { @parser.parse 'foo', :base_heading_level => 2 }.should_not raise_error
40
+ end
41
+
42
+ it 'should complain if overridden with non-integer value' do
43
+ lambda { @parser.parse 'foo', :base_heading_level => 'foo' }.should raise_error(TypeError)
44
+ lambda {
45
+ @parser.base_heading_level = 'bar'
46
+ @parser.parse 'foo' # error actually gets raised only at parse time
47
+ }.should raise_error(TypeError)
48
+ lambda {
49
+ parser = Wikitext::Parser.new :base_heading_level => 'baz'
50
+ parser.parse 'foo' # error actually gets raised only at parse time
51
+ }.should raise_error(TypeError)
52
+ end
53
+
54
+ # these tested additionally below
55
+ it 'should handle negative levels' do
56
+ @parser.base_heading_level = -1
57
+ @parser.parse('== hello ==').should == "<h2>hello</h2>\n"
58
+ @parser.base_heading_level = -2
59
+ @parser.parse('== hello ==').should == "<h2>hello</h2>\n"
60
+ @parser.base_heading_level = -3
61
+ @parser.parse('== hello ==').should == "<h2>hello</h2>\n"
62
+ @parser.base_heading_level = -4
63
+ @parser.parse('== hello ==').should == "<h2>hello</h2>\n"
64
+ @parser.base_heading_level = -5
65
+ @parser.parse('== hello ==').should == "<h2>hello</h2>\n"
66
+ @parser.base_heading_level = -6
67
+ @parser.parse('== hello ==').should == "<h2>hello</h2>\n"
68
+ end
69
+
70
+ # these tested additionally below
71
+ it 'should handle oversized levels (greater than six)' do
72
+ @parser.base_heading_level = 7
73
+ @parser.parse('= hello =').should == "<h6>hello</h6>\n"
74
+ @parser.base_heading_level = 8
75
+ @parser.parse('= hello =').should == "<h6>hello</h6>\n"
76
+ @parser.base_heading_level = 9
77
+ @parser.parse('= hello =').should == "<h6>hello</h6>\n"
78
+ @parser.base_heading_level = 10
79
+ @parser.parse('= hello =').should == "<h6>hello</h6>\n"
80
+ @parser.base_heading_level = 11
81
+ @parser.parse('= hello =').should == "<h6>hello</h6>\n"
82
+ @parser.base_heading_level = 12
83
+ @parser.parse('= hello =').should == "<h6>hello</h6>\n"
84
+ end
85
+
86
+ # here we use a negative value
87
+ it 'should treat the three different override methods as equivalent (level: -1)' do
88
+ @parser.base_heading_level = -1
89
+ @parser.parse('= hello =').should == "<h1>hello</h1>\n"
90
+ @parser.parse('== hello ==').should == "<h2>hello</h2>\n"
91
+ @parser.parse('=== hello ===').should == "<h3>hello</h3>\n"
92
+ @parser.parse('==== hello ====').should == "<h4>hello</h4>\n"
93
+ @parser.parse('===== hello =====').should == "<h5>hello</h5>\n"
94
+ @parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
95
+
96
+ @parser.parse('= hello =', :base_heading_level => -1).should == "<h1>hello</h1>\n"
97
+ @parser.parse('== hello ==', :base_heading_level => -1).should == "<h2>hello</h2>\n"
98
+ @parser.parse('=== hello ===', :base_heading_level => -1).should == "<h3>hello</h3>\n"
99
+ @parser.parse('==== hello ====', :base_heading_level => -1).should == "<h4>hello</h4>\n"
100
+ @parser.parse('===== hello =====', :base_heading_level => -1).should == "<h5>hello</h5>\n"
101
+ @parser.parse('====== hello ======', :base_heading_level => -1).should == "<h6>hello</h6>\n"
102
+
103
+ parser = Wikitext::Parser.new :base_heading_level => -1
104
+ parser.parse('= hello =').should == "<h1>hello</h1>\n"
105
+ parser.parse('== hello ==').should == "<h2>hello</h2>\n"
106
+ parser.parse('=== hello ===').should == "<h3>hello</h3>\n"
107
+ parser.parse('==== hello ====').should == "<h4>hello</h4>\n"
108
+ parser.parse('===== hello =====').should == "<h5>hello</h5>\n"
109
+ parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
110
+ end
111
+
112
+ it 'should treat the three different override methods as equivalent (level: 0)' do
113
+ @parser.base_heading_level = 0
114
+ @parser.parse('= hello =').should == "<h1>hello</h1>\n"
115
+ @parser.parse('== hello ==').should == "<h2>hello</h2>\n"
116
+ @parser.parse('=== hello ===').should == "<h3>hello</h3>\n"
117
+ @parser.parse('==== hello ====').should == "<h4>hello</h4>\n"
118
+ @parser.parse('===== hello =====').should == "<h5>hello</h5>\n"
119
+ @parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
120
+
121
+ @parser.parse('= hello =', :base_heading_level => 0).should == "<h1>hello</h1>\n"
122
+ @parser.parse('== hello ==', :base_heading_level => 0).should == "<h2>hello</h2>\n"
123
+ @parser.parse('=== hello ===', :base_heading_level => 0).should == "<h3>hello</h3>\n"
124
+ @parser.parse('==== hello ====', :base_heading_level => 0).should == "<h4>hello</h4>\n"
125
+ @parser.parse('===== hello =====', :base_heading_level => 0).should == "<h5>hello</h5>\n"
126
+ @parser.parse('====== hello ======', :base_heading_level => 0).should == "<h6>hello</h6>\n"
127
+
128
+ parser = Wikitext::Parser.new :base_heading_level => 0
129
+ parser.parse('= hello =').should == "<h1>hello</h1>\n"
130
+ parser.parse('== hello ==').should == "<h2>hello</h2>\n"
131
+ parser.parse('=== hello ===').should == "<h3>hello</h3>\n"
132
+ parser.parse('==== hello ====').should == "<h4>hello</h4>\n"
133
+ parser.parse('===== hello =====').should == "<h5>hello</h5>\n"
134
+ parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
135
+ end
136
+
137
+ it 'should treat the three different override methods as equivalent (level: 1)' do
138
+ @parser.base_heading_level = 1
139
+ @parser.parse('= hello =').should == "<h2>hello</h2>\n"
140
+ @parser.parse('== hello ==').should == "<h3>hello</h3>\n"
141
+ @parser.parse('=== hello ===').should == "<h4>hello</h4>\n"
142
+ @parser.parse('==== hello ====').should == "<h5>hello</h5>\n"
143
+ @parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
144
+ @parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
145
+
146
+ @parser.parse('= hello =', :base_heading_level => 1).should == "<h2>hello</h2>\n"
147
+ @parser.parse('== hello ==', :base_heading_level => 1).should == "<h3>hello</h3>\n"
148
+ @parser.parse('=== hello ===', :base_heading_level => 1).should == "<h4>hello</h4>\n"
149
+ @parser.parse('==== hello ====', :base_heading_level => 1).should == "<h5>hello</h5>\n"
150
+ @parser.parse('===== hello =====', :base_heading_level => 1).should == "<h6>hello</h6>\n"
151
+ @parser.parse('====== hello ======', :base_heading_level => 1).should == "<h6>hello</h6>\n"
152
+
153
+ parser = Wikitext::Parser.new :base_heading_level => 1
154
+ parser.parse('= hello =').should == "<h2>hello</h2>\n"
155
+ parser.parse('== hello ==').should == "<h3>hello</h3>\n"
156
+ parser.parse('=== hello ===').should == "<h4>hello</h4>\n"
157
+ parser.parse('==== hello ====').should == "<h5>hello</h5>\n"
158
+ parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
159
+ parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
160
+ end
161
+
162
+ it 'should treat the three different override methods as equivalent (level: 2)' do
163
+ @parser.base_heading_level = 2
164
+ @parser.parse('= hello =').should == "<h3>hello</h3>\n"
165
+ @parser.parse('== hello ==').should == "<h4>hello</h4>\n"
166
+ @parser.parse('=== hello ===').should == "<h5>hello</h5>\n"
167
+ @parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
168
+ @parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
169
+ @parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
170
+
171
+ @parser.parse('= hello =', :base_heading_level => 2).should == "<h3>hello</h3>\n"
172
+ @parser.parse('== hello ==', :base_heading_level => 2).should == "<h4>hello</h4>\n"
173
+ @parser.parse('=== hello ===', :base_heading_level => 2).should == "<h5>hello</h5>\n"
174
+ @parser.parse('==== hello ====', :base_heading_level => 2).should == "<h6>hello</h6>\n"
175
+ @parser.parse('===== hello =====', :base_heading_level => 2).should == "<h6>hello</h6>\n"
176
+ @parser.parse('====== hello ======', :base_heading_level => 2).should == "<h6>hello</h6>\n"
177
+
178
+ parser = Wikitext::Parser.new :base_heading_level => 2
179
+ parser.parse('= hello =').should == "<h3>hello</h3>\n"
180
+ parser.parse('== hello ==').should == "<h4>hello</h4>\n"
181
+ parser.parse('=== hello ===').should == "<h5>hello</h5>\n"
182
+ parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
183
+ parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
184
+ parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
185
+ end
186
+
187
+ it 'should treat the three different override methods as equivalent (level: 3)' do
188
+ @parser.base_heading_level = 3
189
+ @parser.parse('= hello =').should == "<h4>hello</h4>\n"
190
+ @parser.parse('== hello ==').should == "<h5>hello</h5>\n"
191
+ @parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
192
+ @parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
193
+ @parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
194
+ @parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
195
+
196
+ @parser.parse('= hello =', :base_heading_level => 3).should == "<h4>hello</h4>\n"
197
+ @parser.parse('== hello ==', :base_heading_level => 3).should == "<h5>hello</h5>\n"
198
+ @parser.parse('=== hello ===', :base_heading_level => 3).should == "<h6>hello</h6>\n"
199
+ @parser.parse('==== hello ====', :base_heading_level => 3).should == "<h6>hello</h6>\n"
200
+ @parser.parse('===== hello =====', :base_heading_level => 3).should == "<h6>hello</h6>\n"
201
+ @parser.parse('====== hello ======', :base_heading_level => 3).should == "<h6>hello</h6>\n"
202
+
203
+ parser = Wikitext::Parser.new :base_heading_level => 3
204
+ parser.parse('= hello =').should == "<h4>hello</h4>\n"
205
+ parser.parse('== hello ==').should == "<h5>hello</h5>\n"
206
+ parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
207
+ parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
208
+ parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
209
+ parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
210
+ end
211
+
212
+ it 'should treat the three different override methods as equivalent (level: 4)' do
213
+ @parser.base_heading_level = 4
214
+ @parser.parse('= hello =').should == "<h5>hello</h5>\n"
215
+ @parser.parse('== hello ==').should == "<h6>hello</h6>\n"
216
+ @parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
217
+ @parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
218
+ @parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
219
+ @parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
220
+
221
+ @parser.parse('= hello =', :base_heading_level => 4).should == "<h5>hello</h5>\n"
222
+ @parser.parse('== hello ==', :base_heading_level => 4).should == "<h6>hello</h6>\n"
223
+ @parser.parse('=== hello ===', :base_heading_level => 4).should == "<h6>hello</h6>\n"
224
+ @parser.parse('==== hello ====', :base_heading_level => 4).should == "<h6>hello</h6>\n"
225
+ @parser.parse('===== hello =====', :base_heading_level => 4).should == "<h6>hello</h6>\n"
226
+ @parser.parse('====== hello ======', :base_heading_level => 4).should == "<h6>hello</h6>\n"
227
+
228
+ parser = Wikitext::Parser.new :base_heading_level => 4
229
+ parser.parse('= hello =').should == "<h5>hello</h5>\n"
230
+ parser.parse('== hello ==').should == "<h6>hello</h6>\n"
231
+ parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
232
+ parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
233
+ parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
234
+ parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
235
+ end
236
+
237
+ it 'should treat the three different override methods as equivalent (level: 5)' do
238
+ @parser.base_heading_level = 5
239
+ @parser.parse('= hello =').should == "<h6>hello</h6>\n"
240
+ @parser.parse('== hello ==').should == "<h6>hello</h6>\n"
241
+ @parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
242
+ @parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
243
+ @parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
244
+ @parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
245
+
246
+ @parser.parse('= hello =', :base_heading_level => 5).should == "<h6>hello</h6>\n"
247
+ @parser.parse('== hello ==', :base_heading_level => 5).should == "<h6>hello</h6>\n"
248
+ @parser.parse('=== hello ===', :base_heading_level => 5).should == "<h6>hello</h6>\n"
249
+ @parser.parse('==== hello ====', :base_heading_level => 5).should == "<h6>hello</h6>\n"
250
+ @parser.parse('===== hello =====', :base_heading_level => 5).should == "<h6>hello</h6>\n"
251
+ @parser.parse('====== hello ======', :base_heading_level => 5).should == "<h6>hello</h6>\n"
252
+
253
+ parser = Wikitext::Parser.new :base_heading_level => 5
254
+ parser.parse('= hello =').should == "<h6>hello</h6>\n"
255
+ parser.parse('== hello ==').should == "<h6>hello</h6>\n"
256
+ parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
257
+ parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
258
+ parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
259
+ parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
260
+ end
261
+
262
+ it 'should treat the three different override methods as equivalent (level: 6)' do
263
+ @parser.base_heading_level = 6
264
+ @parser.parse('= hello =').should == "<h6>hello</h6>\n"
265
+ @parser.parse('== hello ==').should == "<h6>hello</h6>\n"
266
+ @parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
267
+ @parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
268
+ @parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
269
+ @parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
270
+
271
+ @parser.parse('= hello =', :base_heading_level => 6).should == "<h6>hello</h6>\n"
272
+ @parser.parse('== hello ==', :base_heading_level => 6).should == "<h6>hello</h6>\n"
273
+ @parser.parse('=== hello ===', :base_heading_level => 6).should == "<h6>hello</h6>\n"
274
+ @parser.parse('==== hello ====', :base_heading_level => 6).should == "<h6>hello</h6>\n"
275
+ @parser.parse('===== hello =====', :base_heading_level => 6).should == "<h6>hello</h6>\n"
276
+ @parser.parse('====== hello ======', :base_heading_level => 6).should == "<h6>hello</h6>\n"
277
+
278
+ parser = Wikitext::Parser.new :base_heading_level => 6
279
+ parser.parse('= hello =').should == "<h6>hello</h6>\n"
280
+ parser.parse('== hello ==').should == "<h6>hello</h6>\n"
281
+ parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
282
+ parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
283
+ parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
284
+ parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
285
+ end
286
+
287
+ # here we exceed the limit
288
+ it 'should treat the three different override methods as equivalent (level: 7)' do
289
+ @parser.base_heading_level = 7
290
+ @parser.parse('= hello =').should == "<h6>hello</h6>\n"
291
+ @parser.parse('== hello ==').should == "<h6>hello</h6>\n"
292
+ @parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
293
+ @parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
294
+ @parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
295
+ @parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
296
+
297
+ @parser.parse('= hello =', :base_heading_level => 7).should == "<h6>hello</h6>\n"
298
+ @parser.parse('== hello ==', :base_heading_level => 7).should == "<h6>hello</h6>\n"
299
+ @parser.parse('=== hello ===', :base_heading_level => 7).should == "<h6>hello</h6>\n"
300
+ @parser.parse('==== hello ====', :base_heading_level => 7).should == "<h6>hello</h6>\n"
301
+ @parser.parse('===== hello =====', :base_heading_level => 7).should == "<h6>hello</h6>\n"
302
+ @parser.parse('====== hello ======', :base_heading_level => 7).should == "<h6>hello</h6>\n"
303
+
304
+ parser = Wikitext::Parser.new :base_heading_level => 7
305
+ parser.parse('= hello =').should == "<h6>hello</h6>\n"
306
+ parser.parse('== hello ==').should == "<h6>hello</h6>\n"
307
+ parser.parse('=== hello ===').should == "<h6>hello</h6>\n"
308
+ parser.parse('==== hello ====').should == "<h6>hello</h6>\n"
309
+ parser.parse('===== hello =====').should == "<h6>hello</h6>\n"
310
+ parser.parse('====== hello ======').should == "<h6>hello</h6>\n"
311
+ end
312
+
313
+ # for bad markup, we adjust any headings that we output (h2 -> h4),
314
+ # but we show the bad markup (===) as it was entered (not-adjusted)
315
+ it 'should show unbalanced markup exactly as it was entered' do
316
+ @parser.base_heading_level = 2
317
+
318
+ # missing trailing =
319
+ @parser.parse('== hello =').should == "<h4>hello =</h4>\n"
320
+
321
+ # excess trailing =
322
+ @parser.parse('== hello ===').should == "<h4>hello ===</h4>\n"
323
+ end
324
+
325
+ it 'should show markup in <nowiki> spans exactly as it was entered' do
326
+ @parser.base_heading_level = 3
327
+ @parser.parse("<nowiki>\n== foo ==\n</nowiki>").should == "<p>\n== foo ==\n</p>\n"
328
+ end
329
+
330
+ it 'should show markup in <pre> blocks exactly as it was entered' do
331
+ @parser.base_heading_level = 1
332
+ @parser.parse("<pre>\n== bar ==\n</pre>").should == "<pre>\n== bar ==\n</pre>\n"
333
+ end
334
+ end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2007-2009 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2008 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
data/spec/img_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2008 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2007-2008 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2007-2009 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2007-2009 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2007-2008 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
data/spec/nowiki_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2007-2008 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
data/spec/pre_spec.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2007-2008 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2008 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
data/spec/spec_helper.rb CHANGED
@@ -34,7 +34,7 @@ def dedent spaces, string = nil
34
34
  else
35
35
  raise 'Invalid argument'
36
36
  end
37
- string.each do |line|
37
+ string.each_line do |line|
38
38
  if not line =~ /\A {#{spaces.to_i}}/
39
39
  raise "Underlength indent for line: #{line.inspect}"
40
40
  end
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # encoding: utf-8
2
3
  # Copyright 2007-2008 Wincent Colaiuta
3
4
  # This program is free software: you can redistribute it and/or modify
4
5
  # it under the terms of the GNU General Public License as published by
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikitext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wincent Colaiuta
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-04 00:00:00 +01:00
12
+ date: 2009-02-23 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,6 +23,7 @@ extra_rdoc_files: []
23
23
 
24
24
  files:
25
25
  - spec/autolinking_spec.rb
26
+ - spec/base_heading_level_spec.rb
26
27
  - spec/blockquote_spec.rb
27
28
  - spec/em_spec.rb
28
29
  - spec/encoding_spec.rb