From 10f73a48280b36c194ef596a9dbe88d9b1c72a28 Mon Sep 17 00:00:00 2001 From: Glen Whitney Date: Thu, 11 Feb 2021 21:35:58 -0800 Subject: [PATCH] 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'])