wikitext 2.0 → 2.1

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.
data/ext/depend CHANGED
@@ -1,18 +1,25 @@
1
- # depend
2
- # Additional material for Makefile
3
- # Copyright 2008 Wincent Colaiuta
4
- # This program is free software: you can redistribute it and/or modify
5
- # it under the terms of the GNU General Public License as published by
6
- # the Free Software Foundation, either version 3 of the License, or
7
- # (at your option) any later version.
1
+ # Copyright 2008-2010 Wincent Colaiuta. All rights reserved.
8
2
  #
9
- # This program is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- # GNU General Public License for more details.
3
+ # Redistribution and use in source and binary forms, with or without
4
+ # modification, are permitted provided that the following conditions are met:
13
5
  #
14
- # You should have received a copy of the GNU General Public License
15
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
6
+ # 1. Redistributions of source code must retain the above copyright notice,
7
+ # this list of conditions and the following disclaimer.
8
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
9
+ # this list of conditions and the following disclaimer in the documentation
10
+ # and/or other materials provided with the distribution.
11
+ #
12
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
13
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
16
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
+ # POSSIBILITY OF SUCH DAMAGE.
16
23
 
17
24
  # don't warn about unused params because many Ruby methods accept "self" but don't use it
18
25
  CFLAGS += -std=gnu99 -Wall -Wextra -Wno-unused-parameter
@@ -51,6 +51,7 @@ typedef struct
51
51
  ary_t *line; // stack for tracking scope as implied by current line
52
52
  ary_t *line_buffer; // stack for tracking raw tokens (not scope) on current line
53
53
  VALUE external_link_class; // CSS class applied to external links
54
+ VALUE external_link_rel; // rel attribute applied to external links
54
55
  VALUE mailto_class; // CSS class applied to email (mailto) links
55
56
  VALUE img_prefix; // path prepended when emitting img tags
56
57
  int output_style; // HTML_OUTPUT (default) or XML_OUTPUT
@@ -112,6 +113,7 @@ const char p_end[] = "</p>";
112
113
  const char space[] = " ";
113
114
  const char a_start[] = "<a href=\"";
114
115
  const char a_class[] = "\" class=\"";
116
+ const char a_rel[] = "\" rel=\"";
115
117
  const char a_start_close[] = "\">";
116
118
  const char a_end[] = "</a>";
117
119
  const char link_start[] = "[[";
@@ -153,6 +155,7 @@ parser_t *parser_new(void)
153
155
  parser->line = ary_new();
154
156
  parser->line_buffer = ary_new();
155
157
  parser->external_link_class = Qnil; // caller should set up
158
+ parser->external_link_rel = Qnil; // caller should set up
156
159
  parser->mailto_class = Qnil; // caller should set up
157
160
  parser->img_prefix = Qnil; // caller should set up
158
161
  parser->output_style = HTML_OUTPUT;
@@ -280,7 +283,7 @@ void wiki_downcase_bang(char *ptr, long len)
280
283
  // if check_autolink is true, checks parser->autolink to decide whether to emit a real hyperlink
281
284
  // or merely the literal link target
282
285
  // if link_text is Qnil, the link_target is re-used for the link text
