mkdocs-techdocs-core 1.5.2__tar.gz → 1.5.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-techdocs-core
3
- Version: 1.5.2
3
+ Version: 1.5.4
4
4
  Summary: The core MkDocs plugin used by Backstage's TechDocs as a wrapper around multiple MkDocs plugins and Python Markdown extensions
5
5
  Home-page: https://github.com/backstage/mkdocs-techdocs-core
6
6
  Author: TechDocs Core
@@ -23,12 +23,12 @@ Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  Requires-Dist: mkdocs>=1.6
25
25
  Requires-Dist: Markdown<3.8,>=3.2
26
- Requires-Dist: mkdocs-material==9.5.49
26
+ Requires-Dist: mkdocs-material==9.6.8
27
27
  Requires-Dist: markdown-graphviz-inline==1.1.3
28
28
  Requires-Dist: mkdocs-monorepo-plugin==1.1.0
29
- Requires-Dist: plantuml-markdown==3.10.4
29
+ Requires-Dist: plantuml-markdown==3.11.1
30
30
  Requires-Dist: mdx_truly_sane_lists==1.3
31
- Requires-Dist: pymdown-extensions==10.13
31
+ Requires-Dist: pymdown-extensions==10.14.3
32
32
  Requires-Dist: pygments==2.19.1
33
33
  Requires-Dist: mkdocs-redirects==1.2.2
34
34
  Dynamic: author
@@ -78,6 +78,14 @@ plugins:
78
78
  use_material_search: true
79
79
  ```
80
80
 
81
+ (Optional) To use [PyMdown Blocks Extensions](https://facelessuser.github.io/pymdown-extensions/extensions/blocks/) (replaces `admonitions`, `pymdownx.details` and `pymdownx.tabbed` extensions), you need to add the following configuration to your `mkdocs.yml`:
82
+
83
+ ```yaml
84
+ plugins:
85
+ - techdocs-core:
86
+ use_pymdownx_blocks: true
87
+ ```
88
+
81
89
  ## Development
82
90
 
83
91
  ### Running Locally
@@ -194,6 +202,14 @@ We only use `material-mkdocs` as base styles because Backstage also uses the `Ma
194
202
 
195
203
  ## Changelog
196
204
 
205
+ ### 1.5.4
206
+
207
+ - Added proper plugin config to fix `Unrecognised configuration name` error when any config is provided
208
+
209
+ ### 1.5.3
210
+
211
+ - Added support for PyMdown Blocks extensions
212
+
197
213
  ### 1.5.2
198
214
 
199
215
  - Update `markdown_inline_graphviz_extension` to use forked `markdown-graphviz-inline` instead due to abandonment of original dependency.
@@ -33,6 +33,14 @@ plugins:
33
33
  use_material_search: true
34
34
  ```
35
35
 
36
+ (Optional) To use [PyMdown Blocks Extensions](https://facelessuser.github.io/pymdown-extensions/extensions/blocks/) (replaces `admonitions`, `pymdownx.details` and `pymdownx.tabbed` extensions), you need to add the following configuration to your `mkdocs.yml`:
37
+
38
+ ```yaml
39
+ plugins:
40
+ - techdocs-core:
41
+ use_pymdownx_blocks: true
42
+ ```
43
+
36
44
  ## Development
37
45
 
38
46
  ### Running Locally
@@ -149,6 +157,14 @@ We only use `material-mkdocs` as base styles because Backstage also uses the `Ma
149
157
 
150
158
  ## Changelog
151
159
 
160
+ ### 1.5.4
161
+
162
+ - Added proper plugin config to fix `Unrecognised configuration name` error when any config is provided
163
+
164
+ ### 1.5.3
165
+
166
+ - Added support for PyMdown Blocks extensions
167
+
152
168
  ### 1.5.2
153
169
 
154
170
  - Update `markdown_inline_graphviz_extension` to use forked `markdown-graphviz-inline` instead due to abandonment of original dependency.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: mkdocs-techdocs-core
