Skip to content

Commit 78bac72

Browse files
committed
Build: bugfix python script: detect more codeblocks as lintable
1 parent 6e1599f commit 78bac72

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

scripts/python/md-split.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def main():
7474

7575

7676
def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, codedir, name, index, indent_depth):
77-
7877
fenced = (line.strip() == '```')
7978
if fenced:
8079
try:
@@ -94,18 +93,18 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co
9493
if comment_idx >= 0:
9594
no_comment_line = line[:comment_idx]
9695
text_filehandle.write(line[comment_idx + 2:])
97-
if (not has_actual_code
98-
and not line.strip().startswith('//')
99-
and not line.strip().startswith('???')
100-
and not line.strip() ==''):
101-
has_actual_code = True
96+
97+
if (not has_actual_code
98+
and not line.strip().startswith('//')
99+
and not line.strip().startswith('???')
100+
and not line.strip() ==''):
101+
has_actual_code = True
102102
else:
103103
# write empty line so line numbers stay stable
104104
text_filehandle.write('')
105105

106106
if (not line.strip() == '```'):
107-
108-
if ('???' in no_comment_line or '...' in no_comment_line):
107+
if ('???' == no_comment_line or '...' == no_comment_line):
109108
has_question_marks = True
110109
linebuffer.append(dedent(line) if not fenced else line)
111110
try:
@@ -115,10 +114,8 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co
115114
line = ''
116115
break
117116
codefile = os.path.join(codedir, '%s%s.cpp' % (name, index))
118-
119117
if fenced:
120118
text_filehandle.write('')
121-
122119
if (has_actual_code and not has_question_marks):
123120
# add commonly used headers, so that lines can compile
124121
with io.open(codefile, 'w') as code_filehandle:
@@ -145,6 +142,7 @@ def process_code(read_filehandle, text_filehandle, line, linenum, sourcefile, co
145142

146143

147144
def is_code(line, indent_depth = 4):
145+
'''returns the indent depth, 0 means not code in markup'''
148146
if line.startswith(' ' * indent_depth):
149147
return len(line) - len(line.lstrip(' '))
150148
return 0
@@ -171,6 +169,7 @@ def get_marker(line):
171169
namematch = NAMED_A_TAG_REGEX.match(line)
172170
if namematch:
173171
return namematch.group(1) # group 0 is full match
172+
174173
return None
175174

176175
if __name__ == '__main__':

0 commit comments

Comments
 (0)