2929from markdown .extensions import Extension
3030from markdown .preprocessors import Preprocessor
3131
32- INC_SYNTAX = re .compile (r'{!\s*(.+?)\s*!((\blines\b)=([0-9 -]+))?\}' )
32+ INC_SYNTAX = re .compile (r'([ \t]*)\{!\s*(.+?)\s*!((\blines\b)=([0-9 -]+))?\}' )
33+ # INC_SYNTAX = re.compile(r'([ \t]*)\{!\s*(.+?)\s*!\}')
3334HEADING_SYNTAX = re .compile ( '^#+' )
3435
3536
@@ -83,7 +84,8 @@ def run(self, lines):
8384 m = INC_SYNTAX .search (line )
8485
8586 if m :
86- filename = m .group (1 )
87+ tabs = m .group (1 )
88+ filename = m .group (2 )
8789 filename = os .path .expanduser (filename )
8890 if not os .path .isabs (filename ):
8991 filename = os .path .normpath (
@@ -92,6 +94,8 @@ def run(self, lines):
9294 try :
9395 with open (filename , 'r' , encoding = self .encoding ) as r :
9496 original_text = r .readlines ()
97+ if len (tabs ):
98+ original_text = [tabs + line for line in original_text ]
9599
96100 except Exception as e :
97101 if not self .throwException :
@@ -101,10 +105,10 @@ def run(self, lines):
101105 break
102106 else :
103107 raise e
104- if m .group (2 ) is None :
108+ if m .group (3 ) is None :
105109 text = original_text
106110 else :
107- lines_str = m .group (4 )
111+ lines_str = m .group (5 )
108112 lines_blocks = lines_str .split ()
109113 wanted_lines = []
110114 for block in lines_blocks :
@@ -158,7 +162,8 @@ def run(self, lines):
158162 text [i ] = text [i ].rstrip ('\r \n ' )
159163
160164 text [0 ] = line_split [0 ] + text [0 ]
161- text [- 1 ] = text [- 1 ] + line_split [5 ]
165+ # text[-1] = text[-1] + line_split[5]
166+ text [- 1 ] = text [- 1 ] + line_split [- 1 ]
162167 lines = lines [:loc ] + text + lines [loc + 1 :]
163168 break
164169
0 commit comments