Class Creole::Parser
In: lib/creole/parser.rb
Parent: Object

Methods

Attributes

allowed_schemes  [RW]  Allowed url schemes Examples: http https ftp ftps
extensions  [W]  Non-standard wiki text extensions enabled? E.g. underlined, deleted text etc
no_escape  [W]  Disable url escaping for local links Escaping: [[/Test]] —> %2FTest No escaping: [[/Test]] —> Test

Public Class methods

Create a new CreoleParser instance.

Public Instance methods

Convert CCreole text to HTML and return the result. The resulting HTML does not contain <html> and <body> tags.

Example:

   parser = CreoleParser.new("**Hello //World//**", :extensions => true)
   parser.to_html
      #=> "<p><strong>Hello <em>World</em></strong></p>"

Protected Instance methods

Escape any characters with special meaning in HTML using HTML entities.

Escape any characters with special meaning in URLs using URL encoding.

Sanatize a direct url (e.g. wikipedia.org/). The default behaviour returns the original link as-is.

Must ensure that the result is properly URL-escaped. The caller will handle HTML escaping as necessary. Links will not be converted to HTML links if the function returns link.

Custom versions of this function in inherited classes can implement specific link handling behaviour, such as redirection to intermediate pages (for example, for notifing the user that he is leaving the site).

Create image markup. This method can be overridden to generate custom markup, for example to add html additional attributes or to put divs around the imgs.

Sanatize and prefix image URLs. When images are encountered in Creole text, this function is called to obtain the actual URL of the image. The default behaviour is to return the image link as-is. No image tags are inserted if the function returns nil.

Custom version of the method can be used to sanatize URLs (e.g. remove query-parts), inhibit off-site images, or add a base URL, for example:

   def make_image_link(url)
      URI.join("http://mywiki.org/images/", url)
   end

Translate an explicit local link to a desired URL that is properly URL-escaped. The default behaviour is to convert local links directly, escaping any characters that have special meaning in URLs. Relative URLs in local links are not handled.

Examples:

  make_local_link("LocalLink") #=> "LocalLink"
  make_local_link("/Foo/Bar") #=> "%2FFoo%2FBar"

Must ensure that the result is properly URL-escaped. The caller will handle HTML escaping as necessary. HTML links will not be inserted if the function returns nil.

Example custom behaviour:

  make_local_link("LocalLink") #=> "/LocalLink"
  make_local_link("Wikipedia:Bread") #=> "http://en.wikipedia.org/wiki/Bread"

[Validate]