class TaskJuggler::RichText

RichText is a MediaWiki markup parser and HTML generator implemented in pure Ruby. It can also generate plain text versions of the original markup text. It is based on the TextParser class to implement the RichTextParser. The scanner is implemented in the RichTextScanner class. The read-in text is converted into a tree of RichTextElement objects. These can then be turned into HTML element trees modelled by XMLElement or plain text.

This class supports the following mark-ups:

The following markups are block commands and must start at the beginning of the line.

== Headline 1 ==
=== Headline 2 ===
==== Headline 3 ====

---- creates a horizontal line

* Bullet 1
** Bullet 2
*** Bullet 3

# Enumeration Level 1
## Enumeration Level 2
### Enumeration Level 3

 Preformatted text start with
 a single space at the start of
 each line.

The following are in-line mark-ups and can occur within any text block

This is an ''italic'' word.
This is a '''bold''' word.
This is a ''''monospaced'''' word. This is not part of the original
MediaWiki markup, but we needed monospaced as well.
This is a '''''italic and bold''''' word.

Linebreaks are ignored if not followed by a blank line.

[] A web link
[ The TaskJuggler Web Site] another link

[[item]] site internal internal reference (in HTML .html gets appended
[[item An item]] another internal reference
[[function:path arg1 arg2 ...]]

<nowiki> ... </nowiki> Disable markup interpretation for the enclosed
portion of text.



Public Class Methods

new(text, functionHandlers = []) click to toggle source

Create a rich text object by passing a String with markup elements to it. text must be plain text with MediaWiki compatible markup elements. In case an error occurs, an exception of type TjException will be raised. functionHandlers is a Hash that maps RichTextFunctionHandler objects by their function name.

# File lib/taskjuggler/RichText.rb, line 85
def initialize(text, functionHandlers = [])
  # Keep a copy of the original text.
  @inputText = text
  @functionHandlers = functionHandlers

Public Instance Methods

functionHandler(name, block) click to toggle source

Return the RichTextFunctionHandler for the function name. block specifies whether we are looking for a block or inline function.

# File lib/taskjuggler/RichText.rb, line 123
def functionHandler(name, block)
  @functionHandlers.each do |handler|
    return handler if handler.function == name &&
                      handler.blockFunction == block
generateIntermediateFormat(sectionCounter = [ 0, 0, 0], tokenSet = nil) click to toggle source

Convert the @inputText into an abstract syntax tree that can then be converted into the various output formats. sectionCounter is an Array that holds the initial values for the section counters.

# File lib/taskjuggler/RichText.rb, line 94
def generateIntermediateFormat(sectionCounter = [ 0, 0, 0], tokenSet = nil)
  rti =
  # Copy the function handlers.
  @functionHandlers.each do |h|

  # We'll setup the RichTextParser once and share it across all instances.
  if @@parser
    # We already have a RichTextParser that we can reuse.
    @@parser.reuse(rti, sectionCounter, tokenSet)
    # There is no RichTextParser yet, create one.
    @@parser =, sectionCounter, tokenSet)
  # Parse the input text and convert it to the intermediate representation.
  return nil if (tree = @@parser.parse(:richtext)) == false

  # In case the result is empty, use an empty RichTextElement as result
  tree =, :richtext, nil) unless tree
  rti.tree = tree