3
- Version: 1.5.2
3
+ Version: 1.5.4
4
4
  Summary: The core MkDocs plugin used by Backstage's TechDocs as a wrapper around multiple MkDocs plugins and Python Markdown extensions
5
5
  Home-page: https://github.com/backstage/mkdocs-techdocs-core
6
6
  Author: TechDocs Core
@@ -23,12 +23,12 @@ Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  Requires-Dist: mkdocs>=1.6
25
25
  Requires-Dist: Markdown<3.8,>=3.2
26
- Requires-Dist: mkdocs-material==9.5.49
26
+ Requires-Dist: mkdocs-material==9.6.8
27
27
  Requires-Dist: markdown-graphviz-inline==1.1.3
28
28
  Requires-Dist: mkdocs-monorepo-plugin==1.1.0
29
- Requires-Dist: plantuml-markdown==3.10.4
29
+ Requires-Dist: plantuml-markdown==3.11.1
30
30
  Requires-Dist: mdx_truly_sane_lists==1.3
31
- Requires-Dist: pymdown-extensions==10.13
31
+ Requires-Dist: pymdown-extensions==10.14.3
32
32
  Requires-Dist: pygments==2.19.1
33
33
  Requires-Dist: mkdocs-redirects==1.2.2
34
34
  Dynamic: author
@@ -78,6 +78,14 @@ plugins:
78
78
  use_material_search: true
79
79
  ```
80
80
 
81
+ (Optional) To use [PyMdown Blocks Extensions](https://facelessuser.github.io/pymdown-extensions/extensions/blocks/) (replaces `admonitions`, `pymdownx.details` and `pymdownx.tabbed` extensions), you need to add the following configuration to your `mkdocs.yml`:
82
+
83
+ ```yaml
84
+ plugins:
85
+ - techdocs-core:
86
+ use_pymdownx_blocks: true
87
+ ```
88
+
81
89
  ## Development
82
90
 
83
91
  ### Running Locally
@@ -194,6 +202,14 @@ We only use `material-mkdocs` as base styles because Backstage also uses the `Ma
194
202
 
195
203
  ## Changelog
196
204
 
205
+ ### 1.5.4
206
+
207
+ - Added proper plugin config to fix `Unrecognised configuration name` error when any config is provided
208
+
209
+ ### 1.5.3
210
+
211
+ - Added support for PyMdown Blocks extensions
212
+
197
213
  ### 1.5.2
198
214
 
199
215
  - Update `markdown_inline_graphviz_extension` to use forked `markdown-graphviz-inline` instead due to abandonment of original dependency.
@@ -1,10 +1,10 @@
1
1
  mkdocs>=1.6
2
2
  Markdown<3.8,>=3.2
3
- mkdocs-material==9.5.49
3
+ mkdocs-material==9.6.8
4
4
  markdown-graphviz-inline==1.1.3
5
5
  mkdocs-monorepo-plugin==1.1.0
6
- plantuml-markdown==3.10.4
6
+ plantuml-markdown==3.11.1
7
7
  mdx_truly_sane_lists==1.3
8
- pymdown-extensions==10.13
8
+ pymdown-extensions==10.14.3
9
9
  pygments==2.19.1
10
10
  mkdocs-redirects==1.2.2
@@ -9,12 +9,12 @@ Markdown>=3.2,<3.8
9
9
  # pinned to an exact version. Bumps should be accompanied by release notes
10
10
  # explaining what was added or fixed (or at least pointing to the underlying
11
11
  # release notes of the bumped package).
12
- mkdocs-material==9.5.49
12
+ mkdocs-material==9.6.8
13
13
  markdown-graphviz-inline==1.1.3
14
14
  mkdocs-monorepo-plugin==1.1.0
15
- plantuml-markdown==3.10.4
15
+ plantuml-markdown==3.11.1
16
16
  mdx_truly_sane_lists==1.3
17
- pymdown-extensions==10.13
17
+ pymdown-extensions==10.14.3
18
18
  pygments==2.19.1
19
19
  mkdocs-redirects==1.2.2
20
20
 
@@ -28,7 +28,7 @@ with open("requirements.txt") as f:
28
28
 
