wikicloth


An implementation of the mediawiki markup in ruby

Ruby implementation of the MediaWiki markup language.

Source Code: http://github.com/nricciar/wikicloth

Supports

  • Variables, Templates {{ ... }}
  • Links
    • External Links [ ... ]
    • Internal Links, Images [[ ... ]]
  • 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 git://github.com/nricciar/wikicloth.git

Controller

``` include WikiCloth

def show @wiki = WikiCloth.new({ :data => "{{test}} ''Hello {{test}}!''\n", :params => { "test" => "World" } }) end ```

View

<%= @wiki.to_html -%>

Output

<p>&#123;&#123;test&#125;&#125; <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

end ```

You 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 end

Controller

``` include WikiCloth

def show @wiki = WikiCloth.new({ :params => { "PAGENAME" => "Testing123" }, :link_handler => CustomLinkHandler.new, :data => "Hello World From {{ PAGENAME }} on {{ date }}\n" }) end ```

Output (@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>

Project Information

Labels:
ruby wiki mediawiki rails