The wt.textblock
module provides a
TemplateCode
sub-class which
helps with dynamically creating paragraphs of text.
This class is used for creating paragraphs of HTML out of a text string.
Double-newlines in the string (i.e. blank lines) are treated as paragraph
separators. Single newlines are converted to <br>
tags.
Newlines of the form \n
or \r\n
are supported.
Example:
<!--wt:body-->
<p>$$=paragraph$$</p>
<!--wt:/body-->
import jon.wt.textblock as textblock
class body(textblock.TextBlock):
def text(self):
return self.outer.article["body"]
Note the use of the =
literal encoding specifier, because
the output is raw HTML (including <br>
tags).
paragraph
This variable is set to the HTML code for each paragraph in turn by the
main()
method.
text(self)
Returns: string
This method may be overridden by subclasses. It returns a string containing the text data to be turned into HTML paragraphs. The default implementation just returns the empty string.
main(self, template)
template
: string
This method may be overridden by subclasses. It calls
text()
to fetch the text data
and splits it into paragraphs. Each paragraph in turn is converted to HTML,
placed into the paragraph
attribute, and process()
called.
$Id: wt-textblock.html,v 0416d65875b7 2014/03/05 17:37:06 jon $