コード例 #1
0
ファイル: markup.py プロジェクト: lcrees/webstring
    def render(self, info=None, format='html', encoding='unicode'):
        '''
        Render string from template.

        :keyword info: data to substitute into a document
        :keyword str format: HTML doctype to use for string
        :param str encoding: encoding type for return string
        '''
        # substitute any info into the document
        if info is not None:
            self.__imod__(info)
        tree = _copytree(self._tree)
        # use XHTML 1.0 doctype
        if format == 'html':
            # strip namespace prefix from HTML
            xhtml_to_html(tree)
            doc = htostring(tree, encoding=encoding, doctype=_html5)
        # use XHTML 1.1 doctype
        elif format == 'xhtml10':
            doc = htostring(
                tree, method='xml', encoding=encoding, doctype=_xhtml10,
            )
        # use HTML 5 doctype
        elif format == 'xhtml11':
            doc = htostring(
                tree, method='xml', encoding=encoding, doctype=_xhtml11,
            )
        return doc
コード例 #2
0
def tounicode(tree_or_node, **kwargs):
    kwargs['encoding'] = str
    return htostring(tree_or_node, **kwargs)
コード例 #3
0
ファイル: readability.py プロジェクト: 089git/calibre
def tounicode(tree_or_node, **kwargs):
    kwargs['encoding'] = unicode
    return htostring(tree_or_node, **kwargs)