Skip to content

Commit 0909a10

Browse files
authored
Merge pull request #14 from neatc0der/feature/simplify-configuration
simplify configuration effort
2 parents 5bfc868 + fbeb3ea commit 0909a10

File tree

3 files changed

+22
-44
lines changed

3 files changed

+22
-44
lines changed

README.md

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ pip install mkdocs-markmap
2424
Add this to `mkdocs.yml`:
2525

2626
```yaml
27-
markdown_extensions:
28-
- markmap
2927
plugins:
3028
- markmap
3129
```
@@ -36,12 +34,11 @@ There are more options available for `mkdocs.yml` (shown values are defaults):
3634

3735
```yaml
3836
markdown_extensions:
37+
plugins:
3938
- markmap:
4039
base_path: docs
4140
encoding: utf-8
4241
file_extension: .mm.md
43-
plugins:
44-
- markmap:
4542
d3_version: 6.3.1
4643
lib_version: 0.11.1
4744
view_version: 0.2.1
@@ -62,40 +59,6 @@ extra_javascript:
6259
* `markmap-lib`
6360
* `markmap-view`
6461

65-
## Wait, what?! Do I need an extension or a plugin? :unamused:
66-
67-
_Q: What does the plugin do?_
68-
69-
A: It supports code blocks of markdown as follows:
70-
71-
````markdown
72-
```markmap
73-
# Root
74-
75-
## Branch 1
76-
77-
* Branchlet 1a
78-
* Branchlet 1b
79-
80-
## Branch 2
81-
82-
* Branchlet 2a
83-
* Branchlet 2b
84-
```
85-
````
86-
87-
_Q: What does the extension do?_
88-
89-
A: Well, having such a support is nice, but huge mindmap blocks might be annoying within your tidy markdown files. That is why the extension provides an addition to the markdown syntax. It includes files whereever you need them to be:
90-
91-
```markdown
92-
Look at this beautiful mindmap:
93-
94-
{!mindmap.mm.md!}
95-
```
96-
97-
But you _do_ need the plugin for that. Thus, don't forget to follow the quickstart example above.
98-
9962
## Credits :clap:
10063

10164
Some of the development approaches are based on implementations provided by the following projects:

mkdocs_markmap/extension.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ def run(self, lines: List[str]) -> List[str]:
7272

7373

7474
class MarkmapExtension(Extension):
75+
config_defaults: Dict[str, str] = {
76+
'base_path': ['docs', 'Default location from which to evaluate relative paths for the include statement.'],
77+
'encoding': ['utf-8', 'Encoding of the files used by the include statement.'],
78+
'file_extension': ['.mm.md', 'File extension of mindmap files'],
79+
}
80+
7581
def __init__(self, **configs: Dict[str, str]):
76-
self.config: Dict[str, str] = {
77-
'base_path': ['docs', 'Default location from which to evaluate relative paths for the include statement.'],
78-
'encoding': ['utf-8', 'Encoding of the files used by the include statement.'],
79-
'file_extension': ['.mm.md', 'File extension of mindmap files'],
80-
}
82+
self.config: Dict[str, str] = self.config_defaults
8183
for key, value in configs.items():
8284
self.setConfig(key, value)
8385

mkdocs_markmap/plugin.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
from mkdocs_markmap.extension import MarkmapExtension
23
import re
34
from pathlib import Path
45
from typing import Dict, Tuple
@@ -8,7 +9,6 @@
89
from mkdocs.structure.pages import Page
910
from mkdocs.config.base import Config
1011
from mkdocs.config.config_options import Type as PluginType
11-
from mkdocs.utils import copy_file
1212

1313
from .defaults import MARKMAP
1414
from .utils import download
@@ -30,6 +30,9 @@ class MarkmapPlugin(BasePlugin):
3030
(f'{name}_version', PluginType(str, default=module.version))
3131
for name, module in MARKMAP.items()
3232
),
33+
('base_path', PluginType(str, default='docs')),
34+
('encoding', PluginType(str, default='utf-8')),
35+
('file_extension', PluginType(str, default='.mm.md')),
3336
)
3437

3538
def __init__(self):
@@ -78,6 +81,16 @@ def _add_statics(soup: BeautifulSoup):
7881
tag.string = fp.read()
7982
getattr(soup, attribute).append(tag)
8083

84+
def on_config(self, config: Config) -> Config:
85+
config['markdown_extensions'].append('markmap')
86+
config['mdx_configs']['markmap'] = {
87+
key: value
88+
for key, value in config['plugins'].get('markmap').config.items()
89+
if key in MarkmapExtension.config_defaults
90+
}
91+
92+
return config
93+
8194
def on_post_page(self, output_content: str, config: Config, **kwargs) -> str:
8295
soup: BeautifulSoup = BeautifulSoup(output_content, 'html.parser')
8396
page: Page = kwargs.get('page')

0 commit comments

Comments
 (0)