From 23324d782b9a83349437e98128251bcf5d5bc73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Barnaba=CC=81s?= Date: Fri, 2 Jul 2021 15:01:58 +0200 Subject: [PATCH 1/5] tries to fix tabs --- markdown_include/include.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/markdown_include/include.py b/markdown_include/include.py index 5463cd5..f3c25ce 100644 --- a/markdown_include/include.py +++ b/markdown_include/include.py @@ -29,7 +29,7 @@ from markdown.extensions import Extension from markdown.preprocessors import Preprocessor -INC_SYNTAX = re.compile(r'\{!\s*(.+?)\s*!\}') +INC_SYNTAX = re.compile(r'(\w+)\{!\s*(.+?)\s*!\}') HEADING_SYNTAX = re.compile( '^#+' ) @@ -83,7 +83,8 @@ def run(self, lines): m = INC_SYNTAX.search(line) if m: - filename = m.group(1) + tabs = m.group(1) + filename = m.group(2) filename = os.path.expanduser(filename) if not os.path.isabs(filename): filename = os.path.normpath( @@ -92,6 +93,8 @@ def run(self, lines): try: with open(filename, 'r', encoding=self.encoding) as r: text = r.readlines() + if len(tabs): + text = [tabs+line for line in text] except Exception as e: if not self.throwException: From 631eefe2996827b73b848e5182373a2eb44b4840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Barnaba=CC=81s?= Date: Fri, 2 Jul 2021 15:05:10 +0200 Subject: [PATCH 2/5] tries to fix --- markdown_include/include.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown_include/include.py b/markdown_include/include.py index f3c25ce..cefa1da 100644 --- a/markdown_include/include.py +++ b/markdown_include/include.py @@ -29,7 +29,7 @@ from markdown.extensions import Extension from markdown.preprocessors import Preprocessor -INC_SYNTAX = re.compile(r'(\w+)\{!\s*(.+?)\s*!\}') +INC_SYNTAX = re.compile(r'(\s*)\{!\s*(.+?)\s*!\}') HEADING_SYNTAX = re.compile( '^#+' ) From 4bc29cdd19bf287eb29af4a5039da71e4cf32ec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Barnaba=CC=81s?= Date: Fri, 2 Jul 2021 15:11:16 +0200 Subject: [PATCH 3/5] fixes bug: filename was included --- markdown_include/include.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown_include/include.py b/markdown_include/include.py index cefa1da..8be99ea 100644 --- a/markdown_include/include.py +++ b/markdown_include/include.py @@ -121,7 +121,7 @@ def run(self, lines): text[i] = text[i].rstrip('\r\n') text[0] = line_split[0] + text[0] - text[-1] = text[-1] + line_split[2] + text[-1] = text[-1] + line_split[-1] lines = lines[:loc] + text + lines[loc+1:] break From f491c2557bdc43216427853fce6c94f8784bf011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Barnaba=CC=81s?= Date: Fri, 2 Jul 2021 15:14:10 +0200 Subject: [PATCH 4/5] restricts leading whitespace to tab and space --- markdown_include/include.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdown_include/include.py b/markdown_include/include.py index 8be99ea..634bca0 100644 --- a/markdown_include/include.py +++ b/markdown_include/include.py @@ -29,7 +29,7 @@ from markdown.extensions import Extension from markdown.preprocessors import Preprocessor -INC_SYNTAX = re.compile(r'(\s*)\{!\s*(.+?)\s*!\}') +INC_SYNTAX = re.compile(r'([ \t]*)\{!\s*(.+?)\s*!\}') HEADING_SYNTAX = re.compile( '^#+' ) From d830fa56691046a49ecd0219db89940af76f165c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Barnaba=CC=81s?= Date: Fri, 2 Jul 2021 15:19:05 +0200 Subject: [PATCH 5/5] updates readme with the new feature. --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index ea9cc54..df90775 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,10 @@ Markdown is being called. If you would like to change the directory relative to which paths are evaluated, then this can be done by specifying the extension setting ``base_path``. +If there are leading tabs and spaces before the include statement, +all the lines of the included file get prepended the same number of tabs, +so includes to indented sections get automatically indented. + ## Configuration The following settings can be specified when initialising the plugin.