Skip to content

WikiCloth::Parser

advorak edited this page Jan 31, 2012 · 1 revision

Most features of WikiCloth can be overridden as needed by extending the WikiCloth::Parser class...

    url_for do |page|
      "javascript:alert('You clicked on: #{page}');"
    end

    link_attributes_for do |page|
      { :href => url_for(page) }
    end

    template do |template|
      "Hello {{{1}}}" if template == "hello"
    end

    external_link do |url,text|
      "<a href=\"#{url}\" target=\"_blank\" class=\"exlink\">#{text.blank? ? url : text}</a>"
    end

  end

Now instead of calling WikiCloth::Parser directly call your new class.

  @wiki.to_html

output:

  <p>
  Hello world From Testing123 -- <a href="http://www.google.com" target="_blank" class="exlink">http://www.google.com</a>
  </p>
Clone this wiki locally