Skip to content

Commit 0f1cec8

Browse files
committed
bin/lesson_check.py: allow exceptions to line length limit
Allow lines that contain a single image or a single link to go over the suggested line length limit.
1 parent 5e32b18 commit 0f1cec8

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

bin/lesson_check.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
# Pattern to match {% include ... %} statements
5757
P_INTERNAL_INCLUDE_LINK = re.compile(r'^{% include ([^ ]*) %}$')
5858

59+
# Pattern to match image-only and link-only lines
60+
P_LINK_IMAGE_LINE = re.compile("^[> ]*(!?)\[([^]]+)\][([]([^)]+)[])][ ]*$")
61+
5962
# What kinds of blockquotes are allowed?
6063
KNOWN_BLOCKQUOTES = {
6164
'callout',
@@ -376,12 +379,19 @@ def check_line_lengths(self):
376379
"""Check the raw text of the lesson body."""
377380

378381
if self.args.line_lengths:
379-
over = [i for (i, l, n) in self.lines if (
380-
n > MAX_LINE_LEN) and (not l.startswith('!'))]
381-
self.reporter.check(not over,
382+
over_limit = []
383+
384+
for (i, l, n) in self.lines:
385+
# Report lines that are longer than the suggested
386+
# line length limit only if they're not
387+
# link-only or image-only lines.
388+
if n > MAX_LINE_LEN and not P_LINK_IMAGE_LINE.match(l):
389+
over_limit.append(i)
390+
391+
self.reporter.check(not over_limit,
382392
self.filename,
383393
'Line(s) too long: {0}',
384-
', '.join([str(i) for i in over]))
394+
', '.join([str(i) for i in over_limit]))
385395

386396
def check_trailing_whitespace(self):
387397
"""Check for whitespace at the ends of lines."""

0 commit comments

Comments
 (0)