wikicloth 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -25,8 +25,7 @@ Install
25
25
 
26
26
  git clone git://github.com/nricciar/wikicloth.git
27
27
  cd wikicloth/
28
- rake gem
29
- sudo gem install pkg/wikicloth-0.5.0.gem
28
+ rake install
30
29
 
31
30
  Usage
32
31
  ---------------------------------------------------
@@ -52,24 +51,22 @@ Most features of WikiCloth can be overriden as needed...
52
51
  { :href => url_for(page) }
53
52
  end
54
53
 
55
- include_resource do |resource,options|
56
- case resource
57
- when "date"
58
- Time.now.to_s
59
- else
60
- params[resource] unless params[resource].nil?
61
- end
54
+ template do |template|
55
+ "Hello {{{1}}}" if template == "hello"
56
+ end
57
+
58
+ external_link do |url,text|
59
+ "<a href=\"#{url}\" target=\"_blank\" class=\"exlink\">#{text.blank? ? url : text}</a>"
62
60
  end
63
61
 
64
62
  end
65
63
 
66
64
  @wiki = WikiParser.new({
67
65
  :params => { "PAGENAME" => "Testing123" },
68
- :data => "[[ Hello World ]] From {{ PAGENAME }} on {{ date }}\n"
66
+ :data => "{{hello|world}} From {{ PAGENAME }} -- [www.google.com]"
69
67
  })
70
68
 
71
69
  @wiki.to_html =>
72
70
  <p>
73
- <a href="javascript:alert('You clicked on: Hello World');">Hello World</a> From Testing123 on Wed Jul 08 22:23:44 -0400 2009
71
+ Hello world From Testing123 -- <a href="http://www.google.com" target="_blank" class="exlink">http://www.google.com</a>
74
72
  </p>
75
-
data/lib/wikicloth.rb CHANGED
@@ -10,7 +10,7 @@ String.send(:include, ExtendedString)
10
10
 
11
11
  module WikiCloth
12
12
 
13
- VERSION = "0.6.1"
13
+ VERSION = "0.6.2"
14
14
 
15
15
  class WikiCloth
16
16
 
@@ -54,7 +54,7 @@ module WikiCloth
54
54
 
55
55
  def render(opt={})
56
56
  noedit = false
57
- self.params.merge!({ 'WIKI_VERSION' => ::WikiCloth::VERSION })
57
+ self.params.merge!({ 'WIKI_VERSION' => ::WikiCloth::VERSION, 'RUBY_VERSION' => RUBY_VERSION })
58
58
  self.options = { :output => :html, :link_handler => self.link_handler, :params => self.params, :sections => self.sections }.merge(opt)
59
59
  self.options[:link_handler].params = options[:params]
60
60
  data = self.sections.collect { |s| s.render(self.options) }.join
@@ -75,9 +75,10 @@ module WikiCloth
75
75
  ret = "<h#{self.depth}>" + (options[:noedit] == true ? "" :
76
76
  "<span class=\"editsection\">&#91;<a href=\"" + options[:link_handler].section_link(self.id) +
77
77
  "\" title=\"Edit section: #{self.title}\">edit</a>&#93;</span> ") +
78
- "<span id=\"#{self.id}\" class=\"mw-headline\">#{self.title}</span></h#{self.depth}>"
78
+ "<span id=\"#{self.id}\" class=\"mw-headline\"><a name=\"#{self.id}\">#{self.title}</a></span></h#{self.depth}>"
79
79
  end
80
- ret += @template ? self.gsub(/\{\{\{\s*([A-Za-z0-9]+)\s*\}\}\}/,'\1') : self
80
+ #ret += @template ? self.gsub(/\{\{\{\s*([A-Za-z0-9]+)\s*\}\}\}/,'\1') : self
81
+ ret += self
81
82
  ret += "__TOC__" if @auto_toc
82
83
  ret += @children.collect { |c| c.render(options) } .join
83
84
  ret
@@ -147,7 +147,14 @@ class WikiBuffer
147
147
  self.data.gsub!(/---([^-]+)---/,"<strike>\\1</strike>")
148
148
  self.data.gsub!(/_([^_]+)_/,"<u>\\1</u>")
149
149
  end
