Пример #1
0
def include(url, default=''):
    """Do a client-side include of ``url``, defaulting to ``default```
        >>> include("/foo","hello")
        '<hx:include src="/foo">hello</hx:include>'
    """
    
    if callable(url):
        url = url()
    else:
        url = html_escape(url)

    return content_tag("hx:include", content=default, src=url)
Пример #2
0
def include(url, default=''):
    """Do a client-side include of ``url``, defaulting to ``default```
        >>> hinclude.include("/foo","hello")
        '<hx:include src="/foo">hello</hx:include>'
    """
    
    if callable(url):
        url = url()
    else:
        url = html_escape(url)

    return content_tag("hx:include", content=default, src=url)
Пример #3
0
def simple_format(text):
    """
    Returns ``text`` transformed into HTML using very simple formatting rules
    
    Surrounds paragraphs with ``<p>`` tags, and converts line breaks into ``<br />``
    Two consecutive newlines(``\\n\\n``) are considered as a paragraph, one newline (``\\n``) is
    considered a linebreak, three or more consecutive newlines are turned into two newlines.
    """
    text = re.sub(r'(\r\n|\n|\r)', r'\n', text)
    text = re.sub(r'\n\n+', r'\n\n', text)
    text = re.sub(r'(\n\n)', r'</p>\1<p>', text)
    text = re.sub(r'([^\n])(\n)([^\n])', r'\1\2<br />\3', text)
    text = content_tag("p", text).replace('</p><p></p>', '</p>')
    text = re.sub(r'</p><p>', r'</p>\n<p>', text)
    return text
Пример #4
0
def simple_format(text):
    """
    Returns ``text`` transformed into HTML using very simple formatting rules
    
    Surrounds paragraphs with ``<p>`` tags, and converts line breaks into ``<br />``
    Two consecutive newlines(``\\n\\n``) are considered as a paragraph, one newline (``\\n``) is
    considered a linebreak, three or more consecutive newlines are turned into two newlines.
    """
    text = re.sub(r'(\r\n|\n|\r)', r'\n', text)
    text = re.sub(r'\n\n+', r'\n\n', text)
    text = re.sub(r'(\n\n)', r'</p>\1<p>', text)
    text = re.sub(r'([^\n])(\n)([^\n])', r'\1\2<br />\3', text)
    text = content_tag("p", text).replace('</p><p></p>', '</p>')
    text = re.sub(r'</p><p>', r'</p>\n<p>', text)
    return text
Пример #5
0
def simple_format(text):
    """
    Returns ``text`` transformed into HTML using very simple formatting rules
    
    Two or more consecutive newlines(``\\n\\n``) are considered as a paragraph
    and wrapped in ``<p>`` tags. One newline (``\\n``) is considered a
    linebreak and a ``<br />`` tag is appended. This method does not remove the
    newlines from the text.
    """
    if text is None:
        text = ''
    text = re.sub(r'(\r\n|\n|\r)', r'\n', text)
    text = re.sub(r'\n\n+', r'\n\n', text)
    text = re.sub(r'(\n\n)', r'</p>\1<p>', text)
    text = re.sub(r'([^\n])(\n)(?=[^\n])', r'\1\2<br />', text)
    text = content_tag("p", text).replace('</p><p></p>', '</p>')
    text = re.sub(r'</p><p>', r'</p>\n<p>', text)
    return text
Пример #6
0
def simple_format(text):
    """
    Returns ``text`` transformed into HTML using very simple formatting rules
    
    Two or more consecutive newlines(``\\n\\n``) are considered as a paragraph
    and wrapped in ``<p>`` tags. One newline (``\\n``) is considered a
    linebreak and a ``<br />`` tag is appended. This method does not remove the
    newlines from the text.
    """
    if text is None:
        text = ''
    text = re.sub(r'(\r\n|\n|\r)', r'\n', text)
    text = re.sub(r'\n\n+', r'\n\n', text)
    text = re.sub(r'(\n\n)', r'</p>\1<p>', text)
    text = re.sub(r'([^\n])(\n)(?=[^\n])', r'\1\2<br />', text)
    text = content_tag("p", text).replace('</p><p></p>', '</p>')
    text = re.sub(r'</p><p>', r'</p>\n<p>', text)
    return text