本文整理汇总了Python中mkdocs.tests.base.dedent函数的典型用法代码示例。如果您正苦于以下问题:Python dedent函数的具体用法?Python dedent怎么用?Python dedent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dedent函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 & 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), 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
示例16: test_indented_toc
def test_indented_toc(self):
pages = [
{'Home': 'index.md'},
{'API Guide': [
{'Running': 'api-guide/running.md'},
{'Testing': 'api-guide/testing.md'},
{'Debugging': 'api-guide/debugging.md'},
]},
{'About': [
{'Release notes': 'about/release-notes.md'},
{'License': 'about/license.md'}
]}
]
expected = dedent("""
Home - /
API Guide
Running - /api-guide/running/
Testing - /api-guide/testing/
Debugging - /api-guide/debugging/
About
Release notes - /about/release-notes/
License - /about/license/
""")
site_navigation = nav.SiteNavigation(pages)
self.assertEqual(str(site_navigation).strip(), expected)
self.assertEqual(len(site_navigation.nav_items), 3)
self.assertEqual(len(site_navigation.pages), 6)
开发者ID:10389030,项目名称:mkdocs,代码行数:27,代码来源:nav_tests.py
示例17: test_copy_theme_files
def test_copy_theme_files(self):
with TemporaryDirectory() as docs_dir, TemporaryDirectory() as site_dir:
# 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')))
开发者ID:jimporter,项目名称:mkdocs,代码行数:26,代码来源:build_tests.py
示例18: test_yaml_meta_data
def test_yaml_meta_data(self):
doc = dedent(
"""
---
Title: Foo Bar
Date: 2018-07-10
Summary: Line one
Line two
Tags:
- foo
- bar
---
Doc body
"""
)
self.assertEqual(
utils.meta.get_data(doc),
(
"Doc body",
{
'Title': 'Foo Bar',
'Date': datetime.date(2018, 7, 10),
'Summary': 'Line one Line two',
'Tags': ['foo', 'bar']
}
)
)
开发者ID:mkdocs,项目名称:mkdocs,代码行数:27,代码来源:utils_tests.py
示例19: test_copying_media
def test_copying_media(self):
with TemporaryDirectory() as docs_dir, TemporaryDirectory() as site_dir:
# Create a non-empty markdown file, image, html file, dot file and dot directory.
f = open(os.path.join(docs_dir, 'index.md'), 'w')
f.write(dedent("""
page_title: custom title
# Heading 1
This is some text.
# Heading 2
And some more text.
"""))
f.close()
open(os.path.join(docs_dir, 'img.jpg'), 'w').close()
open(os.path.join(docs_dir, 'example.html'), 'w').close()
open(os.path.join(docs_dir, '.hidden'), 'w').close()
os.mkdir(os.path.join(docs_dir, '.git'))
open(os.path.join(docs_dir, '.git/hidden'), 'w').close()
cfg = load_config(docs_dir=docs_dir, site_dir=site_dir)
build.build(cfg)
# Verify only the markdown (coverted to html) and the image are copied.
self.assertTrue(os.path.isfile(os.path.join(site_dir, 'index.html')))
self.assertTrue(os.path.isfile(os.path.join(site_dir, 'img.jpg')))
self.assertTrue(os.path.isfile(os.path.join(site_dir, 'example.html')))
self.assertFalse(os.path.isfile(os.path.join(site_dir, '.hidden')))
self.assertFalse(os.path.isfile(os.path.join(site_dir, '.git/hidden')))
开发者ID:jimporter,项目名称:mkdocs,代码行数:31,代码来源:build_tests.py
示例20: test_nested_anchor
def test_nested_anchor(self):
md = dedent("""
# Heading 1
## Heading 2
# Heading 3
### Heading 4
### <a href="/">Heading 5</a>
""")
expected = dedent("""
Heading 1 - #heading-1
Heading 2 - #heading-2
Heading 3 - #heading-3
Heading 4 - #heading-4
Heading 5 - #heading-5
""")
toc = markdown_to_toc(md)
self.assertEqual(str(toc).strip(), expected)
开发者ID:AlexKasaku,项目名称:mkdocs,代码行数:17,代码来源:toc_tests.py
注:本文中的mkdocs.tests.base.dedent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论