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.
[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
Public Class Methods
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 86 def initialize(text, functionHandlers = []) # Keep a copy of the original text. @inputText = text @functionHandlers = functionHandlers end
Public Instance Methods
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 124 def functionHandler(name, block) @functionHandlers.each do |handler| return handler if handler.function == name && handler.blockFunction == block end nil end
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 95 def generateIntermediateFormat(sectionCounter = [ 0, 0, 0], tokenSet = nil) rti = RichTextIntermediate.new(self) # Copy the function handlers. @functionHandlers.each do |h| rti.registerFunctionHandler(h) end # 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) else # There is no RichTextParser yet, create one. @@parser = RichTextParser.new(rti, sectionCounter, tokenSet) end @@parser.open(@inputText) # 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 = RichTextElement.new(rti, :richtext, nil) unless tree tree.cleanUp rti.tree = tree rti end