当前位置: 首页>>代码示例>>Python>>正文


Python helpgen.rst2html函数代码示例

本文整理汇总了Python中pyquickhelper.helpgen.rst2html函数的典型用法代码示例。如果您正苦于以下问题:Python rst2html函数的具体用法?Python rst2html怎么用?Python rst2html使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rst2html函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_rst2html_png

    def test_rst2html_png(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            # It requires latex.
            return

        temp = get_temp_folder(__file__, "temp_rst2html_png")
        rst = os.path.join(os.path.abspath(
            os.path.dirname(__file__)), "data", "hermionne.rst")
        with open(rst, "r", encoding="utf-8") as f:
            content = f.read()

        text = rst2html(content)

        ji = os.path.join(temp, "out.html")
        with open(ji, "w", encoding="utf-8") as f:
            f.write(text)
        text2 = rst2html(content, layout="sphinx")
        ji = os.path.join(temp, "out_sphinx.html")
        with open(ji, "w", encoding="utf-8") as f:
            f.write(text)
        self.assertTrue(len(text2) > len(text))
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:26,代码来源:test_rst2html.py

示例2: test_rst_only

    def test_rst_only(self):
        from docutils import nodes as skip_

        content = """
                    test a directive
                    ================

                    .. only:: html

                        only for html

                    .. only:: rst

                        only for rst

                    """.replace("                    ", "")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        tives = [("cmdref", CmdRef, cmdref_node,
                  visit_cmdref_node, depart_cmdref_node)]

        text = rst2html(content,  # fLOG=fLOG,
                        writer="rst", keep_warnings=True,
                        directives=tives, extlinks={'issue': ('http://%s', '_issue_')})

        temp = get_temp_folder(__file__, "temp_only")
        with open(os.path.join(temp, "out_cmdref.rst"), "w", encoding="utf8") as f:
            f.write(text)

        t1 = "only for rst"
        if t1 not in text:
            raise Exception(text)
        t1 = "only for html"
        if t1 in text:
            raise Exception(text)

        text = rst2html(content,  # fLOG=fLOG,
                        writer="html", keep_warnings=True,
                        directives=tives, extlinks={'issue': ('http://%s', '_issue_')})

        temp = get_temp_folder(__file__, "temp_only")
        with open(os.path.join(temp, "out_cmdref.rst"), "w", encoding="utf8") as f:
            f.write(text)

        t1 = "only for rst"
        if t1 in text:
            raise Exception(text)
        t1 = "only for html"
        if t1 not in text:
            raise Exception(text)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:51,代码来源:test_rst_builder.py

示例3: test_blogpost_agg

    def test_blogpost_agg(self):

        from docutils import nodes as skip_

        content = """
                    test a directive
                    ================

                    before

                    .. blogpostagg::
                        :title: first blog post
                        :keywords: keyw
                        :categories: cat1
                        :date: 2018-03-24

                        this code shoud appear___.

                        this one not sure.

                    after
                    """.replace("                    ", "")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        tives = [("blogpostagg", BlogPostDirectiveAgg, blogpostagg_node,
                  visit_blogpostagg_node, depart_blogpostagg_node)]

        text = rst2html(content,  # fLOG=fLOG,
                        layout="sphinx", writer="html", keep_warnings=True,
                        directives=tives, extlinks={'issue': ('http://%s', '_issue_')})

        temp = get_temp_folder(__file__, "temp_blogagg_ext")
        with open(os.path.join(temp, "out_blog.html"), "w", encoding="utf8") as f:
            f.write(text)

        self.assertIn('<font size="5">2018-03-24</font></p>', text)

        text = rst2html(content,  # fLOG=fLOG,
                        layout="sphinx", writer="rst", keep_warnings=True,
                        directives=tives, extlinks={'issue': ('http://%s', '_issue_')})

        with open(os.path.join(temp, "out_blog.rst"), "w", encoding="utf8") as f:
            f.write(text)

        self.assertIn('this code shoud appear___', text)
        self.assertIn('==========', text)
        self.assertIn(':bigger:`2018-03-24`', text)
        self.assertIn('after', text)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:49,代码来源:test_blog_extension.py

示例4: test_docstyle

    def test_docstyle(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        extensions = get_default_standard_extensions() + get_default_extensions()
        extensions = [_ for _ in extensions if "matplotlib" not in _ and
                      "images" not in _ and "IPython" not in _ and
                      "nbsphinx" not in _ and "jupyter" not in _ and
                      "jsdemo" not in _ and
                      "inheritance_diagram" not in _]
        external_docnames = [
            "_modules/src/pyquickhelper/helpgen/_fake_function_to_documentation"]
        funcs = [None, f1, f2, f3, f4, f5, f6]

        exps = [" * **a** -- parameter a",
                ":param      a:",
                ":param a:",
                "a: parameter a"]

        for i in range(1, 7):
            content = ".. autofunction:: pyquickhelper.helpgen._fake_function_to_documentation.f{0}".format(
                i)
            text = rst2html(content,  # fLOG=fLOG,
                            writer="rst", keep_warnings=True,
                            layout="sphinx", extensions=extensions,
                            external_docnames=external_docnames)
            filt = list(filter(lambda s: s in text, exps))
            if len(filt) == 0:
                doc = funcs[i].__doc__
                rows = doc.split("\n")
                conv = private_migrating_doxygen_doc(rows, 0, "f%d" % i)
                content = "\n".join(conv)
                text2 = rst2html(content,  # fLOG=fLOG,
                                 writer="rst", keep_warnings=True,
                                 layout="sphinx", extensions=extensions,
                                 external_docnames=external_docnames)
                filt = list(filter(lambda s: s in text2, exps))
                if len(filt) == 0:
                    fLOG("\n---- ORIGINAL", i, "\n", funcs[i].__doc__,
                         "\n---- RESULT", i, "\n", text,
                         "\n**** CONVERTED\n", content,
                         "\n**** FINAL", i, "\n", text2,
                         "\n*************** END")
                else:
                    rep = text2.strip("\n ")
                    if not rep.startswith(".."):
                        raise Exception("\n" + text2)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:49,代码来源:test_style_doc.py

示例5: test_rst_image_target2

    def test_rst_image_target2(self):

        temp = get_temp_folder(__file__, "temp_rst_image_target2")
        root = os.path.abspath(os.path.dirname(__file__))
        img1 = os.path.join(root, "data", "image", "im.png")
        content = """
                    .. image:: {0}
                        :target: https://github.com/sdpython.png
                        :width: 200
                        :alt: alternative1
                    """.replace("                    ", "").format(img1).replace("\\", "/")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        text = rst2html(content,  # fLOG=fLOG,
                        writer="rst", keep_warnings=False, layout='sphinx',
                        extlinks={'issue': ('http://%s', '_issue_')},
                        rst_image_dest=temp)

        text = text.replace("\r", "")
        self.assertNotIn('data/image/im.png', text)
        self.assertIn('   :alt: alternative1', text)
        self.assertIn('   :width: 200', text)
        with open(os.path.join(temp, "out_image.rst"), "w", encoding="utf8") as f:
            f.write(text)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:25,代码来源:test_rst_builder.py

示例6: test_autosignature_class_onemethod2

    def test_autosignature_class_onemethod2(self):
        this = os.path.abspath(os.path.dirname(__file__))
        data = os.path.join(this, "datadoc")
        with sys_path_append(data):

            newstring = ["AAAAAAAAAAAAAAAA",
                         "",
                         ".. autosignature:: exdocassert2.onefunction",
                         "",
                         "CCCCCCCCCCCCCCCC"]
            newstring = "\n".join(newstring)
            htmls = rst2html(newstring, layout="sphinx_body")

        self.assertIn("CCCCCCCCCCCCCCCC", htmls)

        html = htmls.split("CCCCCCCCCCCCCCCC")
        if "onefunction" not in html[0]:
            raise Exception(html[0])
        if "<strong>a</strong>" in html[0]:
            raise Exception(html[0])
        if ":param a:" in html[0]:
            raise Exception(html[0])
        if "`" in html[0]:
            raise Exception(html[0])
        if "if a and b have different types" in html[0]:
            raise Exception(html[0])
        if "Return the addition of" not in html[0]:
            raise Exception(html[0])
        if "Second line should be aligned." not in html[0]:
            raise Exception(html[0])
        if "<p>Return the addition of" not in html[0]:
            raise Exception(html[0])
        if "should be aligned.</p>" not in html[0]:
            raise Exception(html[0])
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:34,代码来源:test_autosignature.py

示例7: test_rst2html_autoclass

    def test_rst2html_autoclass(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        if is_travis_or_appveyor() in ('travis', 'appveyor'):
            # It requires latex.
            return

        if sys.version_info[:2] <= (2, 7):
            # i don't want to fix it for Python 2.7
            return

        content = """
                    ======
                    title1
                    ======

                    .. autoclass:: pyquickhelper.sphinxext.sphinx_runpython_extension.RunPythonDirective
                        :members:

        """.replace("                    ", "")

        temp = get_temp_folder(__file__, "temp_rst2html_autoclass")
        text = rst2html(content, outdir=temp, layout="sphinx", writer="rst")
        ji = os.path.join(temp, "out.rst")
        with open(ji, "w", encoding="utf-8") as f:
            f.write(text)
        self.assertIn("* ``:indent:<int>`` to indent the output", text)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:30,代码来源:test_rst2html_toc.py

示例8: test_runpython_numpy

    def test_runpython_numpy(self):
        """
        this test also test the extension runpython
        """
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        from docutils import nodes

        if "enable_disabled_documented_pieces_of_code" in sys.__dict__:
            raise Exception("this case shoud not be")

        content = """
                    test a directive
                    ================

                    .. runpythonthis::
                        :setsysvar:
                        :rst:
                        :showcode:
                        :numpy_precision: 2

                        import numpy
                        print(numpy.array([1.123456789, 1.987654321]))
                    """.replace("                    ", "")

        html = rst2html(content,  # fLOG=fLOG,
                        writer="rst", keep_warnings=True)
        if "[1.12 1.99]" not in html:
            raise Exception(html)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:32,代码来源:test_runpython_extension.py

示例9: test_md_image_target

    def test_md_image_target(self):

        temp = get_temp_folder(__file__, "temp_md_image_target")
        root = os.path.abspath(os.path.dirname(__file__))
        img1 = os.path.join(root, "data", "image", "im.png")
        content = """
                    .. image:: {0}
                        :target: https://github.com/sdpython
                        :width: 200
                        :alt: alternative1
                    """.replace("                    ", "").format(img1).replace("\\", "/")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        text = rst2html(content,  # fLOG=fLOG,
                        writer="md", keep_warnings=False, layout='sphinx',
                        extlinks={'issue': ('http://%s', '_issue_')},
                        md_image_dest=temp)

        text = text.replace("\r", "")
        self.assertIn('![alternative1]', text)
        self.assertIn('=200x', text)
        self.assertIn("![alternative1](5cf2985161e8ba56d893.png =200x)", text)
        self.assertExists(os.path.join(temp, '5cf2985161e8ba56d893.png'))
        with open(os.path.join(temp, "md_image.md"), "w", encoding="utf8") as f:
            f.write(text)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:26,代码来源:test_md_builder.py

示例10: test_md_title

    def test_md_title(self):
        from docutils import nodes as skip_

        content = """

                    title1
                    ======

                    title2
                    ======

                    title3
                    ++++++

                    title4
                    ******

                    """.replace("                    ", "")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        text = rst2html(content,  # fLOG=fLOG,
                        writer="md", keep_warnings=False, layout='sphinx',
                        extlinks={'issue': ('http://%s', '_issue_')})

        self.assertIn("# title1", text)
        self.assertIn("# title2", text)
        self.assertIn("## title3", text)
        self.assertIn("### title4", text)
        temp = get_temp_folder(__file__, "temp_md_title")
        with open(os.path.join(temp, "out_md_title.md"), "w", encoding="utf8") as f:
            f.write(text)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:32,代码来源:test_md_builder.py

示例11: test_autosignature_class_static_method

    def test_autosignature_class_static_method(self):
        this = os.path.abspath(os.path.dirname(__file__))
        data = os.path.join(this, "datadoc")
        with sys_path_append(data):

            obj = import_object("exsig.clex.static_method", "staticmethod")
            self.assertTrue(obj is not None)

            newstring = ["AAAAAAAAAAAAAAAA",
                         "",
                         ".. autosignature:: exsig.clex.static_method",
                         "",
                         "CCCCCCCCCCCCCCCC"]
            newstring = "\n".join(newstring)
            htmls = rst2html(newstring, layout="sphinx_body")

        self.assertIn("CCCCCCCCCCCCCCCC", htmls)

        html = htmls.split("CCCCCCCCCCCCCCCC")
        if "static_method" not in html[0]:
            raise Exception(html[0])
        if "<strong>a</strong>" in html[0]:
            raise Exception(html[0])
        if ":param a:" in html[0]:
            raise Exception(html[0])
        if "`" in html[0]:
            raise Exception(html[0])
        if "if a and b have different types" in html[0]:
            raise Exception(html[0])
        if "Return the static addition of" not in html[0]:
            raise Exception(html[0])
        if "<p>Return the static addition of" not in html[0]:
            raise Exception(html[0])
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:33,代码来源:test_autosignature.py

示例12: test_md_reference

    def test_md_reference(self):
        from docutils import nodes as skip_

        content = """
                    test a directive
                    ================

                    :py:class:`pyquickhelper.sphinxext.sphinx_md_builder.MdBuilder`

                    :py:class:`Renamed <pyquickhelper.sphinxext.sphinx_md_builder.MdBuilder>`
                    """.replace("                    ", "")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        tives = [("cmdref", CmdRef, cmdref_node,
                  visit_cmdref_node, depart_cmdref_node)]

        text = rst2html(content,  # fLOG=fLOG,
                        writer="md", keep_warnings=True, layout='sphinx',
                        directives=tives, extlinks={'issue': ('http://%s', '_issue_')})

        temp = get_temp_folder(__file__, "temp_only")
        with open(os.path.join(temp, "out_cmdref.md"), "w", encoding="utf8") as f:
            f.write(text)

        t1 = "pyquickhelper.sphinxext.sphinx_md_builder.MdBuilder"
        if t1 not in text:
            raise Exception(text)
        t1 = "[Renamed]("
        if t1 not in text:
            raise Exception(text)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:31,代码来源:test_md_builder.py

示例13: test_thumbnail

    def test_thumbnail(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        from docutils import nodes as skip_

        content = """
                    test a directive
                    ================

                    before

                    .. thumbnail:: http://www.xavierdupre.fr/app/pyquickhelper/helpsphinx/_static/project_ico.png
                        :width: 10
                        :height: 20
                        :download: 1

                    after

                    this code shoud appear
                    """.replace("                    ", "")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        logger2 = logging.getLogger("video")

        log_capture_string = StringIO()
        ch = logging.StreamHandler(log_capture_string)
        ch.setLevel(logging.DEBUG)
        logger2.addHandler(ch)
        with warnings.catch_warnings(record=True):
            html = rst2html(content,  # fLOG=fLOG,
                            writer="custom", keep_warnings=True,
                            directives=None)

        warns = log_capture_string.getvalue()
        if warns:
            raise Exception(warns)

        t1 = "this code shoud not appear"
        if t1 in html:
            raise Exception(html)

        t1 = "this code shoud appear"
        if t1 not in html:
            raise Exception(html)

        t1 = "_images"
        if t1 not in html:
            raise Exception(html)

        t1 = "linkedin"
        if t1 in html:
            raise Exception(html)

        temp = get_temp_folder(__file__, "temp_sphinx_thumbnail")
        with open(os.path.join(temp, "out_image.html"), "w", encoding="utf8") as f:
            f.write(html)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:60,代码来源:test_thumbnail_extension.py

示例14: test_parse_readme_cb

    def test_parse_readme_cb(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        fold = os.path.dirname(os.path.abspath(__file__))
        readme = os.path.join(fold, "data", "README.rst")
        fLOG(readme)
        assert os.path.exists(readme)
        with open(readme, "r", encoding="utf8") as f:
            content = f.read()
        r = parse_markdown(content)
        if "<p>.. _l-README:</p>" not in str(r):
            m = [ord(c) for c in content]
            m = ",".join(str(_) for _ in m[:20])
            raise Exception("IN\n{0}\nOUT:{1}".format(m, str(r)))

        ht = rst2html(content)
        # fLOG(ht)
        assert len(ht) > 0

        spl = content.split("\n")
        r = list(yield_sphinx_only_markup_for_pipy(spl))
        assert len(r) == len(spl)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:25,代码来源:test_markdown_helper.py

示例15: test_latex_image_overwrite

    def test_latex_image_overwrite(self):

        temp = get_temp_folder(__file__, "temp_latex_image_overwrite")
        root = os.path.abspath(os.path.dirname(__file__))
        img1 = os.path.join(root, "data", "image", "im.png")
        img2 = os.path.join(root, "data", "thumbnail", "im.png")
        img1 = img1[2:]
        img2 = img2[2:]
        content = """
                    .. image:: {0}
                        :width: 59
                        :alt: alternative1

                    * .. image:: {1}
                        :width: 59
                        :alt: alternative2
                    """.replace("                    ", "").format(img1, img2).replace("\\", "/")
        if sys.version_info[0] >= 3:
            content = content.replace('u"', '"')

        text = rst2html(content,  # fLOG=fLOG,
                        writer="elatex", keep_warnings=False, layout='sphinx',
                        extlinks={'issue': ('http://%s', '_issue_')},
                        md_image_dest=temp, override_image_directive=True)

        text = text.replace("\r", "")
        self.assertIn('sphinxincludegraphics', text)
        self.assertIn('=59', text)
        self.assertIn("png", text)
        with open(os.path.join(temp, "elatex_image.tex"), "w", encoding="utf8") as f:
            f.write(text)
开发者ID:sdpython,项目名称:pyquickhelper,代码行数:31,代码来源:test_latex_builder.py


注:本文中的pyquickhelper.helpgen.rst2html函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。