From 0f1cec89ee03e2fed3ac8883e76838b6a5f3dfd4 Mon Sep 17 00:00:00 2001 From: Maxim Belkin Date: Thu, 6 May 2021 11:12:34 -0500 Subject: [PATCH] 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. --- bin/lesson_check.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/lesson_check.py b/bin/lesson_check.py index 39ed1976..2216fa70 100644 --- a/bin/lesson_check.py +++ b/bin/lesson_check.py @@ -56,6 +56,9 @@ # Pattern to match {% include ... %} statements P_INTERNAL_INCLUDE_LINK = re.compile(r'^{% include ([^ ]*) %}$') +# Pattern to match image-only and link-only lines +P_LINK_IMAGE_LINE = re.compile("^[> ]*(!?)\[([^]]+)\][([]([^)]+)[])][ ]*$") + # What kinds of blockquotes are allowed? KNOWN_BLOCKQUOTES = { 'callout', @@ -376,12 +379,19 @@ def check_line_lengths(self): """Check the raw text of the lesson body.""" if self.args.line_lengths: - over = [i for (i, l, n) in self.lines if ( - n > MAX_LINE_LEN) and (not l.startswith('!'))] - self.reporter.check(not over, + over_limit = [] + + for (i, l, n) in self.lines: + # Report lines that are longer than the suggested + # line length limit only if they're not + # link-only or image-only lines. + if n > MAX_LINE_LEN and not P_LINK_IMAGE_LINE.match(l): + over_limit.append(i) + + self.reporter.check(not over_limit, self.filename, 'Line(s) too long: {0}', - ', '.join([str(i) for i in over])) + ', '.join([str(i) for i in over_limit])) def check_trailing_whitespace(self): """Check for whitespace at the ends of lines."""