|
10 | 10 |
|
11 | 11 | """Sphinx rst linter.""" |
12 | 12 |
|
13 | | -__version__ = "0.6.6" |
| 13 | +__version__ = "0.6.7" |
14 | 14 |
|
15 | 15 | import argparse |
16 | 16 | import io |
|
77 | 77 | ) |
78 | 78 |
|
79 | 79 | # fmt: off |
80 | | -DIRECTIVES = [ |
| 80 | +DIRECTIVES_CONTAINING_RST = [ |
81 | 81 | # standard docutils ones |
82 | 82 | 'admonition', 'attention', 'caution', 'class', 'compound', 'container', |
83 | | - 'contents', 'csv-table', 'danger', 'date', 'default-role', 'epigraph', |
84 | | - 'error', 'figure', 'footer', 'header', 'highlights', 'hint', 'image', |
85 | | - 'important', 'include', 'line-block', 'list-table', 'meta', 'note', |
86 | | - 'parsed-literal', 'pull-quote', 'raw', 'replace', |
87 | | - 'restructuredtext-test-directive', 'role', 'rubric', 'sectnum', 'sidebar', |
88 | | - 'table', 'target-notes', 'tip', 'title', 'topic', 'unicode', 'warning', |
| 83 | + 'danger', 'epigraph', 'error', 'figure', 'footer', 'header', 'highlights', |
| 84 | + 'hint', 'image', 'important', 'include', 'line-block', 'list-table', 'meta', |
| 85 | + 'note', 'parsed-literal', 'pull-quote', 'replace', 'sidebar', 'tip', 'topic', |
| 86 | + 'warning', |
89 | 87 | # Sphinx and Python docs custom ones |
90 | 88 | 'acks', 'attribute', 'autoattribute', 'autoclass', 'autodata', |
91 | 89 | 'autoexception', 'autofunction', 'automethod', 'automodule', |
92 | 90 | 'availability', 'centered', 'cfunction', 'class', 'classmethod', 'cmacro', |
93 | | - 'cmdoption', 'cmember', 'code-block', 'confval', 'cssclass', 'ctype', |
| 91 | + 'cmdoption', 'cmember', 'confval', 'cssclass', 'ctype', |
94 | 92 | 'currentmodule', 'cvar', 'data', 'decorator', 'decoratormethod', |
95 | 93 | 'deprecated-removed', 'deprecated(?!-removed)', 'describe', 'directive', |
96 | 94 | 'doctest', 'envvar', 'event', 'exception', 'function', 'glossary', |
97 | 95 | 'highlight', 'highlightlang', 'impl-detail', 'index', 'literalinclude', |
98 | 96 | 'method', 'miscnews', 'module', 'moduleauthor', 'opcode', 'pdbcommand', |
99 | | - 'productionlist', 'program', 'role', 'sectionauthor', 'seealso', |
| 97 | + 'program', 'role', 'sectionauthor', 'seealso', |
100 | 98 | 'sourcecode', 'staticmethod', 'tabularcolumns', 'testcode', 'testoutput', |
101 | 99 | 'testsetup', 'toctree', 'todo', 'todolist', 'versionadded', |
102 | 100 | 'versionchanged', 'c:function', 'coroutinefunction' |
103 | 101 | ] |
| 102 | + |
| 103 | +DIRECTIVES_CONTAINING_ARBITRARY_CONTENT = [ |
| 104 | + # standard docutils ones |
| 105 | + 'contents', 'csv-table', 'date', 'default-role', 'include', 'raw', |
| 106 | + 'restructuredtext-test-directive','role', 'rubric', 'sectnum', 'table', |
| 107 | + 'target-notes', 'title', 'unicode', |
| 108 | + # Sphinx and Python docs custom ones |
| 109 | + 'productionlist', 'code-block', |
| 110 | +] |
| 111 | + |
104 | 112 | # fmt: on |
105 | 113 |
|
106 | 114 |
|
107 | | -ALL_DIRECTIVES = "(" + "|".join(DIRECTIVES) + ")" |
| 115 | +DIRECTIVES_CONTAINING_ARBITRARY_CONTENT_RE = ( |
| 116 | + "(" + "|".join(DIRECTIVES_CONTAINING_ARBITRARY_CONTENT) + ")" |
| 117 | +) |
| 118 | +DIRECTIVES_CONTAINING_RST_RE = "(" + "|".join(DIRECTIVES_CONTAINING_RST) + ")" |
| 119 | +ALL_DIRECTIVES = ( |
| 120 | + "(" |
| 121 | + + "|".join(DIRECTIVES_CONTAINING_RST + DIRECTIVES_CONTAINING_ARBITRARY_CONTENT) |
| 122 | + + ")" |
| 123 | +) |
108 | 124 | BEFORE_ROLE = r"(^|(?<=[\s(/'{\[*-]))" |
109 | 125 | SIMPLENAME = r"(?:(?!_)\w)+(?:[-._+:](?:(?!_)\w)+)*" |
110 | 126 | ROLE_TAG = rf":{SIMPLENAME}:" |
@@ -780,16 +796,18 @@ def check_leaked_markup(file, lines, options=None): |
780 | 796 |
|
781 | 797 | def is_multiline_non_rst_block(line): |
782 | 798 | """Returns True if the next lines are an indented literal block.""" |
783 | | - if line.endswith("..\n"): |
784 | | - return True |
785 | | - if line.endswith("::\n"): |
| 799 | + if re.match(r"^\s*\.\.$", line): # it's the start of a comment block. |
786 | 800 | return True |
787 | | - if re.match(r"^ *\.\. code-block::", line): |
| 801 | + if re.match(rf"^ *\.\. {DIRECTIVES_CONTAINING_RST_RE}::", line): |
| 802 | + return False |
| 803 | + if re.match(rf"^ *\.\. {DIRECTIVES_CONTAINING_ARBITRARY_CONTENT_RE}::", line): |
788 | 804 | return True |
789 | 805 | if re.match(r"^ *.. productionlist::", line): |
790 | 806 | return True |
791 | 807 | if re.match(r"^ *\.\. ", line) and type_of_explicit_markup(line) == "comment": |
792 | 808 | return True |
| 809 | + if line.endswith("::\n"): # It's a literal block |
| 810 | + return True |
793 | 811 | return False |
794 | 812 |
|
795 | 813 |
|
|
0 commit comments