creole 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.3
4
+ - ruby-head
5
+ - jruby
6
+ - rbx-18mode
7
+ - rbx-19mode
data/CHANGES ADDED
@@ -0,0 +1,6 @@
1
+ 0.5.0
2
+
3
+ * Remove methods make_*_anchor
4
+ * Add method make_headline
5
+ * Parse tags inside link text
6
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+ gemspec
3
+
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = %w(lib)
20
20
 
21
21
  s.homepage = 'http://github.com/minad/creole'
22
- s.rdoc_options = %w(--main README.creole)
22
+
23
23
  s.add_development_dependency('bacon')
24
+ s.add_development_dependency('rake')
24
25
  end
@@ -24,8 +24,8 @@ require 'uri'
24
24
  # hierachical local links, you must inherit Creole::CreoleParser and
25
25
  # override make_local_link.
26
26
  #
27
- # You can customize the created anchor/image markup by overriding
28
- # make_*_anchor/make_image.
27
+ # You can customize the created image markup by overriding
28
+ # make_image.
29
29
 
30
30
  # Main Creole parser class. Call CreoleParser#parse to parse Creole
31
31
  # formatted text.
@@ -57,6 +57,7 @@ module Creole
57
57
  def initialize(text, options = {})
58
58
  @allowed_schemes = %w(http https ftp ftps)
59
59
  @text = text
60
+ @extensions = @no_escape = nil
60
61
  options.each_pair {|k,v| send("#{k}=", v) }
61
62
  end
62
63
 
@@ -119,7 +120,7 @@ module Creole
119
120
 
120
121
  def start_paragraph
121
122
  if @p
122
- @out << ' ' if @out[-1,1] != ' '
123
+ @out << ' ' if @out[-1] != ?\s
123
124
  else
124
125
  end_paragraph
125
126
  start_tag('p')
@@ -127,20 +128,6 @@ module Creole
127
128
  end
128
129
  end
129
130
 
130
- # Create anchor markup for direct links. This
131
- # method can be overridden to generate custom
132
- # markup, for example to add html additional attributes.
133
- def make_direct_anchor(uri, text)
134
- '<a href="' << escape_html(uri) << '">' << escape_html(text) << '</a>'
135
- end
136
-
137
- # Create anchor markup for explicit links. This
138
- # method can be overridden to generate custom
139
- # markup, for example to add html additional attributes.
140
- def make_explicit_anchor(uri, text)
141
- '<a href="' << escape_html(uri) << '">' << escape_html(text) << '</a>'
142
- end
143
-
144
131
  # Translate an explicit local link to a desired URL that is
145
132
  # properly URL-escaped. The default behaviour is to convert local
146
133
  # links directly, escaping any characters that have special
@@ -206,6 +193,10 @@ module Creole
206
193
  end
207
194
  end
208
195
 
196
+ def make_headline(level, text)
197
+ "<h#{level}>" << escape_html(text) << "</h#{level}>"
198
+ end
199
+
209
200
  def make_explicit_link(link)
210
201
  begin
211
202
  uri = URI.parse(link)
@@ -219,73 +210,90 @@ module Creole
219
210
  until str.empty?
220
211
  case str
