Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-21 16:42:57 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-26 04:53:52 +0300
commitc4b20a82eac46334b29fe5c37104f5a22c3ef9e5 (patch)
tree98a16d8cd7e3ea314f6850a5ca3c349162d8c13a /utils/doclinter.py
parent6e795a05beb79a6bc8fa8453f37512b4887c13af (diff)
doclinter: Ignore large code-block and long interpreted text
Diffstat (limited to 'utils/doclinter.py')
-rw-r--r--utils/doclinter.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/utils/doclinter.py b/utils/doclinter.py
index 3f711bfa5..af310f720 100644
--- a/utils/doclinter.py
+++ b/utils/doclinter.py
@@ -15,6 +15,9 @@ from typing import List
MAX_LINE_LENGTH = 100
+LONG_INTERPRETED_TEXT = re.compile(r'^\s*\W*(:(\w+:)+)?`.*`\W*$')
+CODE_BLOCK_DIRECTIVE = re.compile(r'^(\s*)\.\. code-block::')
+LEADING_SPACES = re.compile(r'^(\s*)')
def lint(path: str) -> int:
@@ -22,13 +25,28 @@ def lint(path: str) -> int:
document = f.readlines()
errors = 0
+ in_code_block = False
+ code_block_depth = 0
for i, line in enumerate(document):
if line.endswith(' '):
print('%s:%d: the line ends with whitespace.' %
(path, i + 1))
errors += 1
- if len(line) > MAX_LINE_LENGTH:
+ matched = CODE_BLOCK_DIRECTIVE.match(line)
+ if matched:
+ in_code_block = True
+ code_block_depth = len(matched.group(1))
+ elif in_code_block:
+ if line.strip() == '':
+ pass
+ else:
+ spaces = LEADING_SPACES.match(line).group(1)
+ if len(spaces) < code_block_depth:
+ in_code_block = False
+ elif LONG_INTERPRETED_TEXT.match(line):
+ pass
+ elif len(line) > MAX_LINE_LENGTH:
if re.match(r'^\s*\.\. ', line):
# ignore directives and hyperlink targets
pass