Skip to content

Commit 571858a

Browse files
authored
Some performance improvements (#147)
1 parent e647ef9 commit 571858a

File tree

14 files changed

+1157
-2974
lines changed

14 files changed

+1157
-2974
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto
2+
examples/a-lot-of-includes/ -diff

examples/a-lot-of-includes/docs/barbaz.svg

Loading

examples/a-lot-of-includes/docs/included.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ Some ignored content.
44

55
Some included content.
66

7+
![Image](barbaz.svg)
8+
79
<!--end-->
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Foo bar baz 00
2+
Foo bar baz 00
3+
Foo bar baz 00
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Foo bar baz 01
2+
Foo bar baz 01
3+
Foo bar baz 01
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Foo bar baz 02
2+
Foo bar baz 02
3+
Foo bar baz 02
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Foo bar baz 03
2+
Foo bar baz 03
3+
Foo bar baz 03

examples/a-lot-of-includes/docs/index.md

Lines changed: 1020 additions & 2867 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mkdocs-include-markdown-plugin"
3-
version = "4.0.2"
3+
version = "4.0.3"
44
description = "Mkdocs Markdown includer plugin."
55
readme = "README.md"
66
license = "Apache-2.0"

src/mkdocs_include_markdown_plugin/config.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,35 @@
22

33
from __future__ import annotations
44

5+
import re
6+
57
from mkdocs.config.config_options import Type as MkType
68

9+
from mkdocs_include_markdown_plugin.regexes import INCLUDE_TAG_RE
10+
711

8-
CONFIG_DEFAULT_COMMENTS = True
12+
DEFAULT_COMMENTS = True
13+
DEFAULT_OPENING_TAG = '{%'
14+
DEFAULT_CLOSING_TAG = '%}'
915

1016
CONFIG_DEFAULTS = {
11-
'opening_tag': '{%',
12-
'closing_tag': '%}',
17+
'opening_tag': DEFAULT_OPENING_TAG,
18+
'closing_tag': DEFAULT_CLOSING_TAG,
1319
'encoding': 'utf-8',
1420
'preserve_includer_indent': True,
1521
'dedent': False,
1622
'trailing_newlines': True,
17-
'comments': CONFIG_DEFAULT_COMMENTS,
23+
'comments': DEFAULT_COMMENTS,
1824
}
1925

2026
CONFIG_SCHEME = (
2127
(
2228
'opening_tag',
23-
MkType(str, default=CONFIG_DEFAULTS['opening_tag']),
29+
MkType(str, default=DEFAULT_OPENING_TAG),
2430
),
2531
(
2632
'closing_tag',
27-
MkType(str, default=CONFIG_DEFAULTS['closing_tag']),
33+
MkType(str, default=DEFAULT_CLOSING_TAG),
2834
),
2935
(
3036
'encoding',
@@ -44,6 +50,22 @@
4450
),
4551
(
4652
'comments',
47-
MkType(bool, default=CONFIG_DEFAULTS['comments']),
53+
MkType(bool, default=DEFAULT_COMMENTS),
4854
),
4955
)
56+
57+
58+
def create_include_tag(
59+
opening_tag: str, closing_tag: str, tag: str = 'include',
60+
) -> re.Pattern[str]:
61+
"""Create a regex pattern to match an inclusion tag directive.
62+
63+
Replaces the substrings '$OPENING_TAG' and '$CLOSING_TAG' from
64+
INCLUDE_TAG_REGEX by the effective tag.
65+
"""
66+
return re.compile(
67+
INCLUDE_TAG_RE.replace(' include', f' {tag}').replace(
68+
'$OPENING_TAG', re.escape(opening_tag),
69+
).replace('$CLOSING_TAG', re.escape(closing_tag)),
70+
flags=re.VERBOSE | re.DOTALL,
71+
)

0 commit comments

Comments
 (0)