Class: TaskJuggler::RichText
Overview
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.
Constant Summary collapse
- @@parser =
The Parser uses complex to setup data structures that are identical for all RichText instances. So, we’ll share them across the instances.
nil
Instance Attribute Summary collapse
-
#inputText ⇒ Object
readonly
Returns the value of attribute inputText.
Instance Method Summary collapse
-
#functionHandler(name, block) ⇒ Object
Return the RichTextFunctionHandler for the function name.
-
#generateIntermediateFormat(sectionCounter = [ 0, 0, 0], tokenSet = nil) ⇒ Object
Convert the @inputText into an abstract syntax tree that can then be converted into the various output formats.
-
#initialize(text, functionHandlers = []) ⇒ RichText
constructor
Create a rich text object by passing a String with markup elements to it.
Constructor Details
#initialize(text, functionHandlers = []) ⇒ RichText
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.
86 87 88 89 90 |
# File 'lib/taskjuggler/RichText.rb', line 86 def initialize(text, functionHandlers = []) # Keep a copy of the original text. @inputText = text @functionHandlers = functionHandlers end |
Instance Attribute Details
#inputText ⇒ Object (readonly)
Returns the value of attribute inputText.
75 76 77 |
# File 'lib/taskjuggler/RichText.rb', line 75 def inputText @inputText end |
Instance Method Details
#functionHandler(name, block) ⇒ Object
Return the RichTextFunctionHandler for the function name. block specifies whether we are looking for a block or inline function.
124 125 126 127 128 129 130 |
# 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 |
#generateIntermediateFormat(sectionCounter = [ 0, 0, 0], tokenSet = nil) ⇒ Object
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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# 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 |