221
212
  when /\A(\~)?((https?|ftps?):\/\/\S+?)(?=([\,.?!:;"'\)]+)?(\s|$))/
213
+ str = $'
222
214
  if $1
223
215
  @out << escape_html($2)
224
216
  else
225
217
  if uri = make_direct_link($2)
226
- @out << make_direct_anchor(uri, $2)
218
+ @out << '<a href="' << escape_html(uri) << '">' << escape_html($2) << '</a>'
227
219
  else
228
220
  @out << escape_html($&)
229
221
  end
230
222
  end
231
223
  when /\A\[\[\s*([^|]*?)\s*(\|\s*(.*?))?\s*\]\]/m
232
- link = $1
224
+ str = $'
225
+ link, content = $1, $3
233
226
  if uri = make_explicit_link(link)
234
- @out << make_explicit_anchor(uri, $3 || link)
227
+ @out << '<a href="' << escape_html(uri) << '">'
228
+ if content
229
+ until content.empty?
230
+ content = parse_inline_tag(content)
231
+ end
232
+ else
233
+ @out << escape_html(link)
234
+ end
235
+ @out << '</a>'
235
236
  else
236
237
  @out << escape_html($&)
237
238
  end
238
- when /\A\{\{\{(.*?\}*)\}\}\}/
239
- @out << '<tt>' << escape_html($1) << '</tt>'
240
- when /\A\{\{\s*(.*?)\s*(\|\s*(.*?)\s*)?\}\}/
241
- if uri = make_image_link($1)
242
- @out << make_image(uri, $3)
243
- else
239
+ else
240
+ str = parse_inline_tag(str)
241
+ end
242
+ end
243
+ end
244
+
245
+ def parse_inline_tag(str)
246
+ case str
247
+ when /\A\{\{\{(.*?\}*)\}\}\}/
248
+ @out << '<tt>' << escape_html($1) << '</tt>'
249
+ when /\A\{\{\s*(.*?)\s*(\|\s*(.*?)\s*)?\}\}/
250
+ if uri = make_image_link($1)
251
+ @out << make_image(uri, $3)
252
+ else
253
+ @out << escape_html($&)
254
+ end
255
+ when /\A([:alpha:]|[:digit:])+/
256
+ @out << $&
257
+ when /\A\s+/
258
+ @out << ' ' if @out[-1] != ?\s
259
+ when /\A\*\*/
260
+ toggle_tag 'strong', $&
261
+ when /\A\/\//
262
+ toggle_tag 'em', $&
263
+ when /\A\\\\/
264
+ @out << '<br/>'
265
+ else
266
+ if @extensions
267
+ case str
268
+ when /\A__/
269
+ toggle_tag 'u', $&
270
+ when /\A\-\-/
271
+ toggle_tag 'del', $&
272
+ when /\A\+\+/
273
+ toggle_tag 'ins', $&
274
+ when /\A\^\^/
275
+ toggle_tag 'sup', $&
276
+ when /\A\~\~/
277
+ toggle_tag 'sub', $&
278
+ when /\A\(R\)/i
279
+ @out << '&#174;'
280
+ when /\A\(C\)/i
281
+ @out << '&#169;'
282
+ when /\A~([^\s])/
283
+ @out << escape_html($1)
284
+ when /./
244
285
  @out << escape_html($&)
245
286
  end
246
- when /\A([:alpha:]|[:digit:])+/
247
- @out << $&
248
- when /\A\s+/
249
- @out << ' ' if @out[-1,1] != ' '
250
- when /\A\*\*/
251
- toggle_tag 'strong', $&
252
- when /\A\/\//
253
- toggle_tag 'em', $&
254
- when /\A\\\\/
255
- @out << '<br/>'
256
287
  else
257
- if @extensions
258
- case str
259
- when /\A__/
260
- toggle_tag 'u', $&
261
- when /\A\-\-/
262
- toggle_tag 'del', $&
263
- when /\A\+\+/
264
- toggle_tag 'ins', $&
265
- when /\A\^\^/
266
- toggle_tag 'sup', $&
267
- when /\A\~\~/
268
- toggle_tag 'sub', $&
269
- when /\A\(R\)/i
270
- @out << '&#174;'
271
- when /\A\(C\)/i
272
- @out << '&#169;'
273
- when /\A~([^\s])/
274
- @out << escape_html($1)
275
- when /./
276
- @out << escape_html($&)
277
- end
278
- else
279
- case str
280
- when /\A~([^\s])/
281
- @out << escape_html($1)
282
- when /./
283
- @out << escape_html($&)
284
- end
288
+ case str
289
+ when /\A~([^\s])/
290
+ @out << escape_html($1)
291
+ when /./
292
+ @out << escape_html($&)
285
293
  end
286
294
  end
287
- str = $'
288
295
  end
296
+ return $'
289
297
  end
290
298
 
291
299
  def parse_table_row(str)
@@ -320,7 +328,7 @@ module Creole
320
328
  when /\A\s*(={1,6})\s*(.*?)\s*=*\s*$(\r?\n)?/
321
329
  end_paragraph
322
330
  level = $1.size
323
- @out << "<h#{level}>" << escape_html($2) << "</h#{level}>"
331
+ @out << make_headline(level, $2)
324
332
  when /\A[ \t]*\|.*$(\r?\n)?/
325
333
  if !@stack.include?('table')
326
334
  end_paragraph
@@ -1,3 +1,3 @@
1
1
  module Creole
2
- VERSION = '0.4.2'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -154,8 +154,9 @@ describe Creole::Parser do
154
154
  tc("<p><a href=\"http://www.wikicreole.org/\">Visit the WikiCreole website</a></p>",
155
155
  "[[http://www.wikicreole.org/|Visit the WikiCreole website]]")
156
156
 
157
- # WARNING: Parsing markup within a link is optional
158
- tc "<p><a href=\"Weird+Stuff\">**Weird** //Stuff//</a></p>", "[[Weird Stuff|**Weird** //Stuff//]]"
157
+ # WRNING: Parsing markup within a link is optional
158
+ tc "<p><a href=\"Weird+Stuff\"><strong>Weird</strong> <em>Stuff</em></a></p>", "[[Weird Stuff|**Weird** //Stuff//]]"
159
+ tc("<p><a href=\"http://example.org/\"><img src=\"image.jpg\"/></a></p>", "[[http://example.org/|{{image.jpg}}]]")
159
160
 
160
161
  # Inside bold
161
162
  tc "<p><strong><a href=\"link\">link</a></strong></p>", "**[[link]]**"
metadata CHANGED
@@ -1,42 +1,52 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: creole
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
4
5
  prerelease:
5
- version: 0.4.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Lars Christensen
9
9
  - Daniel Mendler
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-05-03 00:00:00 +02:00
15
- default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
13
+ date: 2012-10-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
18
16
  name: bacon
17
+ requirement: &7674580 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :development
19
24
  prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
25
+ version_requirements: *7674580
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &7674100 !ruby/object:Gem::Requirement
21
29
  none: false
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: "0"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
26
34
  type: :development
27
- version_requirements: *id001
35
+ prerelease: false
36
+ version_requirements: *7674100
28
37
  description: Creole is a lightweight markup language (http://wikicreole.org/).
29
- email:
38
+ email:
30
39
  - larsch@belunktum.dk
31
40
  - mail@daniel-mendler.de
32
41
  executables: []
33
-
34
42
  extensions: []
35
-
36
- extra_rdoc_files:
43
+ extra_rdoc_files:
37
44
  - README.creole
38
- files:
45
+ files:
39
46
  - .gitignore
47
+ - .travis.yml
48
+ - CHANGES
49
+ - Gemfile
40
50
  - README.creole
41
51
  - Rakefile
42
52
  - creole.gemspec
@@ -44,34 +54,28 @@ files:
44
54
  - lib/creole/parser.rb
45
55
  - lib/creole/version.rb
46
56
  - test/parser_test.rb
47
- has_rdoc: true
48
57
  homepage: http://github.com/minad/creole
49
58
  licenses: []
50
-
51
59
  post_install_message:
52
- rdoc_options:
53
- - --main
54
- - README.creole
55
- require_paths:
60
+ rdoc_options: []
61
+ require_paths:
56
62
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
63
+ required_ruby_version: !ruby/object:Gem::Requirement
58
64
  none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: "0"
63
- required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
70
  none: false
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: "0"
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
69
75
  requirements: []
70
-
71
76
  rubyforge_project: creole
72
- rubygems_version: 1.6.2
77
+ rubygems_version: 1.8.15
73
78
  signing_key:
74
79
  specification_version: 3
75
80
  summary: Lightweight markup language
76
81
  test_files: []
77
-