283
- void wiki_append_hyperlink(parser_t *parser, VALUE link_prefix, str_t *link_target, str_t *link_text, VALUE link_class, bool check_autolink)
286
+ void wiki_append_hyperlink(parser_t *parser, VALUE link_prefix, str_t *link_target, str_t *link_text, VALUE link_class, VALUE link_rel, bool check_autolink)
284
287
  {
285
288
  if (check_autolink && !parser->autolink)
286
289
  str_append_str(parser->output, link_target);
@@ -305,6 +308,11 @@ void wiki_append_hyperlink(parser_t *parser, VALUE link_prefix, str_t *link_targ
305
308
  str_append(parser->output, a_class, sizeof(a_class) - 1); // " class="
306
309
  str_append_string(parser->output, link_class);
307
310
  }
311
+ if (link_rel != Qnil)
312
+ {
313
+ str_append(parser->output, a_rel, sizeof(a_rel) - 1); // " rel="
314
+ str_append_string(parser->output, link_rel);
315
+ }
308
316
  str_append(parser->output, a_start_close, sizeof(a_start_close) - 1); // ">
309
317
  if (!link_text || link_text->len == 0) // re-use link_target
310
318
  str_append_str(parser->output, link_target);
@@ -963,12 +971,13 @@ void wiki_rollback_failed_external_link(parser_t *parser)
963
971
  // store a couple of values before popping
964
972
  int scope_includes_space = IN(SPACE);
965
973
  VALUE link_class = IN(PATH) ? Qnil : parser->external_link_class;
974
+ VALUE link_rel = IN(PATH) ? Qnil : parser->external_link_rel;
966
975
  wiki_pop_from_stack_up_to(parser, NULL, EXT_LINK_START, true);
967
976
 
968
977
  str_append(parser->output, ext_link_start, sizeof(ext_link_start) - 1);
969
978
  if (parser->link_target->len > 0)
970
979
  {
971
- wiki_append_hyperlink(parser, Qnil, parser->link_target, NULL, link_class, true);
980
+ wiki_append_hyperlink(parser, Qnil, parser->link_target, NULL, link_class, link_rel, true);
972
981
  if (scope_includes_space)
973
982
  {
974
983
  str_append(parser->output, space, sizeof(space) - 1);
@@ -998,6 +1007,7 @@ VALUE Wikitext_parser_initialize(int argc, VALUE *argv, VALUE self)
998
1007
  VALUE autolink = Qtrue;
999
1008
  VALUE line_ending = rb_str_new2("\n");
1000
1009
  VALUE external_link_class = rb_str_new2("external");
1010
+ VALUE external_link_rel = Qnil;
1001
1011
  VALUE mailto_class = rb_str_new2("mailto");
1002
1012
  VALUE internal_link_prefix = rb_str_new2("/wiki/");
1003
1013
  VALUE img_prefix = rb_str_new2("/images/");
@@ -1014,6 +1024,7 @@ VALUE Wikitext_parser_initialize(int argc, VALUE *argv, VALUE self)
1014
1024
  autolink = OVERRIDE_IF_SET(autolink);
1015
1025
  line_ending = OVERRIDE_IF_SET(line_ending);
1016
1026
  external_link_class = OVERRIDE_IF_SET(external_link_class);
1027
+ external_link_rel = OVERRIDE_IF_SET(external_link_rel);
1017
1028
  mailto_class = OVERRIDE_IF_SET(mailto_class);
1018
1029
  internal_link_prefix = OVERRIDE_IF_SET(internal_link_prefix);
1019
1030
  img_prefix = OVERRIDE_IF_SET(img_prefix);
@@ -1027,6 +1038,7 @@ VALUE Wikitext_parser_initialize(int argc, VALUE *argv, VALUE self)
1027
1038
  rb_iv_set(self, "@autolink", autolink);
1028
1039
  rb_iv_set(self, "@line_ending", line_ending);
1029
1040
  rb_iv_set(self, "@external_link_class", external_link_class);
1041
+ rb_iv_set(self, "@external_link_rel", external_link_rel);
1030
1042
  rb_iv_set(self, "@mailto_class", mailto_class);
1031
1043
  rb_iv_set(self, "@internal_link_prefix", internal_link_prefix);
1032
1044
  rb_iv_set(self, "@img_prefix", img_prefix);
@@ -1070,6 +1082,8 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
1070
1082
  line_ending = StringValue(line_ending);
1071
1083
  VALUE link_class = rb_iv_get(self, "@external_link_class");
1072
1084
  link_class = NIL_P(link_class) ? Qnil : StringValue(link_class);
1085
+ VALUE link_rel = rb_iv_get(self, "@external_link_rel");
1086
+ link_rel = NIL_P(link_rel) ? Qnil : StringValue(link_rel);
1073
1087
  VALUE mailto_class = rb_iv_get(self, "@mailto_class");
1074
1088
  mailto_class = NIL_P(mailto_class) ? Qnil : StringValue(mailto_class);
1075
1089
  VALUE prefix = rb_iv_get(self, "@internal_link_prefix");
@@ -1102,6 +1116,14 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
1102
1116
  if (rb_funcall(options, has_key, 1, id) == Qtrue)
1103
1117
  base_heading_level = NUM2INT(rb_hash_aref(options, id));
1104
1118
 
1119
+ // :external_link_rel => 'nofollow'
1120
+ id = ID2SYM(rb_intern("external_link_rel"));
1121
+ if (rb_funcall(options, has_key, 1, id) == Qtrue)
1122
+ {
1123
+ link_rel = rb_hash_aref(options, id);
1124
+ link_rel = NIL_P(link_rel) ? Qnil : StringValue(link_rel);
1125
+ }
1126
+
1105
1127
  // :output_style => :html/:xml
1106
1128
  id = ID2SYM(rb_intern("output_style"));
1107
1129
  if (rb_funcall(options, has_key, 1, id) == Qtrue)
@@ -1128,6 +1150,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
1128
1150
  parser_t *parser = parser_new();
1129
1151
  GC_WRAP_PARSER(parser, parser_gc);
1130
1152
  parser->external_link_class = link_class;
1153
+ parser->external_link_rel = link_rel;
1131
1154
  parser->mailto_class = mailto_class;
1132
1155
  parser->img_prefix = rb_iv_get(self, "@img_prefix");
1133
1156
  parser->autolink = rb_iv_get(self, "@autolink") == Qtrue ? true : false;
@@ -1947,7 +1970,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
1947
1970
  wiki_start_para_if_necessary(parser);
1948
1971
  token_str->ptr = token->start;
1949
1972
  token_str->len = TOKEN_LEN(token);
1950
- wiki_append_hyperlink(parser, rb_str_new2("mailto:"), token_str, NULL, mailto_class, true);
1973
+ wiki_append_hyperlink(parser, rb_str_new2("mailto:"), token_str, NULL, mailto_class, Qnil, true);
1951
1974
  }
1952
1975
  break;
1953
1976
 
@@ -1962,7 +1985,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
1962
1985
  wiki_rollback_failed_internal_link(parser);
1963
1986
  token_str->ptr = token->start;
1964
1987
  token_str->len = TOKEN_LEN(token);
1965
- wiki_append_hyperlink(parser, Qnil, token_str, NULL, parser->external_link_class, true);
1988
+ wiki_append_hyperlink(parser, Qnil, token_str, NULL, parser->external_link_class, parser->external_link_rel, true);
1966
1989
  }
1967
1990
  else if (IN(EXT_LINK_START))
1968
1991
  {
@@ -1987,7 +2010,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
1987
2010
  wiki_pop_excess_elements(parser);
1988
2011
  wiki_start_para_if_necessary(parser);
1989
2012
  str_append(parser->output, ext_link_start, sizeof(ext_link_start) - 1);
1990
- wiki_append_hyperlink(parser, Qnil, token_str, NULL, parser->external_link_class, true);
2013
+ wiki_append_hyperlink(parser, Qnil, token_str, NULL, parser->external_link_class, parser->external_link_rel, true);
1991
2014
  }
1992
2015
  }
1993
2016
  else
@@ -1999,7 +2022,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
1999
2022
  wiki_start_para_if_necessary(parser);
2000
2023
  token_str->ptr = token->start;
2001
2024
  token_str->len = TOKEN_LEN(token);
2002
- wiki_append_hyperlink(parser, Qnil, token_str, NULL, parser->external_link_class, true);
2025
+ wiki_append_hyperlink(parser, Qnil, token_str, NULL, parser->external_link_class, parser->external_link_rel, true);
2003
2026
  }
2004
2027
  break;
2005
2028
 
@@ -2202,7 +2225,7 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
2202
2225
  wiki_encode_link_target(parser);
2203
2226
  wiki_pop_from_stack_up_to(parser, output, LINK_START, true);
2204
2227
  parser->capture = NULL;
2205
- wiki_append_hyperlink(parser, prefix, parser->link_target, parser->link_text, j, false);
2228
+ wiki_append_hyperlink(parser, prefix, parser->link_target, parser->link_text, j, Qnil, false);
2206
2229
  str_clear(parser->link_target);
2207
2230
  str_clear(parser->link_text);
2208
2231
  }
@@ -2270,9 +2293,10 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
2270
2293
  {
2271
2294
  // success!
2272
2295
  j = IN(PATH) ? Qnil : parser->external_link_class;
2296
+ k = IN(PATH) ? Qnil : parser->external_link_rel;
2273
2297
  wiki_pop_from_stack_up_to(parser, output, EXT_LINK_START, true);
2274
2298
  parser->capture = NULL;
2275
- wiki_append_hyperlink(parser, Qnil, parser->link_target, parser->link_text, j, false);
2299
+ wiki_append_hyperlink(parser, Qnil, parser->link_target, parser->link_text, j, k, false);
2276
2300
  }
