From 8e282fa90c7b159bc93e725a1d529c935b67c73b Mon Sep 17 00:00:00 2001 From: Thibault Kruse Date: Sat, 10 Sep 2016 09:05:44 +0900 Subject: [PATCH] Minor fix to python code extractor, dedent by indentation amount --- scripts/python/md-split.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/python/md-split.py b/scripts/python/md-split.py index fb147e9..21af9d9 100755 --- a/scripts/python/md-split.py +++ b/scripts/python/md-split.py @@ -105,7 +105,7 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co if (not line.strip() == '```'): if ('???' == no_comment_line or '...' == no_comment_line): has_question_marks = True - linebuffer.append(dedent(line) if not fenced else line) + linebuffer.append(dedent(line, indent_depth) if not fenced else line) try: line = read_filehandle.next() linenum += 1 @@ -147,7 +147,7 @@ def is_code(line, indent_depth = 4): return 0 def is_inside_code(line, indent_depth): - return is_code(line, indent_depth) or line.strip() == '' + return is_code(line, indent_depth) > 0 or line.strip() == '' def stripped(line): # Remove well-formed html tags, fixing mistakes by legitimate users @@ -155,9 +155,9 @@ def stripped(line): sline = re.sub('[()\[\]#*]', ' ', line) return sline -def dedent(line): - if line.startswith(' '): - return line[4:] +def dedent(line, indent_depth): + if line.startswith(' ' * indent_depth): + return line[indent_depth:] if line.startswith('\t'): return line[1:] return line