Coverage for lino/utils/html2rst.py : 87%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# This document is part of the Lino test suite. To test only this # document, run:: # # $ python setup.py test -s tests.UtilsTests.test_html2rst
reStructuredText string.
If `stripped` is `True`, output will be more concise and optimized for console output, but possibly not valid reStructuredText.
Usage examples:
>>> from lino.utils.xmlgen.html import E >>> e = E.p("This is a ", E.b("first"), " test.") >>> print html2rst(e, True) This is a **first** test. <BLANKLINE>
>>> e = E.p(E.b("This")," is another test.") >>> print html2rst(e, True) **This** is another test. <BLANKLINE>
>>> e = E.p(E.b("This")," is ",E.em("another")," test.") >>> print html2rst(e, True) **This** is *another* test. <BLANKLINE>
>>> url = "http://example.com" >>> e = E.p(E.b("This")," is ",E.a("a link",href=url),".") >>> print html2rst(e, True) **This** is `a link <http://example.com>`__. <BLANKLINE>
>>> e = E.p("An empty bold text:",E.b("")) >>> print html2rst(e, True) An empty bold text: <BLANKLINE>
>>> e = E.ul(E.li("First"), E.li("Second")) >>> print html2rst(e, True) <BLANKLINE> First Second <BLANKLINE>
>>> e = E.h1("A header") >>> print html2rst(e, True) ======== A header ======== <BLANKLINE>
For images we render the ``alt`` text between brackets:
>>> e = E.img(src="http://example.com/images/1.jpg", alt="1") >>> print html2rst(e, True) [img 1]
If there is no ``alt`` text, render the content of ``src``:
>>> e = E.img(src="http://example.com/images/1.jpg") >>> print html2rst(e, True) [img http://example.com/images/1.jpg]
"""
"""The html2rst function.""" #~ print "20120613 html2odftext()", e.tag, e.text rst += '\n\n'
if stripped: rst += '\n' else: rst += ' |br| \n'
else: rst += '\n\n' else: rst = '\n\n' + rst + '\n\n' else: rst = '' else: else: raise Exception("20150723 %s" % e.tag)
# def html2rst(e): # return _html2rst(e).strip()
"""\ A table containing elementtree HTML:
.. complextable:: :header:
Code <NEXTCELL> Result <NEXTROW>
>>> from lino.utils.xmlgen.html import E >>> headers = [E.p("A ", E.b("formatted"), " header"), "A plain header"] >>> rows = [[1,2], [3,4]] >>> print RstTable(headers).to_rst(rows) ======================== ================ A **formatted** header A plain header ------------------------ ---------------- 1 2 3 4 ======================== ================ <BLANKLINE>
<NEXTCELL>
======================== ================ A **formatted** header A plain header ------------------------ ---------------- 1 2 3 4 ======================== ================
"""
|