HtmlUtils

HTML utility functions.

cpip.util.HtmlUtils.pathSplit(p)

Split a path into its components.

Parameters:p (str) – The path.
Returns:list([str]) – The split path.

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

Parameters:
  • theSrcPath (str) – The path of the original source, whis will be encoded with retHtmlFileName().
  • theLineNum (int) – An integer line number in the target.
Returns:

str – The link text.

cpip.util.HtmlUtils.retHtmlFileName(thePath)

Creates a unique, short, human readable file name base on the input file path. This is the file name plus a hash of the path.

Parameters:thePath (str) – The file path.
Returns:str – The name.
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.

Parameters:
  • theS (cpip.util.XmlWrite.XhtmlStream) – The XHTML stream.
  • theText (str) – The text to write, must be non-empty.
  • theSpan (str) – CSS class for the text.
Returns:

NoneType

cpip.util.HtmlUtils.writeDictTreeAsTable(theS, theDt, tableAttrs, includeKeyTail)

Writes a cpip.util.DictTree.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.

Parameters:
  • theS (cpip.util.XmlWrite.XhtmlStream) – HTML stream.
  • theDt (cpip.util.DictTree.DictTreeHtmlTable) – The table.
  • tableAttrs (dict({str : [str]})) – Table element attributes.
  • includeKeyTail (bool) – Include keys in the tail.
Returns:

NoneType

Raises:

StopIteration

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.

Parameters:
  • valueType (NoneType, str) – The type of the value: None, |'list' | 'set'
  • theS (cpip.util.XmlWrite.XhtmlStream) – The HTML stream.
  • theKvS (list([tuple([str, tuple([str, str, tuple([<class 'int'>, int, int])])]), tuple([str, tuple([str, str, tuple([int, int, int])])])]), list([tuple([str, tuple([str, str])])])) – A list of pairs (file_path, value).
  • tableStyle (str) – The CSS style used for the table.
  • fnTd (function) –

    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 (NoneType, function) –

    Optional 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>.
Returns:

NoneType

Raises:

StopIteration

cpip.util.HtmlUtils.writeHtmlFileAnchor(theS, theLineNum, theText='', theClass=None, theHref=None)

Writes an anchor.

Parameters:
  • theS (cpip.util.XmlWrite.XhtmlStream) – The XHTML stream.
  • theLineNum (int) – An integer line number in the target.
  • theText (str) – Navigation text.
  • theClass (str) – CSS class for the navigation text.
  • theHref (NoneType, str) – The HREF.
Returns:

NoneType

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

Parameters:
  • theS (cpip.util.XmlWrite.XhtmlStream) – The XHTML stream.
  • theSrcPath (str) – The path of the original source, whis will be encoded with retHtmlFileName().
  • theLineNum (int) – An integer line number in the target.
  • theText (str) – Navigation text.
  • theClass (NoneType, str) – Optional CSS class for the navigation text.
Returns:

NoneType