From 5e385d0744764cc22c66af898ed11859df0b6225 Mon Sep 17 00:00:00 2001 From: Quentin Carbonneaux Date: Thu, 7 May 2020 12:26:37 +0200 Subject: Cleanup formatting in .. coqtop:: directives --- doc/tools/coqrst/coqdoc/main.py | 22 +++++----------------- 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"(?<=(?