Skip to content

merge #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ You can use this to include lines in a different order than the original file. B
also means that if you want to preserve the original order, you have to pay attention
to the order in which you specify the lines.

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.
Expand Down
15 changes: 10 additions & 5 deletions markdown_include/include.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from markdown.extensions import Extension
from markdown.preprocessors import Preprocessor

INC_SYNTAX = re.compile(r'{!\s*(.+?)\s*!((\blines\b)=([0-9 -]+))?\}')
INC_SYNTAX = re.compile(r'([ \t]*)\{!\s*(.+?)\s*!((\blines\b)=([0-9 -]+))?\}')
# INC_SYNTAX = re.compile(r'([ \t]*)\{!\s*(.+?)\s*!\}')
HEADING_SYNTAX = re.compile( '^#+' )


Expand Down Expand Up @@ -83,7 +84,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(
Expand All @@ -92,6 +94,8 @@ def run(self, lines):
try:
with open(filename, 'r', encoding=self.encoding) as r:
original_text = r.readlines()
if len(tabs):
original_text = [tabs+line for line in original_text]

except Exception as e:
if not self.throwException:
Expand All @@ -101,10 +105,10 @@ def run(self, lines):
break
else:
raise e
if m.group(2) is None:
if m.group(3) is None:
text = original_text
else:
lines_str = m.group(4)
lines_str = m.group(5)
lines_blocks = lines_str.split()
wanted_lines = []
for block in lines_blocks:
Expand Down Expand Up @@ -158,7 +162,8 @@ def run(self, lines):
text[i] = text[i].rstrip('\r\n')

text[0] = line_split[0] + text[0]
text[-1] = text[-1] + line_split[5]
# text[-1] = text[-1] + line_split[5]
text[-1] = text[-1] + line_split[-1]
lines = lines[:loc] + text + lines[loc+1:]
break

Expand Down