HtmlUtils

HTML utility functions.

cpip.util.HtmlUtils.pathSplit(p)

Split a path into its components.

Returns a string that is a link to a HTML file.

theSrcPath : str
The path of the original source, whis will be encoded with retHtmlFileName().
theLineNum : int
An integer line number in the target.
cpip.util.HtmlUtils.retHtmlFileName(thePath)

Creates a unique, short, human readable file name base on the input file path.

cpip.util.HtmlUtils.writeCharsAndSpan(theS, theText, theSpan)

Write theText to the stream theS. If theSpan is not None the text is enclosed in a <span class=theSpan> element.

theS
The XHTML stream.
theText : str
The text to write, must be non-empty.
theClass : str, optional
CSS class for the text.
cpip.util.HtmlUtils.writeDictTreeAsTable(theS, theDt, tableAttrs, includeKeyTail)

Writes a DictTreeHtmlTable object as a table, for example as a directory structure.

The key list in the DictTreeHtmlTable object is the path to the file i.e. os.path.abspath(p).split(os.sep) and the value is expected to be a pair of (link, nav_text) or None.

cpip.util.HtmlUtils.writeFileListAsTable(theS, theFileLinkS, tableAttrs, includeKeyTail)

Writes a list of file names as an HTML table looking like a directory structure. theFileLinkS is a list of pairs (file_path, href). The navigation text in the cell will be the basename of the file_path.

cpip.util.HtmlUtils.writeFileListTrippleAsTable(theS, theFileLinkS, tableAttrs, includeKeyTail)

Writes a list of file names as an HTML table looking like a directory structure. theFileLinkS is a list of triples (file_name, href, nav_text).

cpip.util.HtmlUtils.writeFilePathsAsTable(valueType, theS, theKvS, tableStyle, fnTd, fnTrTh=None)

Writes file paths as a table, for example as a directory structure.

valueType
The type of the value: None, |'list' | 'set'
theS
The HTML stream.
theKvS: list
A list of pairs (file_path, value).
tableStyle: str
The style used for the table.
fnTd

A callback function that is executed for a <td> element when there is a non-None value. This is called with the following arguments:

theS
The HTML stream.
attrs : dict
A map of attrs that include the rowspan/colspan for the <td>
k : list
The key as a list of path components.
v
The value given by the caller.
fnTrTh

Callback function for the header that will be called with the following arguments:

theS
The HTML stream.
pathDepth
Maximum depth of the largest path, this can be used for <th colspan=”...”>File path</th>.
cpip.util.HtmlUtils.writeHtmlFileAnchor(theS, theLineNum, theText='', theClass=None, theHref=None)

Writes an anchor.

theS
The XHTML stream.
theLineNum : int
An integer line number in the target.
theText : str, optional
Navigation text.
theClass : str, optional
CSS class for the navigation text.
theHref : str, optional
The href=.

Writes a link to another HTML file that represents source code.

theS
The XHTML stream.
theSrcPath : str
The path of the original source, this will be encoded with retHtmlFileName().
theLineNum : int
An integer line number in the target.
theText : str, optional
Navigation text.
theClass : obj, optional
CSS class for the navigation text.