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


Python base.dedent函数代码示例

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


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

示例1: test_convert_markdown

    def test_convert_markdown(self):
        """
        Ensure that basic Markdown -> HTML and TOC works.
        """

        html, toc, meta = build.convert_markdown(dedent("""
            page_title: custom title

            # Heading 1

            This is some text.

            # Heading 2

            And some more text.
        """))

        expected_html = dedent("""
            <h1 id="heading-1">Heading 1</h1>
            <p>This is some text.</p>
            <h1 id="heading-2">Heading 2</h1>
            <p>And some more text.</p>
        """)

        expected_toc = dedent("""
            Heading 1 - #heading-1
            Heading 2 - #heading-2
        """)

        expected_meta = {'page_title': ['custom title']}

        self.assertEqual(html.strip(), expected_html)
        self.assertEqual(str(toc).strip(), expected_toc)
        self.assertEqual(meta, expected_meta)
开发者ID:chaabni,项目名称:mkdocs,代码行数:34,代码来源:build_tests.py

示例2: test_markdown_table_extension

    def test_markdown_table_extension(self):
        """
        Ensure that the table extension is supported.
        """

        html, toc, meta = build.convert_markdown(dedent("""
        First Header   | Second Header
        -------------- | --------------
        Content Cell 1 | Content Cell 2
        Content Cell 3 | Content Cell 4
        """))

        expected_html = dedent("""
        <table>
        <thead>
        <tr>
        <th>First Header</th>
        <th>Second Header</th>
        </tr>
        </thead>
        <tbody>
        <tr>
        <td>Content Cell 1</td>
        <td>Content Cell 2</td>
        </tr>
        <tr>
        <td>Content Cell 3</td>
        <td>Content Cell 4</td>
        </tr>
        </tbody>
        </table>
        """)

        self.assertEqual(html.strip(), expected_html)
开发者ID:chaabni,项目名称:mkdocs,代码行数:34,代码来源:build_tests.py

示例3: test_indented_toc_html

 def test_indented_toc_html(self):
     md = dedent("""
     # Heading 1
     ## <code>Heading</code> 2
     ## Heading 3
     """)
     expected = dedent("""
     Heading 1 - #heading-1
         Heading 2 - #heading-2
         Heading 3 - #heading-3
     """)
     toc = self.markdown_to_toc(md)
     self.assertEqual(str(toc).strip(), expected)
开发者ID:Argoday,项目名称:mkdocs,代码行数:13,代码来源:toc_tests.py

示例4: test_flat_h2_toc

 def test_flat_h2_toc(self):
     md = dedent("""
     ## Heading 1
     ## Heading 2
     ## Heading 3
     """)
     expected = dedent("""
     Heading 1 - #heading-1
     Heading 2 - #heading-2
     Heading 3 - #heading-3
     """)
     toc = self.markdown_to_toc(md)
     self.assertEqual(str(toc).strip(), expected)
开发者ID:Argoday,项目名称:mkdocs,代码行数:13,代码来源:toc_tests.py

示例5: test_flat_toc

 def test_flat_toc(self):
     md = dedent("""
     # Heading 1
     # Heading 2
     # Heading 3
     """)
     expected = dedent("""
     Heading 1 - #heading-1
     Heading 2 - #heading-2
     Heading 3 - #heading-3
     """)
     toc = get_toc(get_markdown_toc(md))
     self.assertEqual(str(toc).strip(), expected)
     self.assertEqual(len(toc), 3)
开发者ID:mkdocs,项目名称:mkdocs,代码行数:14,代码来源:toc_tests.py

示例6: test_entityref

 def test_entityref(self):
     md = dedent("""
     # Heading & 1
     ## Heading > 2
     ### Heading < 3
     """)
     expected = dedent("""
     Heading &amp; 1 - #heading-1
         Heading &gt; 2 - #heading-2
             Heading &lt; 3 - #heading-3
     """)
     toc = get_toc(get_markdown_toc(md))
     self.assertEqual(str(toc).strip(), expected)
     self.assertEqual(len(toc), 1)
开发者ID:mkdocs,项目名称:mkdocs,代码行数:14,代码来源:toc_tests.py

示例7: test_markdown_fenced_code_extension

    def test_markdown_fenced_code_extension(self):
        """
        Ensure that the fenced code extension is supported.
        """
        html, toc, meta = build.convert_markdown(dedent("""
        ```
        print 'foo'
        ```
        """), load_config())

        expected_html = dedent("""
        <pre><code>print 'foo'\n</code></pre>
        """)

        self.assertEqual(html.strip(), expected_html)
开发者ID:RussellTaylor83,项目名称:mkdocs,代码行数:15,代码来源:build_tests.py

示例8: test_html_toc

 def test_html_toc(self):
     html = dedent("""
     <div class="toc">
     <ul>
     <li><a href="#foo">Heading 1</a></li>
     <li><a href="#bar">Heading 2</a></li>
     </ul>
     </div>
     """)
     expected = dedent("""
     Heading 1 - #foo
     Heading 2 - #bar
     """)
     toc = get_toc(html)
     self.assertEqual(str(toc).strip(), expected)
     self.assertEqual(len(toc), 2)
开发者ID:mkdocs,项目名称:mkdocs,代码行数:16,代码来源:toc_tests.py

示例9: test_yaml_load

    def test_yaml_load(self):
        try:
            from collections import OrderedDict
        except ImportError:
            # Don't test if can't import OrderdDict
            # Exception can be removed when Py26 support is removed
            return

        yaml_text = dedent('''
            test:
                key1: 1
                key2: 2
                key3: 3
                key4: 4
                key5: 5
                key5: 6
                key3: 7
        ''')

        self.assertEqual(
            utils.yaml_load(yaml_text),
            OrderedDict([('test', OrderedDict([('key1', 1), ('key2', 2),
                                               ('key3', 7), ('key4', 4),
                                               ('key5', 6)]))])
        )
