Esempio n. 1
0
def html_to_rst(html, indent=0, indent_first=False):
    """
    Use bcdoc to convert html to rst.

    :type html: string
    :param html: Input HTML to be converted
    :type indent: int
    :param indent: Number of spaces to indent each line
    :type indent_first: boolean
    :param indent_first: Whether to indent the first line
    :rtype: string
    """
    doc = ReSTDocument()

    # TODO: Remove me, temp workaround to fix doc building
    # because of smart quotes that aren't currently supported.
    html = html.replace(u'\u2019', "'")
    html = html.replace(u'\u2014', '-')

    doc.include_doc_string(html)
    rst = doc.getvalue().decode('utf-8')

    if indent:
        rst = '\n'.join([(' ' * indent) + line for line in rst.splitlines()])

        if not indent_first:
            rst = rst.strip()

    return rst
Esempio n. 2
0
def html_to_rst(html, indent=0, indent_first=False):
    """
    Use bcdoc to convert html to rst.

    :type html: string
    :param html: Input HTML to be converted
    :type indent: int
    :param indent: Number of spaces to indent each line
    :type indent_first: boolean
    :param indent_first: Whether to indent the first line
    :rtype: string
    """
    doc = ReSTDocument()

    # TODO: Remove me, temp workaround to fix doc building
    # because of smart quotes that aren't currently supported.
    html = html.replace(u'\u2019', "'")
    html = html.replace(u'\u2014', '-')

    doc.include_doc_string(html)
    rst = doc.getvalue().decode('utf-8')

    if indent:
        rst = '\n'.join([(' ' * indent) + line for line in rst.splitlines()])

        if not indent_first:
            rst = rst.strip()

    return rst
Esempio n. 3
0
File: mangle.py Progetto: Axik/boto3
def html_to_rst(html):
    """
    Converts the service HTML docs to reStructured Text, for use in docstrings.

    :param html: The raw HTML to convert
    :type html: string

    :returns: A reStructured Text formatted version of the text
    :rtype: string
    """
    doc = ReSTDocument()
    doc.include_doc_string(html)
    raw_doc = doc.getvalue()
    return raw_doc.decode('utf-8')
Esempio n. 4
0
def html_to_rst(html, indent=0, indentFirst=False):
    """
    Use bcdoc to convert html to rst.

    :type html: string
    :param html: Input HTML to be converted
    :type indent: int
    :param indent: Number of spaces to indent each line
    :type indentFirst: boolean
    :param indentFirst: Whether to indent the first line
    :rtype: string
    """
    doc = ReSTDocument()
    doc.include_doc_string(html)
    rst = doc.getvalue().decode('utf-8')

    if indent:
        rst = '\n'.join([(' ' * indent) + line for line in rst.splitlines()])

        if not indentFirst:
            rst = rst.strip()

    return rst
Esempio n. 5
0
 def test_remove_doc_string(self):
     doc = ReSTDocument()
     doc.writeln('foo')
     doc.include_doc_string('<p>this is a <code>test</code></p>')
     doc.remove_last_doc_string()
     self.assertEqual(doc.getvalue(), six.b('foo\n'))
Esempio n. 6
0
 def test_include_doc_string(self):
     doc = ReSTDocument()
     doc.include_doc_string('<p>this is a <code>test</code></p>')
     self.assertEqual(doc.getvalue(), six.b('\n\nthis is a ``test`` \n\n'))
Esempio n. 7
0
 def test_remove_doc_string(self):
     doc = ReSTDocument()
     doc.writeln('foo')
     doc.include_doc_string('<p>this is a <code>test</code></p>')
     doc.remove_last_doc_string()
     self.assertEqual(doc.getvalue(), six.b('foo\n'))
Esempio n. 8
0
 def test_include_doc_string(self):
     doc = ReSTDocument()
     doc.include_doc_string('<p>this is a <code>test</code></p>')
     self.assertEqual(doc.getvalue(), six.b('\n\nthis is a ``test`` \n\n'))