From 981384c6f7134d9b9f465833256941ebb42770e5 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Sat, 9 Jan 2021 08:42:00 -0800 Subject: [PATCH] feat: Make the `start` parameter to a semiliterate pattern optional Resolves #4. --- mkdocs.yml | 1 - mkdocs_semiliterate/plugin.py | 24 ++++++++++++++++++++++++ setup.cfg | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mkdocs.yml b/mkdocs.yml index 49cb8f4..2330344 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -12,7 +12,6 @@ plugins: include_extensions: [LICENSE] semiliterate: - pattern: '(\.md)$' - start: '^(.*\s*)' replace: [['^(.*).*(.*\s*)$', '\1\2\3']] - pattern: '(\.py)$' start: '"""\smd' diff --git a/mkdocs_semiliterate/plugin.py b/mkdocs_semiliterate/plugin.py index bdc3829..f1079d0 100644 --- a/mkdocs_semiliterate/plugin.py +++ b/mkdocs_semiliterate/plugin.py @@ -49,6 +49,30 @@ 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. + """ + self.start_hot = False + if 'start' not in kwargs: + kwargs['start'] = 'dummy' + self.start_hot = True + super().__init__(input_stream, output_stream, **kwargs) + + def extract(self): + if self.start_hot: + self.extracting = True + self.start = False + super().extract() + include_open = re.compile(r'''(?.*?)\1\s+(?P[\s\S]*?)\s\!\}''') diff --git a/setup.cfg b/setup.cfg index c43a2af..665b8c7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = mkdocs-semiliterate -version = 0.0.5 +version = 0.0.7 [options] packages = mkdocs_semiliterate