Ruby implementation of the MediaWiki markup language.
Supports
- Variables, Templates {{ ... }}
- Links
- External Links [ ... ]
- Internal Links, Images [[ ... ]]
- (see also pipe trick)
- Wikimedia Markup
- == Headings ==
- Lists (*#;:)
- bold ('''), italic ('') or both (''''')
- Horizontal rule (----)
- Tables
- <code>,<nowiki>,<pre> (disable wiki markup)
- space at the beginning of a line (<pre>)
- <ref> and <references/> support
- html sanitization
Getting Started
Install
./script/plugin install http://wikicloth.googlecode.com/svn/trunk/wikicloth/
Controller
include WikiCloth
def show
@wiki = WikiCloth.new({
:data => "<nowiki>{{test}}</nowiki> ''Hello {{test}}!''\n",
:params => { "test" => "World" } })
endView
<%= @wiki.to_html -%>
Output
<p>{{test}} <i>Hello World!</i></p>
Wiki Links and Variable/Template Handling
Use the url_for and link_attributes_for methods to override the default URL for an [[internal link]]. If you need even more control, the link_for can also be used to return raw html.
custom_link_handler.rb
class CustomLinkHandler < WikiCloth::WikiLinkHandler
def url_for(page)
"javascript:alert('You clicked on: #{page}');"
end
def link_attributes_for(page)
{ :href => url_for(page) }
end
endYou can also override the include_resource method to give you control over {{ template_variables }}...
custom_link_handler.rb
def include_resource(resource,options=[])
case resource
when "date"
Time.now.to_s
else
# default behavior
super(resource,options)
end
endController
include WikiCloth
def show
@wiki = WikiCloth.new({
:params => { "PAGENAME" => "Testing123" },
:link_handler => CustomLinkHandler.new,
:data => "Hello World From {{ PAGENAME }} on {{ date }}\n"
})
endOutput (@wiki.to_html)
<p>
<a href="javascript:alert('You clicked on: Hello World');">Hello World</a> From Testing123 on Wed Jul 08 22:23:44 -0400 2009
</p>