wikicloth 0.7.0 → 0.7.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/.gitignore +3 -0
- data/.travis.yml +3 -0
- data/Gemfile +2 -0
- data/README +1 -1
- data/README.textile +72 -0
- data/Rakefile +19 -26
- data/examples/info.rb +15 -0
- data/examples/print.rb +23 -0
- data/lib/wikicloth.rb +3 -3
- data/lib/wikicloth/version.rb +3 -0
- data/lib/wikicloth/wiki_buffer.rb +5 -5
- data/lib/wikicloth/wiki_link_handler.rb +16 -7
- data/run_tests.rb +0 -1
- data/sample_documents/default.css +34 -0
- data/sample_documents/wiki.png +0 -0
- data/test/wiki_cloth_test.rb +69 -3
- data/wikicloth.gemspec +29 -0
- metadata +78 -30
- data/install.rb +0 -0
- data/uninstall.rb +0 -0
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README
CHANGED
@@ -7,7 +7,6 @@ Supports
|
|
7
7
|
* Links
|
8
8
|
o External Links [ ... ]
|
9
9
|
o Internal Links, Images [[ ... ]]
|
10
|
-
+ (see also pipe trick)
|
11
10
|
* Wikimedia Markup
|
12
11
|
o == Headings ==
|
13
12
|
o Lists (*#;:)
|
@@ -33,6 +32,7 @@ Usage
|
|
33
32
|
@wiki = WikiCloth::Parser.new({
|
34
33
|
:data => "<nowiki>{{test}}</nowiki> ''Hello {{test}}!''\n",
|
35
34
|
:params => { "test" => "World" } })
|
35
|
+
|
36
36
|
@wiki.to_html => "<p>{{test}} <i>Hello World!</i></p>"
|
37
37
|
|
38
38
|
|
data/README.textile
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
h2. WikiCloth "!https://secure.travis-ci.org/nricciar/wikicloth.png!":http://travis-ci.org/nricciar/wikicloth
|
2
|
+
|
3
|
+
Ruby implementation of the MediaWiki markup language.
|
4
|
+
|
5
|
+
h2. Supports
|
6
|
+
|
7
|
+
* Variables, Templates {{ ... }}
|
8
|
+
* Links
|
9
|
+
** External Links [ ... ]
|
10
|
+
** Internal Links, Images [[ ... ]]
|
11
|
+
* Wikimedia Markup
|
12
|
+
** == Headings ==
|
13
|
+
** Lists (*#;:)
|
14
|
+
** bold (<code>'''</code>), italic (<code>''</code>) or both (<code>'''''</code>)
|
15
|
+
** Horizontal rule (----)
|
16
|
+
** "Tables":https://github.com/nricciar/wikicloth/wiki/Tables
|
17
|
+
** Table of Contents [<code>__NOTOC__, __FORCETOC__, __TOC__</code>]
|
18
|
+
* <code><code>,<nowiki>,<pre></code> (disable wiki markup)
|
19
|
+
* <ref> and <references/> support
|
20
|
+
* "html sanitization":https://github.com/nricciar/wikicloth/wiki/Html-Sanitization
|
21
|
+
|
22
|
+
For more information about the MediaWiki markup see "http://www.mediawiki.org/wiki/Markup_spec":http://www.mediawiki.org/wiki/Markup_spec
|
23
|
+
|
24
|
+
h2. Install
|
25
|
+
|
26
|
+
<pre> git clone git://github.com/nricciar/wikicloth.git
|
27
|
+
cd wikicloth/
|
28
|
+
rake install</pre>
|
29
|
+
|
30
|
+
h2. Usage
|
31
|
+
|
32
|
+
<pre> @wiki = WikiCloth::Parser.new({
|
33
|
+
:data => "<nowiki>{{test}}</nowiki> ''Hello {{test}}!''\n",
|
34
|
+
:params => { "test" => "World" } })
|
35
|
+
|
36
|
+
@wiki.to_html => "<p>{{test}} <i>Hello World!</i></p>"</pre>
|
37
|
+
|
38
|
+
|
39
|
+
h2. Advanced Usage
|
40
|
+
|
41
|
+
Most features of WikiCloth can be overriden as needed...
|
42
|
+
|
43
|
+
<pre> class WikiParser < WikiCloth::Parser
|
44
|
+
|
45
|
+
url_for do |page|
|
46
|
+
"javascript:alert('You clicked on: #{page}');"
|
47
|
+
end
|
48
|
+
|
49
|
+
link_attributes_for do |page|
|
50
|
+
{ :href => url_for(page) }
|
51
|
+
end
|
52
|
+
|
53
|
+
template do |template|
|
54
|
+
"Hello {{{1}}}" if template == "hello"
|
55
|
+
end
|
56
|
+
|
57
|
+
external_link do |url,text|
|
58
|
+
"<a href=\"#{url}\" target=\"_blank\" class=\"exlink\">#{text.blank? ? url : text}</a>"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
@wiki = WikiParser.new({
|
64
|
+
:params => { "PAGENAME" => "Testing123" },
|
65
|
+
:data => "{{hello|world}} From {{ PAGENAME }} -- [www.google.com]"
|
66
|
+
})
|
67
|
+
|
68
|
+
@wiki.to_html =>
|
69
|
+
<p>
|
70
|
+
Hello world From Testing123 -- <a href="http://www.google.com" target="_blank" class="exlink">http://www.google.com</a>
|
71
|
+
</p></pre>
|
72
|
+
|
data/Rakefile
CHANGED
@@ -1,38 +1,31 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
require 'rake/gempackagetask'
|
5
2
|
require File.join(File.dirname(__FILE__),'init')
|
6
3
|
|
7
4
|
require 'bundler'
|
8
5
|
Bundler::GemHelper.install_tasks
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rdoc.rdoc_dir = 'rdoc'
|
15
|
-
rdoc.title = 'WikiCloth'
|
16
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
17
|
-
rdoc.rdoc_files.include('README')
|
18
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
7
|
+
require 'rake/testtask'
|
8
|
+
Rake::TestTask.new(:test) do |test|
|
9
|
+
test.pattern = 'test/*_test.rb'
|
10
|
+
test.verbose = true
|
19
11
|
end
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
file_name[root] if root
|
13
|
+
require 'rcov/rcovtask'
|
14
|
+
Rcov::RcovTask.new do |test|
|
15
|
+
test.libs << 'test'
|
16
|
+
test.pattern = 'test/**/test_*.rb'
|
17
|
+
test.verbose = true
|
27
18
|
end
|
28
19
|
|
29
|
-
|
30
|
-
multiruby = lambda do |glob|
|
31
|
-
system 'multiruby', TEST_LOADER, *Dir.glob(glob)
|
32
|
-
end
|
20
|
+
task :default => :test
|
33
21
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
22
|
+
require 'rake/rdoctask'
|
23
|
+
Rake::RDocTask.new do |rdoc|
|
24
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
25
|
+
|
26
|
+
rdoc.rdoc_dir = 'rdoc'
|
27
|
+
rdoc.title = "wikicloth #{version}"
|
28
|
+
rdoc.rdoc_files.include('README*')
|
29
|
+
rdoc.rdoc_files.include('LICENSE')
|
30
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
38
31
|
end
|
data/examples/info.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'../init.rb')
|
2
|
+
if ARGV[0] && File.exists?(ARGV[0])
|
3
|
+
data = File.read(ARGV[0])
|
4
|
+
else
|
5
|
+
data = "[[ this ]] is a [[ link ]] and another [http://www.google.com Google]. This is a <ref>reference</ref>, but this is a [[Category:Test]]. This is in another [[de:Sprache]]"
|
6
|
+
end
|
7
|
+
|
8
|
+
wiki = WikiCloth::Parser.new(:data => data)
|
9
|
+
wiki.to_html
|
10
|
+
|
11
|
+
puts "Internal Links: #{wiki.internal_links.size}"
|
12
|
+
puts "External Links: #{wiki.external_links.size}"
|
13
|
+
puts "References: #{wiki.references.size}"
|
14
|
+
puts "Categories: #{wiki.categories.size} [#{wiki.categories.join(",")}]"
|
15
|
+
puts "Languages: #{wiki.languages.size} [#{wiki.languages.keys.join(",")}]"
|
data/examples/print.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'../init.rb')
|
2
|
+
if ARGV[0] && File.exists?(ARGV[0])
|
3
|
+
data = File.read(ARGV[0])
|
4
|
+
else
|
5
|
+
data = "[[ this ]] is a [[ link ]] and another [http://www.google.com Google] but they should be disabled"
|
6
|
+
end
|
7
|
+
|
8
|
+
# Disables all links in the document for printing
|
9
|
+
class PrettyPrint < WikiCloth::Parser
|
10
|
+
|
11
|
+
external_link do |url,text|
|
12
|
+
text.nil? ? url : "#{text} (#{url})"
|
13
|
+
end
|
14
|
+
|
15
|
+
link_for do |page,text|
|
16
|
+
text.nil? ? page : text
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
# load file into custom parser and render without
|
22
|
+
# section edit links
|
23
|
+
puts PrettyPrint.new(:data => data).to_html(:noedit => true)
|
data/lib/wikicloth.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'jcode' if RUBY_VERSION < '1.9'
|
2
2
|
require File.join(File.expand_path(File.dirname(__FILE__)), "wikicloth", "core_ext")
|
3
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "wikicloth", "version")
|
3
4
|
require File.join(File.expand_path(File.dirname(__FILE__)), "wikicloth", "wiki_buffer")
|
4
5
|
require File.join(File.expand_path(File.dirname(__FILE__)), "wikicloth", "wiki_link_handler")
|
5
6
|
require File.join(File.expand_path(File.dirname(__FILE__)), "wikicloth", "parser")
|
@@ -10,8 +11,6 @@ String.send(:include, ExtendedString)
|
|
10
11
|
|
11
12
|
module WikiCloth
|
12
13
|
|
13
|
-
VERSION = "0.7.0"
|
14
|
-
|
15
14
|
class WikiCloth
|
16
15
|
|
17
16
|
def initialize(opt={})
|
@@ -61,7 +60,8 @@ module WikiCloth
|
|
61
60
|
self.options[:link_handler].params = options[:params]
|
62
61
|
data = self.sections.collect { |s| s.render(self.options) }.join
|
63
62
|
data.gsub!(/<!--(.|\s)*?-->/,"")
|
64
|
-
data << "\
|
63
|
+
data << "\n" if data.last(1) != "\n"
|
64
|
+
data << "garbage"
|
65
65
|
|
66
66
|
buffer = WikiBuffer.new("",options)
|
67
67
|
|
@@ -70,14 +70,14 @@ class WikiBuffer
|
|
70
70
|
def check_globals()
|
71
71
|
return false if self.class != WikiBuffer
|
72
72
|
|
73
|
-
if previous_char == "\n"
|
74
|
-
if @indent == @buffers[-1].object_id && current_char != " "
|
73
|
+
if previous_char == "\n" || previous_char == ""
|
74
|
+
if @indent == @buffers[-1].object_id && current_char != " "
|
75
|
+
@indent = nil
|
75
76
|
# close pre tag
|
76
77
|
cc_temp = current_char
|
77
78
|
"</pre>\n".each_char { |c| self.add_char(c) }
|
78
79
|
# get the parser back on the right track
|
79
80
|
"\n#{cc_temp}".each_char { |c| @buffers[-1].add_char(c) }
|
80
|
-
@indent = nil
|
81
81
|
return true
|
82
82
|
end
|
83
83
|
if current_char == " " && @indent.nil? && ![WikiBuffer::HTMLElement,WikiBuffer::Var].include?(@buffers[-1].class)
|
@@ -182,7 +182,7 @@ class WikiBuffer
|
|
182
182
|
self.data.gsub!(/__([A-Z]+)__/) { |r|
|
183
183
|
case $1
|
184
184
|
when "TOC"
|
185
|
-
@options[:link_handler].toc(@options[:sections])
|
185
|
+
@options[:link_handler].toc(@options[:sections], @options[:toc_numbered])
|
186
186
|
else
|
187
187
|
""
|
188
188
|
end
|
@@ -226,7 +226,7 @@ class WikiBuffer
|
|
226
226
|
@paragraph_open = false
|
227
227
|
else
|
228
228
|
if self.data =~ /^\s*$/ && @paragraph_open && @list_data.empty?
|
229
|
-
self.data = "</p
|
229
|
+
self.data = "</p>#{self.data}"
|
230
230
|
@paragraph_open = false
|
231
231
|
else
|
232
232
|
if self.data !~ /^\s*$/
|
@@ -43,27 +43,36 @@ class WikiLinkHandler
|
|
43
43
|
ret.flatten
|
44
44
|
end
|
45
45
|
|
46
|
-
def toc(sections)
|
47
|
-
ret = "<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div>"
|
46
|
+
def toc(sections, toc_numbered=false)
|
47
|
+
ret = "<table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul>"
|
48
48
|
previous_depth = 1
|
49
|
-
|
49
|
+
indices = []
|
50
|
+
section_list(sections).each do |section|
|
51
|
+
next if section.title.nil?
|
50
52
|
if section.depth > previous_depth
|
53
|
+
indices[section.depth] = 0 if indices[section.depth].nil?
|
54
|
+
indices[section.depth] += 1
|
51
55
|
c = section.depth - previous_depth
|
52
56
|
c.times { ret += "<ul>" }
|
53
|
-
ret += "<li><a href=\"##{section.id}\">#{section.title}</a>"
|
57
|
+
ret += "<li><a href=\"##{section.id}\">#{indices[0..section.depth].compact.join('.') + " " if toc_numbered}#{section.title}</a>"
|
54
58
|
elsif section.depth == previous_depth
|
55
|
-
|
59
|
+
indices[section.depth] = 0 if indices[section.depth].nil?
|
60
|
+
indices[section.depth] += 1
|
61
|
+
ret += "</li><li><a href=\"##{section.id}\">#{indices[0..section.depth].compact.join('.') + " " if toc_numbered}#{section.title}</a>"
|
56
62
|
else
|
63
|
+
indices[section.depth] = 0 if indices[section.depth].nil?
|
64
|
+
indices[section.depth] += 1
|
65
|
+
indices = indices[0..section.depth]
|
57
66
|
ret += "</li>" unless previous_depth == 1
|
58
67
|
c = previous_depth - section.depth
|
59
68
|
c.times { ret += "</ul>" }
|
60
|
-
ret += "<li><a href=\"##{section.id}\">#{section.title}</a>"
|
69
|
+
ret += "<li><a href=\"##{section.id}\">#{indices[0..section.depth].compact.join('.') + " " if toc_numbered}#{section.title}</a>"
|
61
70
|
end
|
62
71
|
previous_depth = section.depth
|
63
72
|
end
|
64
73
|
ret += "</li>"
|
65
74
|
(previous_depth-1).times { ret += "</ul>" }
|
66
|
-
"#{ret}</td></tr></table>"
|
75
|
+
"#{ret}</ul></td></tr></table>"
|
67
76
|
end
|
68
77
|
|
69
78
|
def external_links
|
data/run_tests.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
.thumb { background-color:#F8FCFF;border:1px solid #fff;margin-bottom:0.5em }
|
2
|
+
.tright { border-width:0.5em 0 0.8em 1.4em;margin:0.5em 0 0.8em 1.4em;clear:right;float:right }
|
3
|
+
.thumbinner {
|
4
|
+
background-color:#F9F9F9;
|
5
|
+
border:1px solid #CCCCCC;
|
6
|
+
font-size:94%;
|
7
|
+
overflow:hidden;
|
8
|
+
padding:3px !important;
|
9
|
+
text-align:center;
|
10
|
+
}
|
11
|
+
.thumbimage { border:1px solid #CCCCCC }
|
12
|
+
|
13
|
+
h1, h2, h3, h4, h5, h6 {
|
14
|
+
padding-bottom:0.17em;
|
15
|
+
padding-top:0.5em;
|
16
|
+
color:#000;
|
17
|
+
}
|
18
|
+
h2, h1 { border-bottom:1px solid #AAAAAA; }
|
19
|
+
.editsection {
|
20
|
+
font-size:76%;
|
21
|
+
font-weight:normal;
|
22
|
+
}
|
23
|
+
.editsection {
|
24
|
+
float:right;
|
25
|
+
margin-left:5px;
|
26
|
+
}
|
27
|
+
|
28
|
+
pre {
|
29
|
+
background-color:#F9F9F9;
|
30
|
+
border:1px dashed #2F6FAB;
|
31
|
+
color:black;
|
32
|
+
line-height:1.1em;
|
33
|
+
padding:1em;
|
34
|
+
}
|
Binary file
|
data/test/wiki_cloth_test.rb
CHANGED
@@ -159,7 +159,7 @@ EOS
|
|
159
159
|
test "table spanning template" do
|
160
160
|
wiki = WikiParser.new(:data => "{{tablebegin}}{{tablemid}}{{tableend}}")
|
161
161
|
data = wiki.to_html
|
162
|
-
|
162
|
+
|
163
163
|
assert data =~ /test/
|
164
164
|
end
|
165
165
|
|
@@ -228,11 +228,77 @@ EOS
|
|
228
228
|
test "disable edit stuff" do
|
229
229
|
wiki = WikiParser.new(:data => "= Hallo =")
|
230
230
|
data = wiki.to_html
|
231
|
-
|
231
|
+
if RUBY_VERSION == "1.8.7"
|
232
|
+
assert_equal data, "\n<p><h1><span class=\"editsection\">[<a href=\"?section=Hallo\" title=\"Edit section: Hallo\">edit</a>]</span> <span class=\"mw-headline\" id=\"Hallo\"><a name=\"Hallo\">Hallo</a></span></h1></p>"
|
233
|
+
else
|
234
|
+
assert_equal data, "\n<p><h1><span class=\"editsection\">[<a href=\"?section=Hallo\" title=\"Edit section: Hallo\">edit</a>]</span> <span id=\"Hallo\" class=\"mw-headline\"><a name=\"Hallo\">Hallo</a></span></h1></p>"
|
235
|
+
end
|
232
236
|
|
233
237
|
data = wiki.to_html(:noedit => true)
|
234
|
-
|
238
|
+
if RUBY_VERSION == "1.8.7"
|
239
|
+
assert_equal data, "\n<p><h1><span class=\"mw-headline\" id=\"Hallo\"><a name=\"Hallo\">Hallo</a></span></h1></p>"
|
240
|
+
else
|
241
|
+
assert_equal data, "\n<p><h1><span id=\"Hallo\" class=\"mw-headline\"><a name=\"Hallo\">Hallo</a></span></h1></p>"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
test "render toc" do
|
246
|
+
wiki = WikiCloth::WikiCloth.new({:data => "=A=\n=B=\n=C=\n=D="})
|
247
|
+
data = wiki.render
|
248
|
+
assert data =~ /A/
|
249
|
+
end
|
235
250
|
|
251
|
+
test "table after paragraph" do
|
252
|
+
wiki = WikiCloth::WikiCloth.new({:data => "A\n{|style=""\n|\n|}"})
|
253
|
+
data = wiki.render
|
254
|
+
assert data =~ /table/
|
236
255
|
end
|
237
256
|
|
257
|
+
test "pre trailing newlines" do
|
258
|
+
wiki = WikiCloth::WikiCloth.new({:data => "A\n B\n\n\n\nC"})
|
259
|
+
data = wiki.render
|
260
|
+
assert_equal data, "\n<p>A\n</p>\n<p><pre> B\n</pre>\n</p>\n\n\n\n<p>C</p>"
|
261
|
+
end
|
262
|
+
|
263
|
+
test "pre at eof" do
|
264
|
+
wiki = WikiCloth::WikiCloth.new({:data => "A\n B\n"})
|
265
|
+
data = wiki.render
|
266
|
+
assert_equal data, "\n<p>A\n</p>\n<p><pre> B\n</pre>\n</p>"
|
267
|
+
end
|
268
|
+
|
269
|
+
test "empty item in toc" do
|
270
|
+
wiki = WikiCloth::WikiCloth.new({:data => "__TOC__\n=A="})
|
271
|
+
data = wiki.render
|
272
|
+
if RUBY_VERSION == "1.8.7"
|
273
|
+
assert_equal data, "\n<p><table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul></li><li><a href=\"#A\">A</a></li></ul></td></tr></table>\n<h1><span class=\"editsection\">[<a href=\"?section=A\" title=\"Edit section: A\">edit</a>]</span> <span class=\"mw-headline\" id=\"A\"><a name=\"A\">A</a></span></h1></p>"
|
274
|
+
else
|
275
|
+
assert_equal data, "\n<p><table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul></li><li><a href=\"#A\">A</a></li></ul></td></tr></table>\n<h1><span class=\"editsection\">[<a href=\"?section=A\" title=\"Edit section: A\">edit</a>]</span> <span id=\"A\" class=\"mw-headline\"><a name=\"A\">A</a></span></h1></p>"
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
test "pre at beginning" do
|
280
|
+
wiki = WikiCloth::WikiCloth.new({:data => " A"})
|
281
|
+
data = wiki.render
|
282
|
+
assert_equal data, "\n\n<p><pre> A\n</pre>\n</p>"
|
283
|
+
end
|
284
|
+
|
285
|
+
test "toc declared as list" do
|
286
|
+
wiki = WikiCloth::WikiCloth.new({:data => "__TOC__\n=A=\n==B==\n===C==="})
|
287
|
+
data = wiki.render
|
288
|
+
if RUBY_VERSION == "1.8.7"
|
289
|
+
assert_equal data, "\n<p><table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul></li><li><a href=\"#A\">A</a><ul><li><a href=\"#B\">B</a><ul><li><a href=\"#C\">C</a></li></ul></ul></ul></td></tr></table>\n<h1><span class=\"editsection\">[<a href=\"?section=A\" title=\"Edit section: A\">edit</a>]</span> <span class=\"mw-headline\" id=\"A\"><a name=\"A\">A</a></span></h1>\n<h2><span class=\"editsection\">[<a href=\"?section=B\" title=\"Edit section: B\">edit</a>]</span> <span class=\"mw-headline\" id=\"B\"><a name=\"B\">B</a></span></h2>\n<h3><span class=\"editsection\">[<a href=\"?section=C\" title=\"Edit section: C\">edit</a>]</span> <span class=\"mw-headline\" id=\"C\"><a name=\"C\">C</a></span></h3></p>"
|
290
|
+
else
|
291
|
+
assert_equal data, "\n<p><table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul></li><li><a href=\"#A\">A</a><ul><li><a href=\"#B\">B</a><ul><li><a href=\"#C\">C</a></li></ul></ul></ul></td></tr></table>\n<h1><span class=\"editsection\">[<a href=\"?section=A\" title=\"Edit section: A\">edit</a>]</span> <span id=\"A\" class=\"mw-headline\"><a name=\"A\">A</a></span></h1>\n<h2><span class=\"editsection\">[<a href=\"?section=B\" title=\"Edit section: B\">edit</a>]</span> <span id=\"B\" class=\"mw-headline\"><a name=\"B\">B</a></span></h2>\n<h3><span class=\"editsection\">[<a href=\"?section=C\" title=\"Edit section: C\">edit</a>]</span> <span id=\"C\" class=\"mw-headline\"><a name=\"C\">C</a></span></h3></p>"
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
test "toc numbered" do
|
296
|
+
wiki = WikiCloth::WikiCloth.new({:data => "=A=\n=B=\n==C==\n==D==\n===E===\n===F===\n====G====\n====H====\n==I==\n=J=\n=K=\n===L===\n===M===\n====N====\n====O===="})
|
297
|
+
data = wiki.render(:noedit => true, :toc_numbered => true)
|
298
|
+
if RUBY_VERSION == "1.8.7"
|
299
|
+
assert_equal data, "\n<p><table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul></li><li><a href=\"#A\">1 A</a></li><li><a href=\"#B\">2 B</a><ul><li><a href=\"#C\">2.1 C</a></li><li><a href=\"#D\">2.2 D</a><ul><li><a href=\"#E\">2.2.1 E</a></li><li><a href=\"#F\">2.2.2 F</a><ul><li><a href=\"#G\">2.2.2.1 G</a></li><li><a href=\"#H\">2.2.2.2 H</a></li></ul></ul><li><a href=\"#I\">2.3 I</a></li></ul><li><a href=\"#J\">3 J</a></li><li><a href=\"#K\">4 K</a><ul><ul><li><a href=\"#L\">4.1 L</a></li><li><a href=\"#M\">4.2 M</a><ul><li><a href=\"#N\">4.2.1 N</a></li><li><a href=\"#O\">4.2.2 O</a></li></ul></ul></ul></ul></td></tr></table><h1><span class=\"mw-headline\" id=\"A\"><a name=\"A\">A</a></span></h1>\n<h1><span class=\"mw-headline\" id=\"B\"><a name=\"B\">B</a></span></h1>\n<h2><span class=\"mw-headline\" id=\"C\"><a name=\"C\">C</a></span></h2>\n<h2><span class=\"mw-headline\" id=\"D\"><a name=\"D\">D</a></span></h2>\n<h3><span class=\"mw-headline\" id=\"E\"><a name=\"E\">E</a></span></h3>\n<h3><span class=\"mw-headline\" id=\"F\"><a name=\"F\">F</a></span></h3>\n<h4><span class=\"mw-headline\" id=\"G\"><a name=\"G\">G</a></span></h4>\n<h4><span class=\"mw-headline\" id=\"H\"><a name=\"H\">H</a></span></h4>\n<h2><span class=\"mw-headline\" id=\"I\"><a name=\"I\">I</a></span></h2>\n<h1><span class=\"mw-headline\" id=\"J\"><a name=\"J\">J</a></span></h1>\n<h1><span class=\"mw-headline\" id=\"K\"><a name=\"K\">K</a></span></h1>\n<h3><span class=\"mw-headline\" id=\"L\"><a name=\"L\">L</a></span></h3>\n<h3><span class=\"mw-headline\" id=\"M\"><a name=\"M\">M</a></span></h3>\n<h4><span class=\"mw-headline\" id=\"N\"><a name=\"N\">N</a></span></h4>\n<h4><span class=\"mw-headline\" id=\"O\"><a name=\"O\">O</a></span></h4></p>"
|
300
|
+
else
|
301
|
+
assert_equal data, "\n<p><table id=\"toc\" class=\"toc\" summary=\"Contents\"><tr><td><div style=\"font-weight:bold\">Table of Contents</div><ul></li><li><a href=\"#A\">1 A</a></li><li><a href=\"#B\">2 B</a><ul><li><a href=\"#C\">2.1 C</a></li><li><a href=\"#D\">2.2 D</a><ul><li><a href=\"#E\">2.2.1 E</a></li><li><a href=\"#F\">2.2.2 F</a><ul><li><a href=\"#G\">2.2.2.1 G</a></li><li><a href=\"#H\">2.2.2.2 H</a></li></ul></ul><li><a href=\"#I\">2.3 I</a></li></ul><li><a href=\"#J\">3 J</a></li><li><a href=\"#K\">4 K</a><ul><ul><li><a href=\"#L\">4.1 L</a></li><li><a href=\"#M\">4.2 M</a><ul><li><a href=\"#N\">4.2.1 N</a></li><li><a href=\"#O\">4.2.2 O</a></li></ul></ul></ul></ul></td></tr></table><h1><span id=\"A\" class=\"mw-headline\"><a name=\"A\">A</a></span></h1>\n<h1><span id=\"B\" class=\"mw-headline\"><a name=\"B\">B</a></span></h1>\n<h2><span id=\"C\" class=\"mw-headline\"><a name=\"C\">C</a></span></h2>\n<h2><span id=\"D\" class=\"mw-headline\"><a name=\"D\">D</a></span></h2>\n<h3><span id=\"E\" class=\"mw-headline\"><a name=\"E\">E</a></span></h3>\n<h3><span id=\"F\" class=\"mw-headline\"><a name=\"F\">F</a></span></h3>\n<h4><span id=\"G\" class=\"mw-headline\"><a name=\"G\">G</a></span></h4>\n<h4><span id=\"H\" class=\"mw-headline\"><a name=\"H\">H</a></span></h4>\n<h2><span id=\"I\" class=\"mw-headline\"><a name=\"I\">I</a></span></h2>\n<h1><span id=\"J\" class=\"mw-headline\"><a name=\"J\">J</a></span></h1>\n<h1><span id=\"K\" class=\"mw-headline\"><a name=\"K\">K</a></span></h1>\n<h3><span id=\"L\" class=\"mw-headline\"><a name=\"L\">L</a></span></h3>\n<h3><span id=\"M\" class=\"mw-headline\"><a name=\"M\">M</a></span></h3>\n<h4><span id=\"N\" class=\"mw-headline\"><a name=\"N\">N</a></span></h4>\n<h4><span id=\"O\" class=\"mw-headline\"><a name=\"O\">O</a></span></h4></p>"
|
302
|
+
end
|
303
|
+
end
|
238
304
|
end
|
data/wikicloth.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
|
5
|
+
require 'wikicloth/version'
|
6
|
+
|
7
|
+
spec = Gem::Specification.new do |s|
|
8
|
+
s.name = "wikicloth"
|
9
|
+
s.version = WikiCloth::VERSION
|
10
|
+
s.author = "David Ricciardi"
|
11
|
+
s.email = "nricciar@gmail.com"
|
12
|
+
s.homepage = "http://github.com/nricciar/wikicloth"
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.summary = "An implementation of the mediawiki markup in ruby"
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.require_path = "lib"
|
18
|
+
s.description = File.read("README")
|
19
|
+
s.has_rdoc = false
|
20
|
+
s.extra_rdoc_files = ["README","MIT-LICENSE"]
|
21
|
+
s.description = %q{mediawiki parser}
|
22
|
+
s.add_dependency 'builder'
|
23
|
+
s.add_dependency 'expression_parser'
|
24
|
+
s.add_development_dependency 'test-unit'
|
25
|
+
s.add_development_dependency 'activesupport'
|
26
|
+
s.add_development_dependency 'i18n'
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
s.add_development_dependency 'rcov'
|
29
|
+
end
|
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:
|
4
|
+
hash: 1
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 1
|
10
|
+
version: 0.7.1
|
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-
|
18
|
+
date: 2011-10-26 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -74,6 +74,48 @@ dependencies:
|
|
74
74
|
version: "0"
|
75
75
|
type: :development
|
76
76
|
version_requirements: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: i18n
|
79
|
+
prerelease: false
|
80
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
version_requirements: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rake
|
93
|
+
prerelease: false
|
94
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
hash: 3
|
100
|
+
segments:
|
101
|
+
- 0
|
102
|
+
version: "0"
|
103
|
+
type: :development
|
104
|
+
version_requirements: *id006
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: rcov
|
107
|
+
prerelease: false
|
108
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
type: :development
|
118
|
+
version_requirements: *id007
|
77
119
|
description: mediawiki parser
|
78
120
|
email: nricciar@gmail.com
|
79
121
|
executables: []
|
@@ -84,39 +126,47 @@ extra_rdoc_files:
|
|
84
126
|
- README
|
85
127
|
- MIT-LICENSE
|
86
128
|
files:
|
129
|
+
- .gitignore
|
130
|
+
- .travis.yml
|
131
|
+
- Gemfile
|
132
|
+
- MIT-LICENSE
|
133
|
+
- README
|
134
|
+
- README.textile
|
135
|
+
- Rakefile
|
136
|
+
- examples/info.rb
|
137
|
+
- examples/print.rb
|
138
|
+
- init.rb
|
87
139
|
- lib/wikicloth.rb
|
88
140
|
- lib/wikicloth/core_ext.rb
|
89
|
-
- lib/wikicloth/wiki_buffer/html_element.rb
|
90
|
-
- lib/wikicloth/wiki_buffer/var.rb
|
91
|
-
- lib/wikicloth/wiki_buffer/table.rb
|
92
|
-
- lib/wikicloth/wiki_buffer/link.rb
|
93
|
-
- lib/wikicloth/token.rb
|
94
141
|
- lib/wikicloth/lexer.rb
|
95
142
|
- lib/wikicloth/parser.rb
|
96
143
|
- lib/wikicloth/section.rb
|
97
|
-
- lib/wikicloth/
|
144
|
+
- lib/wikicloth/token.rb
|
145
|
+
- lib/wikicloth/version.rb
|
98
146
|
- lib/wikicloth/wiki_buffer.rb
|
99
|
-
-
|
147
|
+
- lib/wikicloth/wiki_buffer/html_element.rb
|
148
|
+
- lib/wikicloth/wiki_buffer/link.rb
|
149
|
+
- lib/wikicloth/wiki_buffer/table.rb
|
150
|
+
- lib/wikicloth/wiki_buffer/var.rb
|
151
|
+
- lib/wikicloth/wiki_link_handler.rb
|
152
|
+
- run_tests.rb
|
153
|
+
- sample_documents/air_force_one.wiki
|
154
|
+
- sample_documents/cheatsheet.wiki
|
155
|
+
- sample_documents/default.css
|
156
|
+
- sample_documents/elements.wiki
|
100
157
|
- sample_documents/george_washington.wiki
|
101
158
|
- sample_documents/images.wiki
|
102
|
-
- sample_documents/wiki_tables.wiki
|
103
|
-
- sample_documents/lists.wiki
|
104
|
-
- sample_documents/elements.wiki
|
105
|
-
- sample_documents/tv.wiki
|
106
159
|
- sample_documents/klaus_schulze.wiki
|
107
|
-
- sample_documents/
|
108
|
-
- sample_documents/air_force_one.wiki
|
109
|
-
- sample_documents/cheatsheet.wiki
|
160
|
+
- sample_documents/lists.wiki
|
110
161
|
- sample_documents/pipe_trick.wiki
|
111
|
-
-
|
112
|
-
-
|
113
|
-
-
|
114
|
-
-
|
115
|
-
-
|
116
|
-
- MIT-LICENSE
|
117
|
-
- test/wiki_cloth_test.rb
|
162
|
+
- sample_documents/random.wiki
|
163
|
+
- sample_documents/tv.wiki
|
164
|
+
- sample_documents/wiki.png
|
165
|
+
- sample_documents/wiki_tables.wiki
|
166
|
+
- tasks/wikicloth_tasks.rake
|
118
167
|
- test/test_helper.rb
|
119
|
-
-
|
168
|
+
- test/wiki_cloth_test.rb
|
169
|
+
- wikicloth.gemspec
|
120
170
|
has_rdoc: true
|
121
171
|
homepage: http://github.com/nricciar/wikicloth
|
122
172
|
licenses: []
|
@@ -151,7 +201,5 @@ rubygems_version: 1.3.7
|
|
151
201
|
signing_key:
|
152
202
|
specification_version: 3
|
153
203
|
summary: An implementation of the mediawiki markup in ruby
|
154
|
-
test_files:
|
155
|
-
|
156
|
-
- test/test_helper.rb
|
157
|
-
- run_tests.rb
|
204
|
+
test_files: []
|
205
|
+
|
data/install.rb
DELETED
File without changes
|
data/uninstall.rb
DELETED
File without changes
|