2277
2301
  str_clear(parser->link_target);
2278
2302
  str_clear(parser->link_text);
@@ -78,6 +78,7 @@ void Init_wikitext()
78
78
  rb_define_attr(cWikitextParser, "internal_link_prefix", Qtrue, Qtrue);
79
79
  rb_define_attr(cWikitextParser, "img_prefix", Qtrue, Qtrue);
80
80
  rb_define_attr(cWikitextParser, "external_link_class", Qtrue, Qtrue);
81
+ rb_define_attr(cWikitextParser, "external_link_rel", Qtrue, Qtrue);
81
82
  rb_define_attr(cWikitextParser, "mailto_class", Qtrue, Qtrue);
82
83
  rb_define_attr(cWikitextParser, "autolink", Qtrue, Qtrue);
83
84
  rb_define_attr(cWikitextParser, "space_to_underscore", Qtrue, Qtrue);
@@ -22,5 +22,5 @@
22
22
  # POSSIBILITY OF SUCH DAMAGE.
23
23
 
24
24
  module Wikitext
25
- VERSION = '2.0'
25
+ VERSION = '2.1'
26
26
  end # module Wikitext
@@ -204,6 +204,47 @@ describe Wikitext::Parser, 'external links' do
204
204
  @parser.parse('> ]').should == "<blockquote>\n <p>]</p>\n</blockquote>\n" # in BLOCKQUOTE scope
205
205
  end
206
206
 
