refactor: Adjust again to latest 'simple' commit
Now with even less code!
This commit is contained in:
parent
5a1f9e044a
commit
d0904e40cb
@ -1,6 +1,7 @@
|
|||||||
# MkDocs semiliterate Plugin
|
# MkDocs semiliterate Plugin
|
||||||
|
|
||||||
This plugin for MkDocs is an extension of Allison Thackston's excellent [mkdocs-simple-plugin](https://athackst.github.io/mkdocs-simple-plugin). It adds `{! ... !}` syntax for including content from one file into another (and a couple of other small ease-of-use tweaks).<!-- repo: --><!-- site: The current version of mkdocs-semiliterate is {! setup.cfg {start: name, terminate: '(\d*\.\d*\.\d*)'} !}. -->
|
This plugin for MkDocs is an extension of Allison Thackston's excellent [mkdocs-simple-plugin](https://athackst.github.io/mkdocs-simple-plugin). It adds `{! ... !}` syntax for including content from one file into another (and a couple of other small ease-of-use tweaks).
|
||||||
|
<!-- repo: --><!-- site: The current version of mkdocs-semiliterate is {! setup.cfg { extract: {start: name}, terminate: '(\d*\.\d*\.\d*)'} !}. -->
|
||||||
|
|
||||||
## Rationale
|
## Rationale
|
||||||
|
|
||||||
|
@ -12,18 +12,20 @@ plugins:
|
|||||||
include_extensions: [LICENSE]
|
include_extensions: [LICENSE]
|
||||||
report_docs_build: true
|
report_docs_build: true
|
||||||
extract_standard_markdown:
|
extract_standard_markdown:
|
||||||
|
extract:
|
||||||
replace: [['^(.*)<!-- repo: -->.*<!-- site:(.*?) -->(.*\s*)$', '\1\2\3']]
|
replace: [['^(.*)<!-- repo: -->.*<!-- site:(.*?) -->(.*\s*)$', '\1\2\3']]
|
||||||
semiliterate:
|
semiliterate:
|
||||||
- pattern: '(\.py)$'
|
- pattern: '\.py$'
|
||||||
start: '"""\smd'
|
extract: {start: '"""\smd', stop: '"""'}
|
||||||
stop: '"""'
|
|
||||||
- pattern: '.drone.yml'
|
- pattern: '.drone.yml'
|
||||||
destination: 'drone_develop.md'
|
destination: 'drone_develop.md'
|
||||||
|
extract:
|
||||||
start: '### develop'
|
start: '### develop'
|
||||||
stop: '^\s*###'
|
stop: '^\s*###'
|
||||||
replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$']
|
replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$']
|
||||||
- pattern: '.drone.yml'
|
- pattern: '.drone.yml'
|
||||||
destination: 'drone_install.md'
|
destination: 'drone_install.md'
|
||||||
|
extract:
|
||||||
start: '### install'
|
start: '### install'
|
||||||
stop: '^\s*###'
|
stop: '^\s*###'
|
||||||
replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$']
|
replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$']
|
||||||
|
@ -41,36 +41,14 @@ is interpolated at the current location in the file currently being written.
|
|||||||
Recursive inclusion is supported.
|
Recursive inclusion is supported.
|
||||||
|
|
||||||
Note that the `{! ... !}` directive must be in lines that semiliterate would
|
Note that the `{! ... !}` directive must be in lines that semiliterate would
|
||||||
normally copy. That is, it does not examine lines before the `start` regexp
|
normally copy. That is, it does not examine lines after the `terminate` regexp,
|
||||||
is encountered, or after the `terminate` regexp, or between instances of
|
or when no mode of extraction is active. It also doesn't check any text written
|
||||||
`stop` and `start`. It also doesn't check any text written from lines that
|
from lines that match these special expressions like `start` and `stop`.
|
||||||
match these special expressions. Moreover, on such normally-transcribed lines,
|
Moreover, on such normally-transcribed lines,
|
||||||
it's the text **after** the application of any semiliterate `replace`ments that
|
it's the text **after** the application of any semiliterate `replace`ments that
|
||||||
is checked for `{! ... !}`.
|
is checked for `{! ... !}`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, input_stream, output_stream, **kwargs):
|
|
||||||
""" md
|
|
||||||
### Adjusted semiliterate options
|
|
||||||
|
|
||||||
The `start` regular-expression parameter to a `semiliterate` file-inclusion
|
|
||||||
pattern is now optional. If omitted, it means that extraction begins immediately
|
|
||||||
with the first line of a file; in this case, `pause` and `terminate` retain
|
|
||||||
their usual meanings, although there is not currently any way to resume from a
|
|
||||||
`pause` when `start` is not specified. This adjustment to `semiliterate`
|
|
||||||
parameters makes it easier to extract "front-matter" style documentation from
|
|
||||||
files. It also means that a plain `{! file.md !}` directive will simply
|
|
||||||
incorporate the full contents of `file.md`.
|
|
||||||
"""
|
|
||||||
start_hot = False
|
|
||||||
if 'start' not in kwargs:
|
|
||||||
kwargs['start'] = 'dummy'
|
|
||||||
start_hot = True
|
|
||||||
super().__init__(input_stream, output_stream, **kwargs)
|
|
||||||
if start_hot:
|
|
||||||
self.extracting = True
|
|
||||||
self.start = False
|
|
||||||
|
|
||||||
include_open = re.compile(r'''(?<![`\\])(\{\!\s*)([\s'"])''')
|
include_open = re.compile(r'''(?<![`\\])(\{\!\s*)([\s'"])''')
|
||||||
include_quoted_file = re.compile(
|
include_quoted_file = re.compile(
|
||||||
r'''(['"])(?P<fn>.*?)\1\s+(?P<yml>[\s\S]*?)\s?\!\}''')
|
r'''(['"])(?P<fn>.*?)\1\s+(?P<yml>[\s\S]*?)\s?\!\}''')
|
||||||
@ -138,19 +116,19 @@ disparate languages.
|
|||||||
behavior as compared to `simple`. They are described in this section, with
|
behavior as compared to `simple`. They are described in this section, with
|
||||||
default values in parentheses at the beginning of each entry.
|
default values in parentheses at the beginning of each entry.
|
||||||
|
|
||||||
{! plugin.py ---
|
{! plugin.py extract:
|
||||||
start: '[*]altered_config_scheme'
|
start: '[*]altered_config_scheme'
|
||||||
terminate: '^\s*\)'
|
|
||||||
replace:
|
replace:
|
||||||
- ["\\('(.*)',\\s*$", '\1\n']
|
- ["\\('(.*)',\\s*$", '\1\n']
|
||||||
- ['config_options.Type.*?default=([^\)]*)', ': (\1)']
|
- ['config_options.Type.*?default=([^\)]*)', ': (\1)']
|
||||||
- '^\s*#(.*\s*)$'
|
- '^\s*#(.*\s*)$'
|
||||||
|
terminate: '^\s*\)'
|
||||||
!}
|
!}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
super_sdict = dict(SimplePlugin.config_scheme)
|
super_sdict = dict(SimplePlugin.config_scheme)
|
||||||
super_semi_dflt = super_sdict['semiliterate'].default
|
super_semi_dflt = super_sdict['semiliterate'].default
|
||||||
semi_dflt = [b if r'\*' not in b['stop'] else dict(b, pattern=r'\.')
|
semi_dflt = [b if 'js' not in b['pattern'] else dict(b, pattern=r'\.')
|
||||||
for b in super_semi_dflt]
|
for b in super_semi_dflt]
|
||||||
altered_config_scheme = dict(
|
altered_config_scheme = dict(
|
||||||
super_sdict,
|
super_sdict,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
name = mkdocs-semiliterate
|
name = mkdocs-semiliterate
|
||||||
version = 0.0.10
|
version = 0.0.11
|
||||||
|
|
||||||
[options]
|
[options]
|
||||||
packages = mkdocs_semiliterate
|
packages = mkdocs_semiliterate
|
||||||
|
2
tests/fixtures/recursive-inclusion/baz.qux
vendored
2
tests/fixtures/recursive-inclusion/baz.qux
vendored
@ -2,7 +2,7 @@ I'd like you to know that
|
|||||||
really just about anything can go up here.
|
really just about anything can go up here.
|
||||||
START right here, because everything else on this line is ignored:
|
START right here, because everything else on this line is ignored:
|
||||||
| file
|
| file
|
||||||
in{! xyzzy start: '(.*)' !}ion
|
in{! xyzzy extract: {start: '(.*)'} !}ion
|
||||||
STOP that distraction!
|
STOP that distraction!
|
||||||
Now we can get back to our originally
|
Now we can get back to our originally
|
||||||
scheduled qux.
|
scheduled qux.
|
||||||
|
7
tests/fixtures/recursive-inclusion/foo.bar
vendored
7
tests/fixtures/recursive-inclusion/foo.bar
vendored
@ -12,9 +12,10 @@ Point: This should be ignored by semiliterate extraction.
|
|||||||
---
|
---
|
||||||
And other features, such as extraction resumption.
|
And other features, such as extraction resumption.
|
||||||
|
|
||||||
Not to mention{! baz.qux start: START
|
Not to mention{! baz.qux extract:
|
||||||
terminate: STOP
|
start: START
|
||||||
replace: ['^\|(.*)$'] !}syntax and `{! escaped syntax !}`.
|
replace: ['^\|(.*)$']
|
||||||
|
terminate: STOP !}syntax and `{! escaped syntax !}`.
|
||||||
---
|
---
|
||||||
|
|
||||||
Unfortunate: the bar language has no real structure
|
Unfortunate: the bar language has no real structure
|
||||||
|
@ -7,8 +7,7 @@ plugins:
|
|||||||
copy_standard_markdown: true
|
copy_standard_markdown: true
|
||||||
semiliterate:
|
semiliterate:
|
||||||
- pattern: '(\.bar)$'
|
- pattern: '(\.bar)$'
|
||||||
start: '---'
|
extract: {start: '---', stop: '---'}
|
||||||
stop: '---'
|
|
||||||
terminate: '!!!'
|
terminate: '!!!'
|
||||||
nav:
|
nav:
|
||||||
- About: README.md
|
- About: README.md
|
||||||
|
Loading…
Reference in New Issue
Block a user