diff --git a/README.md b/README.md index 6efbab3..a1ff052 100644 --- a/README.md +++ b/README.md @@ -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). +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). + ## Rationale diff --git a/mkdocs.yml b/mkdocs.yml index f1450b9..b79e254 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -12,21 +12,23 @@ plugins: include_extensions: [LICENSE] report_docs_build: true extract_standard_markdown: + extract: replace: [['^(.*).*(.*\s*)$', '\1\2\3']] semiliterate: - - pattern: '(\.py)$' - start: '"""\smd' - stop: '"""' + - pattern: '\.py$' + extract: {start: '"""\smd', stop: '"""'} - pattern: '.drone.yml' destination: 'drone_develop.md' - start: '### develop' - stop: '^\s*###' - replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$'] + extract: + start: '### develop' + stop: '^\s*###' + replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$'] - pattern: '.drone.yml' destination: 'drone_install.md' - start: '### install' - stop: '^\s*###' - replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$'] + extract: + start: '### install' + stop: '^\s*###' + replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$'] markdown_extensions: - abbr - def_list diff --git a/mkdocs_semiliterate/plugin.py b/mkdocs_semiliterate/plugin.py index 78a9bbc..9e24926 100644 --- a/mkdocs_semiliterate/plugin.py +++ b/mkdocs_semiliterate/plugin.py @@ -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'''(?.*?)\1\s+(?P[\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, diff --git a/setup.cfg b/setup.cfg index 22926a2..c734d18 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = mkdocs-semiliterate -version = 0.0.10 +version = 0.0.11 [options] packages = mkdocs_semiliterate diff --git a/tests/fixtures/recursive-inclusion/baz.qux b/tests/fixtures/recursive-inclusion/baz.qux index 2ee818c..7826096 100644 --- a/tests/fixtures/recursive-inclusion/baz.qux +++ b/tests/fixtures/recursive-inclusion/baz.qux @@ -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. diff --git a/tests/fixtures/recursive-inclusion/foo.bar b/tests/fixtures/recursive-inclusion/foo.bar index 7045796..3c32a0c 100644 --- a/tests/fixtures/recursive-inclusion/foo.bar +++ b/tests/fixtures/recursive-inclusion/foo.bar @@ -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 diff --git a/tests/fixtures/recursive-inclusion/mkdocs.yml b/tests/fixtures/recursive-inclusion/mkdocs.yml index 151026f..c442e43 100644 --- a/tests/fixtures/recursive-inclusion/mkdocs.yml +++ b/tests/fixtures/recursive-inclusion/mkdocs.yml @@ -7,8 +7,7 @@ plugins: copy_standard_markdown: true semiliterate: - pattern: '(\.bar)$' - start: '---' - stop: '---' + extract: {start: '---', stop: '---'} terminate: '!!!' nav: - About: README.md