207
+ describe '#external_link_rel attribute' do
208
+ it 'defaults to nil (external links do not have a rel attribute)' do
209
+ @parser.parse('http://google.com/').should == \
210
+ %Q{<p><a href="http://google.com/" class="external">http://google.com/</a></p>\n}
211
+ end
212
+
213
+ context 'set at parse time' do
214
+ it 'uses the rel attribute in external links' do
215
+ @parser.parse('http://google.com/', :external_link_rel => 'nofollow').should == \
216
+ %Q{<p><a href="http://google.com/" class="external" rel="nofollow">http://google.com/</a></p>\n}
217
+ end
218
+ end
219
+
220
+ context 'set at initialization time' do
221
+ let (:parser) { Wikitext::Parser.new :external_link_rel => 'nofollow' }
222
+
223
+ it 'uses the rel attribute in external links' do
224
+ parser.parse('http://google.com/').should == \
225
+ %Q{<p><a href="http://google.com/" class="external" rel="nofollow">http://google.com/</a></p>\n}
226
+ end
227
+
228
+ it 'is overrideable' do
229
+ parser.parse('http://google.com/', :external_link_rel => nil).should == \
230
+ %Q{<p><a href="http://google.com/" class="external">http://google.com/</a></p>\n}
231
+ end
232
+ end
233
+
234
+ context 'set via an accessor' do
235
+ let (:parser) do
236
+ parser = Wikitext::Parser.new
237
+ parser.external_link_rel = 'nofollow'
238
+ parser
239
+ end
240
+
241
+ it 'uses the rel attribute in external links' do
242
+ parser.parse('http://google.com/').should == \
243
+ %Q{<p><a href="http://google.com/" class="external" rel="nofollow">http://google.com/</a></p>\n}
244
+ end
245
+ end
246
+ end
247
+
207
248
  describe 'questionable links' do
208
249
  it 'should handle links which contain an embedded [ character' do
209
250
  # note that [ is allowed in the link text, although the result may be unexpected to the user
@@ -23,7 +23,7 @@
23
23
 
24
24
  require 'pathname'
25
25
  require 'rubygems'
26
- require 'spec'
26
+ require 'rspec'
27
27
 
28
28
  # allow indenting of multiline spec data for better readability
29
29
  # but must dedent it before actually doing the comparison
metadata CHANGED
@@ -1,11 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikitext
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 1
4
5
  prerelease: false
5
6
  segments:
6
7
  - 2
7
- - 0
8
- version: "2.0"
8
+ - 1
9
+ version: "2.1"
9
10
  platform: ruby
10
11
  authors:
11
12
  - Wincent Colaiuta
@@ -13,45 +14,69 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2010-06-13 00:00:00 +02:00
17
+ date: 2010-10-17 00:00:00 +02:00
17
18
  default_executable:
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
20
21
  name: rspec
21
22
  prerelease: false
22
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
23
25
  requirements:
24
- - - ">="
26
+ - - ~>
25
27
  - !ruby/object:Gem::Version
28
+ hash: 15
26
29
  segments:
30
+ - 2
27
31
  - 0
28
- version: "0"
32
+ - 0
33
+ version: 2.0.0
29
34
  type: :development
30
35
  version_requirements: *id001
31
36
  - !ruby/object:Gem::Dependency
32
37
  name: thor
33
38
  prerelease: false
34
39
  requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
35
41
  requirements:
36
42
  - - ">="
37
43
  - !ruby/object:Gem::Version
44
+ hash: 3
38
45
  segments:
39
46
  - 0
40
47
  version: "0"
41
48
  type: :development
42
49
  version_requirements: *id002
43
50
  - !ruby/object:Gem::Dependency
44
- name: wopen3
51
+ name: yard
45
52
  prerelease: false
46
53
  requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
47
55
  requirements:
48
56
  - - ">="
49
57
  - !ruby/object:Gem::Version
58
+ hash: 27
50
59
  segments:
51
60
  - 0
52
- version: "0"
61
+ - 5
62
+ - 8
63
+ version: 0.5.8
53
64
  type: :development
54
65
  version_requirements: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ name: wopen3
68
+ prerelease: false
69
+ requirement: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ type: :development
79
+ version_requirements: *id004
55
80
  description: " Wikitext is a fast wikitext-to-HTML translator written in C.\n"
56
81
  email: win@wincent.com
57
82
  executables:
@@ -122,7 +147,7 @@ files:
122
147
  - spec/version_spec.rb
123
148
  - spec/vim_formatter.rb
124
149
  - spec/wikitext_spec.rb
125
- has_rdoc: true
150
+ has_rdoc: false
126
151
  homepage: https://wincent.com/products/wikitext
127
152
  licenses: []
128
153
 
@@ -133,23 +158,27 @@ require_paths:
133
158
  - ext
134
159
  - lib
135
160
  required_ruby_version: !ruby/object:Gem::Requirement
161
+ none: false
136
162
  requirements:
137
163
  - - ">="
138
164
  - !ruby/object:Gem::Version
165
+ hash: 3
139
166
  segments:
140
167
  - 0
141
168
  version: "0"
142
169
  required_rubygems_version: !ruby/object:Gem::Requirement
170
+ none: false
143
171
  requirements:
144
172
  - - ">="
145
173
  - !ruby/object:Gem::Version
174
+ hash: 3
146
175
  segments:
147
176
  - 0
148
177
  version: "0"
149
178
  requirements: []
150
179
 
151
180
  rubyforge_project: wikitext
152
- rubygems_version: 1.3.6
181
+ rubygems_version: 1.3.7
153
182
  signing_key:
154
183
  specification_version: 3
155
184
  summary: Wikitext-to-HTML translator