bcftbx.htmlpagewriter
¶
htmlpagewriter
Provides HTMLPageWriter class which provides a simple programmatic interface for generating HTML files.
-
class
bcftbx.htmlpagewriter.
HTMLPageWriter
(title='')¶ Generic HTML generation class
HTMLPageWriter provides basic operations for writing HTML files.
Example usage:
>>> p = HTMLPageWriter("Example page") >>> p.add("This is some text") >>> p.write("example.html")
-
add
(content)¶ Add content to page body
Note that the supplied content is added to the HTML document as-is; no escaping is performed so the content can include arbitrary HTML tags. Note also that no validation is performed.
Parameters: content – text to add to the HTML document body
-
addCSSRule
(css_rule)¶ Add CSS rule
Defines a CSS rule that will be inlined into a “style” tag in the HTML head when the document is written out.
The rule text is added as-is, e.g.:
>>> p = HTMLPageWriter("Example page") >>> p.addCSSRule("body { color: blue; }")
No checking or validation is performed.
Parameters: css_rule – text defining CSS rule
-
addJavaScript
(javascript)¶ Add JavaScript
Defines a line of Javascript code that will be inlined into a “script” tag in the HTML head when the document is written out.
The code is added as-is, no checking or validation is performed.
Parameters: javascript – Javascript code
-
write
(filen=None, fp=None)¶ Write the HTML document to file
Generates a HTML document based on the content, styles etc that have been defined by calls to the object’s methods.
Can supply either a filename or a file-like object opened for writing.
Parameters: - filen – name of the file to write the document to.
- fp – file-like object opened for writing; if this is supplied then filen argument will be ignored even if it is not None.
-