diff options
| author | Quentin Carbonneaux | 2020-05-07 12:26:37 +0200 |
|---|---|---|
| committer | Quentin Carbonneaux | 2020-05-07 13:01:13 +0200 |
| commit | 5e385d0744764cc22c66af898ed11859df0b6225 (patch) | |
| tree | 3f36aa372aad7906dea6732f2b73d063a5fc56e8 /doc | |
| parent | 2dd59422a4f2ba1d6e75e710b88129751379aa79 (diff) | |
Cleanup formatting in .. coqtop:: directives
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/tools/coqrst/coqdoc/main.py | 22 | ||||
| -rw-r--r-- | doc/tools/coqrst/coqdomain.py | 14 |
2 files changed, 16 insertions, 20 deletions
diff --git a/doc/tools/coqrst/coqdoc/main.py b/doc/tools/coqrst/coqdoc/main.py index a3fc069e6c..9a12d5e6f8 100644 --- a/doc/tools/coqrst/coqdoc/main.py +++ b/doc/tools/coqrst/coqdoc/main.py @@ -48,28 +48,16 @@ def coqdoc(coq_code, coqdoc_bin=None): finally: os.remove(filename) -def is_whitespace_string(elem): - return isinstance(elem, NavigableString) and elem.strip() == "" - -def strip_soup(soup, pred): - """Strip elements matching pred from front and tail of soup.""" - while soup.contents and pred(soup.contents[-1]): - soup.contents.pop() - - skip = 0 - for elem in soup.contents: - if not pred(elem): - break - skip += 1 - - soup.contents[:] = soup.contents[skip:] - def lex(source): """Convert source into a stream of (css_classes, token_string).""" coqdoc_output = coqdoc(source) soup = BeautifulSoup(coqdoc_output, "html.parser") root = soup.find(class_='code') - strip_soup(root, is_whitespace_string) + if root.children: + # strip the leading '\n' + first = next(root.children) + if isinstance(first, NavigableString) and first.string[0] == '\n': + first.string.replace_with(first.string[1:]) for elem in root.children: if isinstance(elem, NavigableString): yield [], elem diff --git a/doc/tools/coqrst/coqdomain.py b/doc/tools/coqrst/coqdomain.py index 9d51d2198a..253fc5283f 100644 --- a/doc/tools/coqrst/coqdomain.py +++ b/doc/tools/coqrst/coqdomain.py @@ -905,9 +905,17 @@ class CoqtopBlocksTransform(Transform): return isinstance(node, nodes.Element) and 'coqtop_options' in node @staticmethod - def split_sentences(source): + def split_sentences(node): """Split Coq sentences in source. Could be improved.""" - return re.split(r"(?<=(?<!\.)\.)\s+", source) + lines = map(lambda s: s.rstrip(), node.rawsource.splitlines()) + out = [""] + for l in lines: + out[-1] = out[-1] + l + "\n" + if l.endswith("."): + out.append("") + if out[-1] == "": + out.pop() + return out @staticmethod def parse_options(node): @@ -986,7 +994,7 @@ class CoqtopBlocksTransform(Transform): repl.sendone('Unset Coqtop Exit On Error.') if options['warn']: repl.sendone('Set Warnings "default".') - for sentence in self.split_sentences(node.rawsource): + for sentence in self.split_sentences(node): pairs.append((sentence, repl.sendone(sentence))) if options['abort']: repl.sendone('Abort All.') |
