refactor: Adjust again to latest 'simple' commit
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

Now with even less code!
This commit is contained in:
Glen Whitney 2021-01-15 09:44:25 -08:00
parent 5a1f9e044a
commit d0904e40cb
7 changed files with 27 additions and 46 deletions

View File

@ -1,6 +1,7 @@
# 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

View File

@ -12,18 +12,20 @@ plugins:
include_extensions: [LICENSE]
report_docs_build: true
extract_standard_markdown:
extract:
replace: [['^(.*)<!-- repo: -->.*<!-- site:(.*?) -->(.*\s*)$', '\1\2\3']]
semiliterate:
- pattern: '(\.py)$'
start: '"""\smd'
stop: '"""'
- pattern: '\.py$'
extract: {start: '"""\smd', stop: '"""'}
- pattern: '.drone.yml'
destination: 'drone_develop.md'
extract:
start: '### develop'
stop: '^\s*###'
replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$']
- pattern: '.drone.yml'
destination: 'drone_install.md'
extract:
start: '### install'
stop: '^\s*###'
replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$']

View File

@ -41,36 +41,14 @@ is interpolated at the current location in the file currently being written.
Recursive inclusion is supported.
Note that the `{! ... !}` directive must be in lines that semiliterate would
normally copy. That is, it does not examine lines before the `start` regexp
is encountered, or after the `terminate` regexp, or between instances of
`stop` and `start`. It also doesn't check any text written from lines that
match these special expressions. Moreover, on such normally-transcribed lines,
normally copy. That is, it does not examine lines after the `terminate` regexp,
or when no mode of extraction is active. It also doesn't check any text written
from lines that match these special expressions like `start` and `stop`.
Moreover, on such normally-transcribed lines,
it's the text **after** the application of any semiliterate `replace`ments that
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_quoted_file = re.compile(
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
default values in parentheses at the beginning of each entry.
{! plugin.py ---
{! plugin.py extract:
start: '[*]altered_config_scheme'
terminate: '^\s*\)'
replace:
- ["\\('(.*)',\\s*$", '\1\n']
- ['config_options.Type.*?default=([^\)]*)', ': (\1)']
- '^\s*#(.*\s*)$'
terminate: '^\s*\)'
!}
"""
super_sdict = dict(SimplePlugin.config_scheme)
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]
altered_config_scheme = dict(
super_sdict,

View File

@ -1,6 +1,6 @@
[metadata]
name = mkdocs-semiliterate
version = 0.0.10
version = 0.0.11
[options]
packages = mkdocs_semiliterate

View File

@ -2,7 +2,7 @@ I'd like you to know that
really just about anything can go up here.
START right here, because everything else on this line is ignored:
| file
in{! xyzzy start: '(.*)' !}ion
in{! xyzzy extract: {start: '(.*)'} !}ion
STOP that distraction!
Now we can get back to our originally
scheduled qux.

View File

@ -12,9 +12,10 @@ Point: This should be ignored by semiliterate extraction.
---
And other features, such as extraction resumption.
Not to mention{! baz.qux start: START
terminate: STOP
replace: ['^\|(.*)$'] !}syntax and `{! escaped syntax !}`.
Not to mention{! baz.qux extract:
start: START
replace: ['^\|(.*)$']
terminate: STOP !}syntax and `{! escaped syntax !}`.
---
Unfortunate: the bar language has no real structure

View File

@ -7,8 +7,7 @@ plugins:
copy_standard_markdown: true
semiliterate:
- pattern: '(\.bar)$'
start: '---'
stop: '---'
extract: {start: '---', stop: '---'}
terminate: '!!!'
nav:
- About: README.md