In Files

Parent

Class Index [+]

Quicksearch

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.

 [http://www.taskjuggler.org] A web link
 [http://www.taskjuggler.org The TaskJuggler Web Site] another link

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

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

Attributes

inputText[R]
messageHandler[R]

Public Class Methods

new(text, functionHandlers = [], messageHandler = nil) 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/RichText.rb, line 86
86:     def initialize(text, functionHandlers = [], messageHandler = nil)
87:       # Keep a copy of the original text.
88:       @inputText = text
89:       @functionHandlers = functionHandlers
90:       @messageHandler = messageHandler || MessageHandler.new
91:     end

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/RichText.rb, line 126
126:     def functionHandler(name, block)
127:       @functionHandlers.each do |handler|
128:         return handler if handler.function == name &&
129:                           handler.blockFunction == block
130:       end
131:       nil
132:     end
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/RichText.rb, line 96
 96:     def generateIntermediateFormat(sectionCounter = [ 0, 0, 0], tokenSet = nil)
 97:       rti = RichTextIntermediate.new(self)
 98:       # Copy the function handlers.
 99:       @functionHandlers.each do |h|
100:         rti.registerFunctionHandler(h)
101:       end
102: 
103:       # We'll setup the RichTextParser once and share it across all instances.
104:       if @@parser
105:         # We already have a RichTextParser that we can reuse.
106:         @@parser.reuse(@messageHandler, rti, sectionCounter, tokenSet)
107:       else
108:         # There is no RichTextParser yet, create one.
109:         @@parser = RichTextParser.new(@messageHandler, rti, sectionCounter,
110:                                       tokenSet)
111:       end
112: 
113:       @@parser.open(@inputText)
114:       # Parse the input text and convert it to the intermediate representation.
115:       return nil if (tree = @@parser.parse(:richtext)) == false
116: 
117:       # In case the result is empty, use an empty RichTextElement as result
118:       tree = RichTextElement.new(rti, :richtext, nil) unless tree
119:       tree.cleanUp
120:       rti.tree = tree
121:       rti
122:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.