From 10f73a48280b36c194ef596a9dbe88d9b1c72a28 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Thu, 11 Feb 2021 21:35:58 -0800 Subject: [PATCH 1/7] feat: interpret usual backslash escapes in quoted include filename --- mkdocs_semiliterate/plugin.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mkdocs_semiliterate/plugin.py b/mkdocs_semiliterate/plugin.py index e366576..42c07a9 100644 --- a/mkdocs_semiliterate/plugin.py +++ b/mkdocs_semiliterate/plugin.py @@ -91,9 +91,12 @@ is checked for `{! ... !}`. # OK, we have found (the start of) an inclusion and must process it preamble = line[:include_match.start()] remainder = line[include_match.end(1):] + doublequoted = False body_pattern = StreamInclusion.include_quoted_file if include_match[2].isspace(): body_pattern = StreamInclusion.include_bare_file + elif include_match[2] == '"': + doublequoted = True body_match = body_pattern.search(remainder) if not body_match: for extra_line in self.input_stream: @@ -105,7 +108,12 @@ is checked for `{! ... !}`. errmsg = "semiliterate: End of file while scanning for `!}`" utils.log.error(errmsg) raise EOFError(errmsg) - include_path = self.include_root + '/' + body_match['fn'] + filename = body_match['fn'] + if doublequoted: + filename = (filename.encode('latin-1', 'backslashreplace') + .decode('unicode-escape')) + include_path = self.include_root + '/' + filename + print(f"Including |{include_path}|") new_root = re.match(r'(.*)/', include_path)[1] try: include_parameters = yaml.safe_load(body_match['yml']) -- 2.34.1 From 898ebdc97b44db49931efaf8b2f9736a25859f5d Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Thu, 11 Feb 2021 21:39:04 -0800 Subject: [PATCH 2/7] test: Make sure quoted filenames with escaped chars work --- tests/fixtures/quoted-filename/README.md | 7 + tests/fixtures/quoted-filename/mkdocs.yml | 6 + .../fixtures/quoted-filename/refsite/404.html | 103 ++++++ .../quoted-filename/refsite/croppedindex.html | 120 +++++++ .../quoted-filename/refsite/css/base.css | 313 ++++++++++++++++++ .../refsite/css/bootstrap.min.css | 12 + .../refsite/css/font-awesome.min.css | 4 + .../quoted-filename/snippet/Say \"Don't\"" | 1 + 8 files changed, 566 insertions(+) create mode 100644 tests/fixtures/quoted-filename/README.md create mode 100644 tests/fixtures/quoted-filename/mkdocs.yml create mode 100644 tests/fixtures/quoted-filename/refsite/404.html create mode 100644 tests/fixtures/quoted-filename/refsite/croppedindex.html create mode 100644 tests/fixtures/quoted-filename/refsite/css/base.css create mode 100644 tests/fixtures/quoted-filename/refsite/css/bootstrap.min.css create mode 100644 tests/fixtures/quoted-filename/refsite/css/font-awesome.min.css create mode 100644 "tests/fixtures/quoted-filename/snippet/Say \"Don't\"" diff --git a/tests/fixtures/quoted-filename/README.md b/tests/fixtures/quoted-filename/README.md new file mode 100644 index 0000000..751c4da --- /dev/null +++ b/tests/fixtures/quoted-filename/README.md @@ -0,0 +1,7 @@ +# Test of quoted inclusion + +Hopefully we see + +{! "snippet/Say \"Don\'t\"" !} + +here. diff --git a/tests/fixtures/quoted-filename/mkdocs.yml b/tests/fixtures/quoted-filename/mkdocs.yml new file mode 100644 index 0000000..bd3e416 --- /dev/null +++ b/tests/fixtures/quoted-filename/mkdocs.yml @@ -0,0 +1,6 @@ +site_name: Full inclusion +docs_dir: refsite # dummy +plugins: +- semiliterate: + ignore_folders: [refsite, snippet] + merge_docs_dir: false diff --git a/tests/fixtures/quoted-filename/refsite/404.html b/tests/fixtures/quoted-filename/refsite/404.html new file mode 100644 index 0000000..a5b03b3 --- /dev/null +++ b/tests/fixtures/quoted-filename/refsite/404.html @@ -0,0 +1,103 @@ + + + + + + + + + + + Full inclusion + + + + + + + + + + + + + + +
+
+ +
+
+

404

+

Page not found

+
+
+ + +
+
+ +
+
+

Documentation built with MkDocs.

+
+ + + + + + + diff --git a/tests/fixtures/quoted-filename/refsite/croppedindex.html b/tests/fixtures/quoted-filename/refsite/croppedindex.html new file mode 100644 index 0000000..328fde1 --- /dev/null +++ b/tests/fixtures/quoted-filename/refsite/croppedindex.html @@ -0,0 +1,120 @@ + + + + + + + + + + + Full inclusion + + + + + + + + + + + + + + +
+
+
+
+ +

Test of quoted inclusion

+

Hopefully we see

+

Shh... quiet world.

+

here.

+
+
+ +
+
+

Documentation built with MkDocs.

+
+ + + + + + + + + + + + + +
+
+ +
+
+

404

+

Page not found

+
+
+ + +
+
+ +
+
+

Documentation built with MkDocs.

+
+ + + + + + + diff --git a/tests/fixtures/git-inclusion/refsite/croppedindex.html b/tests/fixtures/git-inclusion/refsite/croppedindex.html new file mode 100644 index 0000000..c8c2f48 --- /dev/null +++ b/tests/fixtures/git-inclusion/refsite/croppedindex.html @@ -0,0 +1,128 @@ + + + + + + + + + + + Full inclusion + + + + + + + + + + + + + + +
+
+
+
+ +

Test of git extraction

+

Hopefully we see

+
      stop: '^\s*###'
+      replace: ['^# (.*\s*)$', '^\s*-(.*\s*)$']
+
+

markdown_extensions: +- abbr +- def_list +theme: + name: readthedocs +docs_dir: mkdocs_semiliterate # dummy

+

here.

+
+
+ +
+
+

Documentation built with MkDocs.

+
+ + + + + + + + +