29
29
  setup(
30
30
  name="mkdocs-techdocs-core",
31
- version="1.5.2",
31
+ version="1.5.4",
32
32
  description="The core MkDocs plugin used by Backstage's TechDocs as a wrapper around "
33
33
  "multiple MkDocs plugins and Python Markdown extensions",
34
34
  long_description=long_description,
@@ -1,22 +1,24 @@
1
1
  """
2
- * Copyright 2020 The Backstage Authors
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
2
+ * Copyright 2020 The Backstage Authors
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
15
  """
16
16
 
17
17
  import tempfile
18
18
  import logging
19
19
  import os
20
+
21
+ from mkdocs.config import Config, config_options
20
22
  from mkdocs.plugins import BasePlugin
21
23
  from mkdocs.theme import Theme
22
24
  from mkdocs.contrib.search import SearchPlugin
@@ -30,7 +32,12 @@ log = logging.getLogger(__name__)
30
32
  TECHDOCS_DEFAULT_THEME = "material"
31
33
 
32
34
 
33
- class TechDocsCore(BasePlugin):
35
+ class TechDocsCoreConfig(Config):
36
+ use_material_search = config_options.Type(bool, default=False)
37
+ use_pymdownx_blocks = config_options.Type(bool, default=False)
38
+
39
+
40
+ class TechDocsCore(BasePlugin[TechDocsCoreConfig]):
34
41
  def __init__(self):
35
42
  # This directory will be removed automatically once the docs are built
36
43
  # MkDocs needs a directory for the theme with the `techdocs_metadata.json` file
@@ -76,9 +83,8 @@ class TechDocsCore(BasePlugin):
76
83
  config["theme"].dirs.append(self.tmp_dir_techdocs_theme.name)
77
84
 
78
85
  # Plugins
79
- use_material_search = config["plugins"]["techdocs-core"].config.get(
80
- "use_material_search", False
81
- )
86
+ use_material_search = self.config["use_material_search"]
87
+ use_pymdownx_blocks = self.config["use_pymdownx_blocks"]
82
88
  del config["plugins"]["techdocs-core"]
83
89
 
84
90
  if use_material_search:
@@ -99,15 +105,64 @@ class TechDocsCore(BasePlugin):
99
105
  if "mdx_configs" not in config:
100
106
  config["mdx_configs"] = {}
101
107
 
102
- config["markdown_extensions"].append("admonition")
103
108
  config["markdown_extensions"].append("toc")
104
109
  config["mdx_configs"]["toc"] = {
105
110
  "permalink": True,
106
111
  }
107
112
 
113
+ if use_pymdownx_blocks:
114
+ config["markdown_extensions"].append("pymdownx.blocks.admonition")
115
+ config["mdx_configs"]["pymdownx.blocks.admonition"] = {
116
+ "types": [
117
+ "new",
118
+ "settings",
119
+ "note",
120
+ "abstract",
121
+ "info",
122
+ "tip",
123
+ "success",
124
+ "question",
125
+ "warning",
126
+ "failure",
127
+ "danger",
128
+ "bug",
129
+ "example",
130
+ "quote",
131
+ ]
132
+ }
133
+ config["markdown_extensions"].append("pymdownx.blocks.details")
134
+ config["mdx_configs"]["pymdownx.blocks.details"] = {
135
+ "types": [
136
+ {"name": "details-new", "class": "new"},
137
+ {"name": "details-settings", "class": "settings"},
138
+ {"name": "details-note", "class": "note"},
139
+ {"name": "details-abstract", "class": "abstract"},
140
+ {"name": "details-info", "class": "info"},
141
+ {"name": "details-tip", "class": "tip"},
142
+ {"name": "details-success", "class": "success"},
143
+ {"name": "details-question", "class": "question"},
144
+ {"name": "details-warning", "class": "warning"},
145
+ {"name": "details-failure", "class": "failure"},
146
+ {"name": "details-danger", "class": "danger"},
147
+ {"name": "details-bug", "class": "bug"},
148
+ {"name": "details-example", "class": "example"},
149
+ {"name": "details-quote", "class": "quote"},
150
+ ]
151
+ }
152
+ config["markdown_extensions"].append("pymdownx.blocks.tab")
153
+ config["mdx_configs"]["pymdownx.blocks.tab"] = {
154
+ "alternate_style": True,
155
+ }
156
+ else:
157
+ config["markdown_extensions"].append("admonition")
158
+ config["markdown_extensions"].append("pymdownx.details")
159
+ config["markdown_extensions"].append("pymdownx.tabbed")
160
+ config["mdx_configs"]["pymdownx.tabbed"] = {
161
+ "alternate_style": True,
162
+ }
163
+
108
164
  config["markdown_extensions"].append("pymdownx.caret")
109
165
  config["markdown_extensions"].append("pymdownx.critic")
110
- config["markdown_extensions"].append("pymdownx.details")
111
166
  config["markdown_extensions"].append("pymdownx.emoji")
112
167
  config["mdx_configs"]["pymdownx.emoji"] = {"emoji_generator": to_svg}
113
168
  config["markdown_extensions"].append("pymdownx.inlinehilite")
@@ -124,10 +179,6 @@ class TechDocsCore(BasePlugin):
124
179
  config["mdx_configs"]["pymdownx.betterem"] = {
125
180
  "smart_enable": "all",
126
181
  }
127
- config["markdown_extensions"].append("pymdownx.tabbed")
128
- config["mdx_configs"]["pymdownx.tabbed"] = {
129
- "alternate_style": True,
130
- }
131
182
  config["markdown_extensions"].append("pymdownx.tasklist")
132
183
  config["mdx_configs"]["pymdownx.tasklist"] = {
133
184
  "custom_checkbox": True,
@@ -0,0 +1,175 @@
1
+ import unittest
2
+ import mkdocs.plugins as plugins
3
+ from mkdocs.theme import Theme
4
+ from .core import TechDocsCore, TECHDOCS_DEFAULT_THEME
5
+ from jinja2 import Environment, PackageLoader, select_autoescape
6
+ import json
7
+
8
+
9
+ # Helper to get the "default" theme passed into config when no theme is
10
+ # provided in the actual config.
11
+ def get_default_theme():
12
+ return Theme(name="mkdocs")
13
+
14
+
15
+ class DummyTechDocsCorePlugin(plugins.BasePlugin):
16
+ pass
17
+
18
+
19
+ class TestTechDocsCore(unittest.TestCase):
20
+ def setUp(self):
21
+ self.plugin_collection = plugins.PluginCollection()
22
+ plugin = DummyTechDocsCorePlugin()
23
+ self.plugin_collection["techdocs-core"] = plugin
24
+ self.techdocscore = TechDocsCore()
25
+ self.techdocscore.load_config(
26
+ {"plugins": self.plugin_collection, "theme": get_default_theme()}
27
+ )
28
+
29
+ def test_removes_techdocs_core_plugin_from_config(self):
30
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
31
+ self.assertTrue("techdocs-core" not in final_config["plugins"])
32
+
33
+ def test_merge_default_config_and_user_config(self):
34
+ self.techdocscore.config["markdown_extension"] = []
35
+ self.techdocscore.config["mdx_configs"] = {}
36
+ self.techdocscore.config["markdown_extension"].append(["toc"])
37
+ self.techdocscore.config["mdx_configs"]["toc"] = {"toc_depth": 3}
38
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
39
+ self.assertTrue("toc" in final_config["mdx_configs"])
40
+ self.assertTrue("permalink" in final_config["mdx_configs"]["toc"])
41
+ self.assertTrue("toc_depth" in final_config["mdx_configs"]["toc"])
42
+ self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])
43
+
44
+ def test_override_default_config_with_user_config(self):
45
+ self.techdocscore.config["markdown_extension"] = []
46
+ self.techdocscore.config["mdx_configs"] = {}
47
+ self.techdocscore.config["markdown_extension"].append(["toc"])
48
+ self.techdocscore.config["mdx_configs"]["toc"] = {"permalink": False}
49
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
50
+ self.assertTrue("toc" in final_config["mdx_configs"])
51
+ self.assertTrue("permalink" in final_config["mdx_configs"]["toc"])
52
+ self.assertFalse(final_config["mdx_configs"]["toc"]["permalink"])
53
+ self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])
54
+
55
+ def test_theme_overrides_removed_when_name_is_not_material(self):
56
+ # we want to force the theme mkdocs to this test
57
+ self.techdocscore.config["theme"] = Theme(name="mkdocs")
58
+ self.techdocscore.config["theme"]["features"] = ["navigation.sections"]
59
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
60
+ self.assertFalse("navigation.sections" in final_config["theme"]["features"])
61
+
62
+ def test_theme_overrides_when_name_is_material(self):
63
+ self.techdocscore.config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
64
+ self.techdocscore.config["theme"]["features"] = ["navigation.sections"]
65
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
66
+ self.assertTrue("navigation.sections" in final_config["theme"]["features"])
67
+
68
+ def test_theme_overrides_techdocs_metadata(self):
69
+ self.techdocscore.config["theme"] = Theme(
70
+ name=TECHDOCS_DEFAULT_THEME, static_templates=["my_static_temples"]
71
+ )
72
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
73
+ self.assertTrue("my_static_temples" in final_config["theme"].static_templates)
74
+ self.assertTrue(
75
+ "techdocs_metadata.json" in final_config["theme"].static_templates
76
+ )
77
+
78
+ def test_theme_overrides_dirs(self):
79
+ custom_theme_dir = "/tmp/my_custom_theme_dir"
80
+ self.techdocscore.config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
81
+ self.techdocscore.config["theme"].dirs.append(custom_theme_dir)
82
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
83
+ self.assertTrue(custom_theme_dir in final_config["theme"].dirs)
84
+ self.assertTrue(
85
+ self.techdocscore.tmp_dir_techdocs_theme.name in final_config["theme"].dirs
86
+ )
87
+
88
+ def test_template_renders__multiline_value_as_valid_json(self):
89
+ self.techdocscore.on_config(self.techdocscore.config)
90
+ env = Environment(
91
+ loader=PackageLoader(
92
+ "techdocs_core", self.techdocscore.tmp_dir_techdocs_theme.name
93
+ ),
94
+ autoescape=select_autoescape(),
95
+ )
96
+ template = env.get_template("techdocs_metadata.json")
97
+ config = {
98
+ "site_name": "my site",
99
+ "site_description": "my very\nlong\nsite\ndescription",
100
+ }
101
+ rendered = template.render(config=config)
102
+ as_json = json.loads(rendered)
103
+ self.assertEqual(config, as_json)
104
+
105
+ def test_restrict_snippet_base_path(self):
106
+ self.techdocscore.config["mdx_configs"] = {
107
+ "pymdownx.snippets": {"restrict_base_path": False}
108
+ }
109
+
110
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
111
+
112
+ self.assertEqual(
113
+ final_config["mdx_configs"]["pymdownx.snippets"]["restrict_base_path"],
114
+ True,
115
+ )
116
+
117
+ def test_material_search(self):
118
+ self.techdocscore.config["use_material_search"] = True
119
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
120
+
121
+ self.assertEqual(
122
+ final_config["plugins"]["search"].__module__,
123
+ "material.plugins.search.plugin",
124
+ )
125
+
126
+ def test_default_search(self):
127
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
128
+ self.assertEqual(
129
+ final_config["plugins"]["search"].__module__, "mkdocs.contrib.search"
130
+ )
131
+
132
+ def test_pymdownx_blocks(self):
133
+ self.techdocscore.config["use_pymdownx_blocks"] = True
134
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
135
+
136
+ self.assertTrue(
137
+ "pymdownx.blocks.admonition" in final_config["markdown_extensions"]
138
+ )
139
+ self.assertTrue(
140
+ "pymdownx.blocks.details" in final_config["markdown_extensions"]
141
+ )
142
+ self.assertTrue("pymdownx.blocks.tab" in final_config["markdown_extensions"])
143
+ self.assertTrue(
144
+ "types" in final_config["mdx_configs"]["pymdownx.blocks.admonition"]
145
+ )
146
+ self.assertTrue(
147
+ "types" in final_config["mdx_configs"]["pymdownx.blocks.details"]
148
+ )
149
+ self.assertTrue(
150
+ "alternate_style" in final_config["mdx_configs"]["pymdownx.blocks.tab"]
151
+ )
152
+ self.assertFalse("admonition" in final_config["markdown_extensions"])
153
+ self.assertFalse("pymdownx.details" in final_config["markdown_extensions"])
154
+ self.assertFalse("pymdownx.tabbed" in final_config["markdown_extensions"])
155
+ self.assertFalse("pymdownx.tabbed" in final_config["mdx_configs"])
156
+
157
+ def test_default_pymdownx(self):
158
+ final_config = self.techdocscore.on_config(self.techdocscore.config)
159
+
160
+ self.assertFalse(
161
+ "pymdownx.blocks.admonition" in final_config["markdown_extensions"]
162
+ )
163
+ self.assertFalse(
164
+ "pymdownx.blocks.details" in final_config["markdown_extensions"]
165
+ )
166
+ self.assertFalse("pymdownx.blocks.tab" in final_config["markdown_extensions"])
167
+ self.assertFalse("pymdownx.blocks.admonition" in final_config["mdx_configs"])
168
+ self.assertFalse("pymdownx.blocks.details" in final_config["mdx_configs"])
169
+ self.assertFalse("pymdownx.blocks.tab" in final_config["mdx_configs"])
170
+ self.assertTrue("admonition" in final_config["markdown_extensions"])
171
+ self.assertTrue("pymdownx.details" in final_config["markdown_extensions"])
172
+ self.assertTrue("pymdownx.tabbed" in final_config["markdown_extensions"])
173
+ self.assertTrue(
174
+ "alternate_style" in final_config["mdx_configs"]["pymdownx.tabbed"]
175
+ )
@@ -1,133 +0,0 @@
1
- import unittest
2
- import mkdocs.plugins as plugins
3
- from mkdocs.theme import Theme
4
- from .core import TechDocsCore, TECHDOCS_DEFAULT_THEME
5
- from jinja2 import Environment, PackageLoader, select_autoescape
6
- import json
7
-
8
-
9
- # Helper to get the "default" theme passed into config when no theme is
10
- # provided in the actual config.
11
- def get_default_theme():
12
- return Theme(name="mkdocs")
13
-
14
-
15
- class DummyTechDocsCorePlugin(plugins.BasePlugin):
16
- pass
17
-
18
-
19
- class TestTechDocsCoreConfig(unittest.TestCase):
20
- def setUp(self):
21
- self.techdocscore = TechDocsCore()
22
- self.plugin_collection = plugins.PluginCollection()
23
- plugin = DummyTechDocsCorePlugin()
24
- self.plugin_collection["techdocs-core"] = plugin
25
- self.mkdocs_yaml_config = {"plugins": self.plugin_collection}
26
- # Note: in reality, config["theme"] is always an instance of Theme
27
- self.mkdocs_yaml_config["theme"] = get_default_theme()
28
-
29
- def test_removes_techdocs_core_plugin_from_config(self):
30
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
31
- self.assertTrue("techdocs-core" not in final_config["plugins"])
32
-
33
- def test_merge_default_config_and_user_config(self):
34
- self.mkdocs_yaml_config["markdown_extension"] = []
35
- self.mkdocs_yaml_config["mdx_configs"] = {}
36
- self.mkdocs_yaml_config["markdown_extension"].append(["toc"])
37
- self.mkdocs_yaml_config["mdx_configs"]["toc"] = {"toc_depth": 3}
38
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
39
- self.assertTrue("toc" in final_config["mdx_configs"])
40
- self.assertTrue("permalink" in final_config["mdx_configs"]["toc"])
41
- self.assertTrue("toc_depth" in final_config["mdx_configs"]["toc"])
42
- self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])
43
-
44
- def test_override_default_config_with_user_config(self):
45
- self.mkdocs_yaml_config["markdown_extension"] = []
46
- self.mkdocs_yaml_config["mdx_configs"] = {}
47
- self.mkdocs_yaml_config["markdown_extension"].append(["toc"])
48
- self.mkdocs_yaml_config["mdx_configs"]["toc"] = {"permalink": False}
49
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
50
- self.assertTrue("toc" in final_config["mdx_configs"])
51
- self.assertTrue("permalink" in final_config["mdx_configs"]["toc"])
52
- self.assertFalse(final_config["mdx_configs"]["toc"]["permalink"])
53
- self.assertTrue("mdx_truly_sane_lists" in final_config["markdown_extensions"])
54
-
55
- def test_theme_overrides_removed_when_name_is_not_material(self):
56
- # we want to force the theme mkdocs to this test
57
- self.mkdocs_yaml_config["theme"] = Theme(name="mkdocs")
58
- self.mkdocs_yaml_config["theme"]["features"] = ["navigation.sections"]
59
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
60
- self.assertFalse("navigation.sections" in final_config["theme"]["features"])
61
-
62
- def test_theme_overrides_when_name_is_material(self):
63
- self.mkdocs_yaml_config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
64
- self.mkdocs_yaml_config["theme"]["features"] = ["navigation.sections"]
65
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
66
- self.assertTrue("navigation.sections" in final_config["theme"]["features"])
67
-
68
- def test_theme_overrides_techdocs_metadata(self):
69
- self.mkdocs_yaml_config["theme"] = Theme(
70
- name=TECHDOCS_DEFAULT_THEME, static_templates=["my_static_temples"]
71
- )
72
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
73
- self.assertTrue("my_static_temples" in final_config["theme"].static_templates)
74
- self.assertTrue(
75
- "techdocs_metadata.json" in final_config["theme"].static_templates
76
- )
77
-
78
- def test_theme_overrides_dirs(self):
79
- custom_theme_dir = "/tmp/my_custom_theme_dir"
80
- self.mkdocs_yaml_config["theme"] = Theme(name=TECHDOCS_DEFAULT_THEME)
81
- self.mkdocs_yaml_config["theme"].dirs.append(custom_theme_dir)
82
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
83
- self.assertTrue(custom_theme_dir in final_config["theme"].dirs)
84
- self.assertTrue(
85
- self.techdocscore.tmp_dir_techdocs_theme.name in final_config["theme"].dirs
86
- )
87
-
88
- def test_template_renders__multiline_value_as_valid_json(self):
89
- self.techdocscore.on_config(self.mkdocs_yaml_config)
90
- env = Environment(
91
- loader=PackageLoader(
92
- "techdocs_core", self.techdocscore.tmp_dir_techdocs_theme.name
93
- ),
94
- autoescape=select_autoescape(),
95
- )
96
- template = env.get_template("techdocs_metadata.json")
97
- config = {
98
- "site_name": "my site",
99
- "site_description": "my very\nlong\nsite\ndescription",
100
- }
101
- rendered = template.render(config=config)
102
- as_json = json.loads(rendered)
103
- self.assertEqual(config, as_json)
104
-
105
- def test_restrict_snippet_base_path(self):
106
- self.mkdocs_yaml_config["mdx_configs"] = {
107
- "pymdownx.snippets": {"restrict_base_path": False}
108
- }
109
-
110
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
111
-
112
- self.assertEqual(
113
- final_config["mdx_configs"]["pymdownx.snippets"]["restrict_base_path"],
114
- True,
115
- )
116
-
117
- def test_material_search(self):
118
- self.plugin_collection["techdocs-core"].load_config(
119
- {"use_material_search": True}
120
- )
121
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
122
-
123
- self.assertEqual(
124
- final_config["plugins"]["search"].__module__,
125
- "material.plugins.search.plugin",
126
- )
127
-
128
- def test_default_search(self):
129
- self.plugin_collection["techdocs-core"].load_config({})
130
- final_config = self.techdocscore.on_config(self.mkdocs_yaml_config)
131
- self.assertEqual(
132
- final_config["plugins"]["search"].__module__, "mkdocs.contrib.search"
133
- )