开发者ID:fedelibre,项目名称:mkdocs,代码行数:25,代码来源:utils_tests.py

示例10: test_copy_theme_files

    def test_copy_theme_files(self):
        docs_dir = tempfile.mkdtemp()
        site_dir = tempfile.mkdtemp()
        try:
            # Create a non-empty markdown file.
            f = open(os.path.join(docs_dir, 'index.md'), 'w')
            f.write(dedent("""
                page_title: custom title

                # Heading 1

                This is some text.
            """))
            f.close()

            cfg = load_config({
                'docs_dir': docs_dir,
                'site_dir': site_dir
            })
            build.build(cfg)

            # Verify only theme media are copied, not templates or Python files.
            self.assertTrue(os.path.isfile(os.path.join(site_dir, 'index.html')))
            self.assertTrue(os.path.isdir(os.path.join(site_dir, 'js')))
            self.assertTrue(os.path.isdir(os.path.join(site_dir, 'css')))
            self.assertTrue(os.path.isdir(os.path.join(site_dir, 'img')))
            self.assertFalse(os.path.isfile(os.path.join(site_dir, '__init__.py')))
            self.assertFalse(os.path.isfile(os.path.join(site_dir, '__init__.pyc')))
            self.assertFalse(os.path.isfile(os.path.join(site_dir, 'base.html')))
            self.assertFalse(os.path.isfile(os.path.join(site_dir, 'content.html')))
            self.assertFalse(os.path.isfile(os.path.join(site_dir, 'nav.html')))
        finally:
            shutil.rmtree(docs_dir)
            shutil.rmtree(site_dir)
开发者ID:10389030,项目名称:mkdocs,代码行数:34,代码来源:build_tests.py

示例11: test_config_option

    def test_config_option(self):
        """
        Users can explicitly set the config file using the '--config' option.
        Allows users to specify a config other than the default `mkdocs.yml`.
        """
        expected_result = {
            'site_name': 'Example',
            'pages': [
                {'Introduction': 'index.md'}
            ],
        }
        file_contents = dedent("""
        site_name: Example
        pages:
        - 'Introduction': 'index.md'
        """)
        with TemporaryDirectory() as temp_path:
            os.mkdir(os.path.join(temp_path, 'docs'))
            config_path = os.path.join(temp_path, 'mkdocs.yml')
            config_file = open(config_path, 'w')

            config_file.write(ensure_utf(file_contents))
            config_file.flush()
            config_file.close()

            result = config.load_config(config_file=config_file.name)
            self.assertEqual(result['site_name'], expected_result['site_name'])
            self.assertEqual(result['pages'], expected_result['pages'])
开发者ID:mkdocs,项目名称:mkdocs,代码行数:28,代码来源:config_tests.py

示例12: test_find_toc_by_id

    def test_find_toc_by_id(self):
        """
        Test finding the relevant TOC item by the tag ID.
        """

        index = search.SearchIndex()

        md = dedent(
            """
        # Heading 1
        ## Heading 2
        ### Heading 3
        """
        )
        toc = markdown_to_toc(md)

        toc_item = index._find_toc_by_id(toc, "heading-1")
        self.assertEqual(toc_item.url, "#heading-1")
        self.assertEqual(toc_item.title, "Heading 1")

        toc_item2 = index._find_toc_by_id(toc, "heading-2")
        self.assertEqual(toc_item2.url, "#heading-2")
        self.assertEqual(toc_item2.title, "Heading 2")

        toc_item3 = index._find_toc_by_id(toc, "heading-3")
        self.assertEqual(toc_item3.url, "#heading-3")
        self.assertEqual(toc_item3.title, "Heading 3")
开发者ID:adamdubiel,项目名称:mkdocs,代码行数:27,代码来源:search_tests.py

示例13: test_config_option

    def test_config_option(self):
        """
        Users can explicitly set the config file using the '--config' option.
        Allows users to specify a config other than the default `mkdocs.yml`.
        """
        expected_result = {
            'site_name': 'Example',
            'pages': [
                {'Introduction': 'index.md'}
            ],
        }
        file_contents = dedent("""
        site_name: Example
        pages:
        - ['index.md', 'Introduction']
        """)
        config_file = tempfile.NamedTemporaryFile('w', delete=False)
        try:
            config_file.write(ensure_utf(file_contents))
            config_file.flush()
            config_file.close()

            result = config.load_config(config_file=config_file.name)
            self.assertEqual(result['site_name'], expected_result['site_name'])
            self.assertEqual(result['pages'], expected_result['pages'])
        finally:
            os.remove(config_file.name)
开发者ID:geoconnections,项目名称:mkdocs,代码行数:27,代码来源:config_tests.py

示例14: test_mm_meta_data

    def test_mm_meta_data(self):
        doc = dedent(
            """
            Title: Foo Bar
            Date: 2018-07-10
            Summary: Line one
                Line two
            Tags: foo
            Tags: bar

            Doc body
            """
        )
        self.assertEqual(
            utils.meta.get_data(doc),
            (
                "Doc body",
                {
                    'title': 'Foo Bar',
                    'date': '2018-07-10',
                    'summary': 'Line one Line two',
                    'tags': 'foo bar'
                }
            )
        )
开发者ID:mkdocs,项目名称:mkdocs,代码行数:25,代码来源:utils_tests.py

示例15: test_no_meta_data

 def test_no_meta_data(self):
     doc = dedent(
         """
         Doc body
         """
     )
     self.assertEqual(utils.meta.get_data(doc), (doc, {}))
开发者ID:mkdocs,项目名称:mkdocs,代码行数:7,代码来源:utils_tests.py


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