150
- self.data.gsub!(/__TOC__/) { |r| @options[:link_handler].toc(@options[:sections]) }
150
+ self.data.gsub!(/__([A-Z]+)__/) { |r|
151
+ case $1
152
+ when "TOC"
153
+ @options[:link_handler].toc(@options[:sections])
154
+ else
155
+ ""
156
+ end
157
+ }
151
158
  self.data.gsub!(/^([-]{4,})/) { |r| "<hr />" }
152
159
  self.data.gsub!(/^([=]{1,6})\s*(.*?)\s*(\1)/) { |r|
153
160
  "<h#{$1.length}>#{$2}</h#{$1.length}>"
@@ -8,8 +8,8 @@ class WikiBuffer::HTMLElement < WikiBuffer
8
8
  ALLOWED_ELEMENTS = ['a','b','i','img','div','span','sup','sub','strike','s','u','font','big','ref','tt','del',
9
9
  'small','blockquote','strong','pre','code','references','ol','li','ul','dd','dt','dl','center',
10
10
  'h1','h2','h3','h4','h5','h6','p','table','tr','td','th','tbody','thead','tfoot']
11
- ALLOWED_ATTRIBUTES = ['src','id','name','style','class','href','start','value','colspan','align','boder',
12
- 'cellpadding','cellspacing']
11
+ ALLOWED_ATTRIBUTES = ['src','id','name','style','class','href','start','value','colspan','align','border',
12
+ 'cellpadding','cellspacing','name','valign','color','rowspan','nowrap','title','rel','for']
13
13
  ESCAPED_TAGS = [ 'nowiki', 'pre', 'code' ]
14
14
  SHORT_TAGS = [ 'meta','br','hr']
15
15
  NO_NEED_TO_CLOSE = ['li','p'] + SHORT_TAGS
@@ -88,7 +88,12 @@ class WikiBuffer::HTMLElement < WikiBuffer
88
88
  when "nowiki"
89
89
  return self.element_content
90
90
  when "a"
91
- return @options[:link_handler].external_link(self.element_attributes['href'], self.element_content)
91
+ if self.element_attributes['href'] =~ /:\/\//
92
+ return @options[:link_handler].external_link(self.element_attributes['href'], self.element_content)
93
+ elsif self.element_attributes['href'].nil? || self.element_attributes['href'] =~ /^\s*([\?\/])/
94
+ # if a element has no href attribute, or href starts with / or ?
95
+ return elem.tag!(self.element_name, self.element_attributes) { |x| x << self.element_content }
96
+ end
92
97
  end
93
98
 
94
99
  tmp = elem.tag!(self.element_name, self.element_attributes) { |x| x << self.element_content }
@@ -14,7 +14,10 @@ class WikiBuffer::Link < WikiBuffer
14
14
  def to_s
15
15
  link_handler = @options[:link_handler]
16
16
  unless self.internal_link
17
- return link_handler.external_link("#{params[0]}".strip, "#{params[1]}".strip)
17
+ url = "#{params[0]}".strip
18
+ url = 'http://' + url if url !~ /^\s*(([a-z]+):\/\/|[\?\/])/
19
+
20
+ return link_handler.external_link(url, "#{params[1]}".strip)
18
21
  else
19
22
  case
20
23
  when params[0] =~ /^:(.*)/
@@ -94,7 +94,6 @@ class WikiBuffer::Var < WikiBuffer
94
94
  default.nil? ? "" : default
95
95
  when "#expr"
96
96
  begin
97
- puts params.first.inspect
98
97
  ExpressionParser::Parser.new.parse(params.first)
99
98
  rescue RuntimeError
100
99
  "Expression error: #{$!}"
@@ -69,7 +69,7 @@ class WikiLinkHandler
69
69
 
70
70
  def external_link(url,text)
71
71
  self.external_links << url
72
- elem.a({ :href => url }) { |x| x << (text.blank? ? url : text) }
72
+ elem.a({ :href => url, :target => "_blank" }) { |x| x << (text.blank? ? url : text) }
73
73
  end
74
74
 
75
75
  def external_links=(val)
@@ -27,11 +27,59 @@ class WikiClothTest < ActiveSupport::TestCase
27
27
  test "links and references" do
28
28
  wiki = WikiCloth::Parser.new(:data => File.open(File.join(File.dirname(__FILE__), '../sample_documents/george_washington.wiki'), READ_MODE) { |f| f.read })
29
29
  data = wiki.to_html
30
- assert wiki.external_links.size == 62
30
+ assert wiki.external_links.size == 41
31
31
  assert wiki.references.size == 76
32
32
  assert wiki.internal_links.size == 560
33
33
  end
34
34
 
35
+ test "behavior switch should not show up in the html output" do
36
+ wiki = WikiParser.new(:data => "__NOTOC__hello world")
37
+ data = wiki.to_html
38
+ assert data !~ /TOC/
39
+ end
40
+
41
+ test "template vars should not be parsed inside a pre tag" do
42
+ wiki = WikiCloth::Parser.new(:data => "<pre>{{{1}}}</pre>")
43
+ data = wiki.to_html
44
+ assert data =~ /&#123;&#123;&#123;1&#125;&#125;&#125;/
45
+ end
46
+
47
+ test "[[ links ]] should not work inside pre tags" do
48
+ data = <<EOS
49
+ Now instead of calling WikiCloth::Parser directly call your new class.
50
+
51
+ <pre> @wiki = WikiParser.new({
52
+ :params => { "PAGENAME" => "Testing123" },
53
+ :data => "[[test]] {{hello|world}} From {{ PAGENAME }} -- [www.google.com]"
54
+ })
55
+
56
+ @wiki.to_html</pre>
57
+ EOS
58
+ wiki = WikiCloth::Parser.new(:data => data)
59
+ data = wiki.to_html
60
+ assert data !~ /href/
61
+ assert data !~ /\{/
62
+ assert data !~ /\]/
63
+ end
64
+
65
+ test "external links without a http:// prefix" do
66
+ wiki = WikiCloth::Parser.new(:data => "[www.google.com]")
67
+ data = wiki.to_html
68
+ assert data =~ /http/
69
+ end
70
+
71
+ test "auto pre at end of document" do
72
+ wiki = WikiParser.new(:data => "test\n\n hello\n world\nend")
73
+ data = wiki.to_html
74
+ assert data =~ /hello/
75
+ assert data =~ /world/
76
+
77
+ wiki = WikiParser.new(:data => "test\n\n hello\n world")
78
+ data = wiki.to_html
79
+ assert data =~ /hello/
80
+ assert data =~ /world/
81
+ end
82
+
35
83
  test "template params" do
36
84
  wiki = WikiParser.new(:data => "{{testparams|test|test=bla|it worked|bla=whoo}}\n")
37
85
  data = wiki.to_html
@@ -102,7 +150,6 @@ class WikiClothTest < ActiveSupport::TestCase
102
150
  data = wiki.to_html
103
151
  assert !(data =~ /<script/)
104
152
  assert !(data =~ /onmouseover/)
105
- assert data =~ /exlink/
106
153
  end
107
154
 
108
155
  test "nowiki and code tags" do
@@ -115,10 +162,10 @@ class WikiClothTest < ActiveSupport::TestCase
115
162
  test "disable edit stuff" do
116
163
  wiki = WikiParser.new(:data => "= Hallo =")
117
164
  data = wiki.to_html
118
- assert_equal data, "<p>\n<h1><span class=\"editsection\">&#91;<a href=\"?section=Hallo\" target=\"_blank\" class=\"exlink\">edit</a>&#93;</span> <span class=\"mw-headline\" id=\"Hallo\">Hallo</span></h1>\n</p>"
165
+ assert_equal data, "<p>\n<h1><span class=\"editsection\">&#91;<a href=\"?section=Hallo\" title=\"Edit section: Hallo\">edit</a>&#93;</span> <span class=\"mw-headline\" id=\"Hallo\"><a name=\"Hallo\">Hallo</a></span></h1>\n</p>"
119
166
 
120
167
  data = wiki.to_html(:noedit => true)
121
- assert_equal data, "<p>\n<h1><span class=\"mw-headline\" id=\"Hallo\">Hallo</span></h1>\n</p>"
168
+ assert_equal data, "<p>\n<h1><span class=\"mw-headline\" id=\"Hallo\"><a name=\"Hallo\">Hallo</a></span></h1>\n</p>"
122
169
 
123
170
  end
124
171
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wikicloth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Ricciardi
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-04 00:00:00 +00:00
18
+ date: 2011-01-06 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency