WhakerPy 0.8

https://sourceforge.net/projects/whakerpy/

Module whakerpy.htmlmaker

Class HTMLComment

Description

Represent a comment element.

The comment tag does not support any standard attributes.

Constructor

Create a comment node.

Parameters
  • parent: (str) Identifier of the parent node
  • content: (str) The comment message
View Source
def __init__(self, parent: str, content: str=' --- '):
    """Create a comment node.

    :param parent: (str) Identifier of the parent node
    :param content: (str) The comment message

    """
    super(HTMLComment, self).__init__(parent, str(uuid.uuid1()))
    self._value = str(content)

Public functions

serialize

Serialize the comment into HTML.

Parameters
  • nbs: (int) Number of spaces for the indentation
Returns
  • (str)
View Source
def serialize(self, nbs: int=4) -> str:
    """Serialize the comment into HTML.

        :param nbs: (int) Number of spaces for the indentation
        :return: (str)

        """
    indent = ' ' * nbs
    html = '\n'
    html += indent + '<!-- '
    r = (70 - len(self._value)) // 2
    if r > 0:
        html += '-' * r
    html += ' ' + self._value + ' '
    if r > 0:
        html += '-' * r
    html += ' -->\n\n'
    return html