wikitext 3.0 → 3.0.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/parser.c CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2007-2011 Wincent Colaiuta. All rights reserved.
1
+ // Copyright 2007-2012 Wincent Colaiuta. All rights reserved.
2
2
  //
3
3
  // Redistribution and use in source and binary forms, with or without
4
4
  // modification, are permitted provided that the following conditions are met:
@@ -1964,6 +1964,9 @@ VALUE Wikitext_parser_parse(int argc, VALUE *argv, VALUE self)
1964
1964
  wiki_emit_pending_crlf_if_necessary(parser);
1965
1965
  str_append(parser->output, token->start, TOKEN_LEN(token));
1966
1966
  }
1967
+ else if (IN(EXT_LINK_START))
1968
+ // must be capturing and this must be part of the link text
1969
+ str_append(parser->capture, token->start, TOKEN_LEN(token));
1967
1970
  else
1968
1971
  {
1969
1972
  wiki_pop_excess_elements(parser);
@@ -1,4 +1,4 @@
1
- # Copyright 2007-2011 Wincent Colaiuta. All rights reserved.
1
+ # Copyright 2007-2012 Wincent Colaiuta. All rights reserved.
2
2
  #
3
3
  # Redistribution and use in source and binary forms, with or without
4
4
  # modification, are permitted provided that the following conditions are met:
@@ -22,5 +22,5 @@
22
22
  # POSSIBILITY OF SUCH DAMAGE.
23
23
 
24
24
  module Wikitext
25
- VERSION = '3.0'
25
+ VERSION = '3.0.1'
26
26
  end # module Wikitext
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
- # Copyright 2007-2010 Wincent Colaiuta. All rights reserved.
2
+ # Copyright 2007-2012 Wincent Colaiuta. All rights reserved.
3
3
  #
4
4
  # Redistribution and use in source and binary forms, with or without
5
5
  # modification, are permitted provided that the following conditions are met:
@@ -49,16 +49,35 @@ describe Wikitext::Parser, 'external links' do
49
49
  @parser.parse('[svn://google.com/ Google]').should == expected
50
50
  end
51
51
 
52
- it 'should format valid external mailto links' do
53
- expected = %Q{<p><a href="mailto:user@example.com" class="mailto">john</a></p>\n}
52
+ it 'formats valid external mailto links' do
53
+ expected = %{<p><a href="mailto:user@example.com" class="mailto">john</a></p>\n}
54
54
  @parser.parse('[mailto:user@example.com john]').should == expected
55
55
  end
56
56
 
57
- it 'should not treat raw email addresses as valid link targets' do
58
- expected = %Q{<p>[<a href="mailto:user@example.com" class="mailto">user@example.com</a> john]</p>\n}
57
+ it 'does not treat raw email addresses as valid link targets' do
58
+ expected = %{<p>[<a href="mailto:user@example.com" class="mailto">user@example.com</a> john]</p>\n}
59
59
  @parser.parse('[user@example.com john]').should == expected
60
60
  end
61
61
 
62
+ it 'formats external mailto links where the linktext is itself an email' do
63
+ # reported here: https://wincent.com/issues/1955
64
+ expected = %{<p><a href="mailto:user@example.com" class="mailto">user@example.com</a></p>\n}
65
+ @parser.parse('[mailto:user@example.com user@example.com]').should == expected
66
+
67
+ # just in case that example seems a little contrived and trivial (you could
68
+ # work around it by instead just writing "user@example.com" in your markup),
69
+ # here's a more obviously useful one
70
+ expected = %{<p><a href="mailto:user@example.com" class="mailto">email me at user@example.com for more info</a></p>\n}
71
+ @parser.parse('[mailto:user@example.com email me at user@example.com for more info]').should == expected
72
+ end
73
+
74
+ it 'allows email addreses in link text' do
75
+ # more general case of bug reported here: https://wincent.com/issues/1955
76
+ expected = %{<p><a href="http://google.com/?q=user@example.com" class="external">Google for user@example.com</a></p>\n}
77
+ @parser.parse('[http://google.com/?q=user@example.com Google for user@example.com]').should == expected
78
+
79
+ end
80
+
62
81
  it 'should format absolute path links' do
63
82
  expected = %Q{<p><a href="/foo/bar">fb</a></p>\n} # note no "external" class
64
83
  @parser.parse('[/foo/bar fb]').should == expected
metadata CHANGED
@@ -5,7 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 3
7
7
  - 0
8
- version: "3.0"
8
+ - 1
9
+ version: 3.0.1
9
10
  platform: ruby
10
11
  authors:
11
12
  - Wincent Colaiuta
@@ -13,7 +14,7 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2011-11-10 00:00:00 -08:00
17
+ date: 2012-03-03 00:00:00 -08:00
17
18
  default_executable:
18
19
  dependencies:
19
20
  - !ruby/object:Gem::Dependency
@@ -148,7 +149,6 @@ files:
148
149
  - spec/p_spec.rb
149
150
  - spec/parser_spec.rb
150
151
  - spec/pre_spec.rb
151
- - spec/rails_spec.rb
152
152
  - spec/regressions_spec.rb
153
153
  - spec/spec_helper.rb
154
154
  - spec/string_spec.rb
data/spec/rails_spec.rb DELETED
@@ -1,239 +0,0 @@
1
- # Copyright 2009-2011 Wincent Colaiuta. All rights reserved.
2
- #
3
- # Redistribution and use in source and binary forms, with or without
4
- # modification, are permitted provided that the following conditions are met:
5
- #
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.
23
-
24
- require 'spec_helper'
25
- require 'wikitext/version'
26
- require 'fileutils'
27
- require 'pathname'
28
- require 'wopen3'
29
-
30
- module RailsSpecs
31
- TRASH_PATH = Pathname.new(__FILE__).dirname + '.trash'
32
- AREL_CLONE_PATH = TRASH_PATH + 'arel.git'
33
- AREL_REPO = 'git://github.com/rails/arel.git'
34
- RAILS_CLONE_PATH = TRASH_PATH + 'rails.git'
35
- RAILS_REPO = 'git://github.com/rails/rails.git'
36
- WIKITEXT_GEM_PATH = TRASH_PATH + '..' + '..'
37
- SUCCESSFUL_TEST_RESULT = /1 tests, 3 assertions, 0 failures, 0 errors/
38
-
39
- def run cmd, *args
40
- result = Wopen3.system(*([cmd] + args))
41
- if result.status != 0
42
- command_string = ([cmd] + args).join(' ')
43
- puts "\n*** COMMAND #{command_string} EXITED WITH NON-ZERO EXIT STATUS (#{result.status})"
44
- puts "*** STDOUT FOR COMMAND #{command_string}:", result.stdout
45
- puts "*** STDERR FOR COMMAND #{command_string}:", result.stderr
46
- raise "non-zero exit status (#{result.status}) for '#{command_string}'"
47
- end
48
- result
49
- end
50
-
51
- def clone repo, path
52
- if File.exist? path
53
- FileUtils.cd path do
54
- run 'git', 'fetch'
55
- end
56
- else
57
- run 'git', 'clone', repo, path
58
- end
59
- end
60
-
61
- def app_path version
62
- version = 'edge' if version.nil?
63
- version = "v#{version}" if version =~ /\A\d\./
64
- TRASH_PATH + "#{version}-app"
65
- end
66
-
67
- # if version is nil will create an "Edge" app
68
- def create_rails3_app rails_version, arel_version = nil
69
- app = app_path rails_version
70
- clone AREL_REPO, AREL_CLONE_PATH
71
- FileUtils.cd AREL_CLONE_PATH do
72
- if arel_version
73
- run 'git', 'reset', '--hard', "v#{arel_version}"
74
- else # "Edge"
75
- run 'git', 'reset', '--hard', 'origin/master'
76
- end
77
- run 'git', 'clean', '-f'
78
- end
79
-
80
- clone RAILS_REPO, RAILS_CLONE_PATH
81
- FileUtils.cd RAILS_CLONE_PATH do
82
- if rails_version
83
- run 'git', 'reset', '--hard', "v#{rails_version}"
84
- else # "Edge"
85
- run 'git', 'reset', '--hard', 'origin/master'
86
- end
87
- run 'git', 'clean', '-f'
88
-
89
- begin
90
- clean_bundler_environment
91
- run 'env', "AREL=#{AREL_CLONE_PATH}",
92
- 'bundle', 'install', '--path', '../bundle', '--without', 'db'
93
- FileUtils.rm_r(app) if File.exist?(app)
94
- run 'env', "AREL=#{AREL_CLONE_PATH}",
95
- 'bundle', 'exec', 'bin/rails', 'new', app, '--skip-activerecord', '--dev'
96
- ensure
97
- restore_bundler_environment
98
- end
99
- end
100
-
101
- create_gemfile app
102
- bundlerize app
103
- end
104
-
105
- def insert text, after, infile
106
- output = []
107
- found = false
108
- File.read(infile).split("\n").each do |line|
109
- output << line
110
- if found == false && line =~ /#{Regexp.escape(after)}/
111
- found = true
112
- output << text
113
- end
114
- end
115
- File.open(infile, 'wb') { |f| f.write(output.join("\n")) }
116
- raise "text '#{after}' not found" unless found
117
- end
118
-
119
- def add_text_to_routes text, infile
120
- insert text, 'Application.routes.draw', infile
121
- end
122
-
123
- def create_gemfile app
124
- File.open(app + 'Gemfile', 'w') do |f|
125
- f.write <<-GEMFILE
126
- source :rubygems
127
- gem 'arel', :path => "#{AREL_CLONE_PATH.realpath}"
128
- gem 'rake'
129
- gem 'rails', :path => "#{RAILS_CLONE_PATH.realpath}"
130
- gem 'sqlite3'
131
- gem 'wikitext', :path => "#{WIKITEXT_GEM_PATH.realpath}"
132
- GEMFILE
133
- end
134
- end
135
-
136
- def bundlerize app
137
- clean_bundler_environment
138
- Dir.chdir app do
139
- run 'bundle', 'install', '--path', '../bundle', '--binstubs'
140
- end
141
- ensure
142
- restore_bundler_environment
143
- end
144
-
145
- def create_controller app
146
- File.open(app + 'app' + 'controllers' + 'wiki_controller.rb', 'w') do |f|
147
- f.write 'class WikiController < ApplicationController; end'
148
- end
149
- end
150
-
151
- def create_template app
152
- template_dir = app + 'app' + 'views' + 'wiki'
153
- FileUtils.mkdir template_dir
154
- File.open(template_dir + 'index.html.wikitext', 'w') do |f|
155
- f.write '* hello, world!'
156
- end
157
- end
158
-
159
- def create_test app
160
- # integration tests won't run without a schema.rb
161
- FileUtils.touch app + 'db' + 'schema.rb'
162
-
163
- File.open(app + 'test' + 'integration' + 'wiki_test.rb', 'w') do |f|
164
- f.write <<'TEST'
165
- require File.join(File.dirname(__FILE__), '..', 'test_helper')
166
-
167
- class WikiTest < ActionController::IntegrationTest
168
- def test_wiki_index
169
- get "/wiki"
170
- assert_response :success
171
- assert_template "wiki/index"
172
- assert_select 'ul>li', 'hello, world!'
173
- end
174
- end
175
- TEST
176
- end
177
- end
178
-
179
- def update_routes app
180
- routes = app + 'config' + 'routes.rb'
181
- add_text_to_routes 'match "/wiki" => "wiki#index"', routes
182
- end
183
-
184
- def setup_rails_app rails_version = nil, arel_version = nil
185
- create_rails3_app rails_version, arel_version
186
- path = app_path rails_version
187
- update_routes path
188
- create_controller path
189
- create_template path
190
- create_test path
191
- end
192
-
193
- def clean_bundler_environment
194
- @bundler_env = ENV.select { |key, value| key =~ /\A(BUNDLE|GEM)_/ }
195
- @bundler_env.each { |pair| ENV.delete(pair.first) }
196
- end
197
-
198
- def restore_bundler_environment
199
- @bundler_env.each { |pair| ENV[pair[0]] = pair[1] }
200
- end
201
-
202
- def run_integration_test app
203
- clean_bundler_environment
204
- FileUtils.cd app do
205
- return run('bin/rake', 'test:integration').stdout
206
- end
207
- ensure
208
- restore_bundler_environment
209
- end
210
- end # module RailsSpecs
211
-
212
- # different versions of Rails require different versions of Arel
213
- { '3.1.0' => '2.1.1' }.each do |rails_version, arel_version|
214
- describe "Template handler in Rails #{rails_version}" do
215
- include RailsSpecs
216
-
217
- before :all do
218
- setup_rails_app rails_version, arel_version
219
- @path = app_path rails_version
220
- end
221
-
222
- it 'should process the template using the wikitext module' do
223
- run_integration_test(@path).should =~ RailsSpecs::SUCCESSFUL_TEST_RESULT
224
- end
225
- end
226
- end
227
-
228
- describe 'Template handler in Edge Rails' do
229
- include RailsSpecs
230
-
231
- before :all do
232
- setup_rails_app
233
- @path = app_path nil
234
- end
235
-
236
- it 'should process the template using the wikitext module' do
237
- run_integration_test(@path).should =~ RailsSpecs::SUCCESSFUL_TEST_RESULT
238
- end
239
- end