diff --git a/pidgy/compat/markdown.ipynb b/pidgy/compat/markdown.ipynb index 130797a0..6669ec1e 100644 --- a/pidgy/compat/markdown.ipynb +++ b/pidgy/compat/markdown.ipynb @@ -65,8 +65,12 @@ " quote, length = self.QUOTES[self.QUOTES[0] in str], len(str)\n", " left, right = length - len(str.lstrip()), len(str.rstrip())\n", " if not str[left:right].strip(): return str\n", - " while str[right-1] == '\\\\':\n", - " right -= 1\n", + " if str[right-1] == '\\\\':\n", + " while str[right-1] == '\\\\':\n", + " right -= 1\n", + " else:\n", + " if str[left:right].endswith(quote[0]):\n", + " quote = {\"'''\": '\"\"\"', '\"\"\"': \"'''\"}[quote]\n", " return str[:left] + quote + str[left:right] + quote + trailing + str[right:]\n", "\n", " def measure_base_indent(self, tokens, env):\n", @@ -127,6 +131,15 @@ "## utility functions for parsing and rendering" ] }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + " import doctest" + ] + }, { "cell_type": "code", "execution_count": 4, @@ -156,7 +169,15 @@ " for token in token.children:\n", " code = filter_tangle_tokens(token, code)\n", " else:\n", - " token.type in CODE_TYPES and token not in code and code.append(token)\n", + " if token.type in CODE_TYPES:\n", + " if token.type == \"code_block\":\n", + " while token.content.lstrip().startswith(\">>>\"):\n", + " start, end = next(doctest.DocTestParser._EXAMPLE_RE.finditer(token.content)).span()\n", + " token.map[0] = len(token.content[:end].splitlines())\n", + " token.content = token.content[end:]\n", + " if not token.content.strip(): return code\n", + " if token not in code:\n", + " code.append(token)\n", " if code and (code[-1].type == \"fence\") and code[-1].info:\n", " code.pop(-1)\n", " return code or [\n", diff --git a/pidgy/tangle.ipynb b/pidgy/tangle.ipynb index 6c479ba3..19b0eb7f 100644 --- a/pidgy/tangle.ipynb +++ b/pidgy/tangle.ipynb @@ -308,4 +308,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/pidgy/testing.md b/pidgy/testing.md index fb8c113f..320b6f89 100644 --- a/pidgy/testing.md +++ b/pidgy/testing.md @@ -16,6 +16,7 @@ we formally test code incrementally during interactive computing. visitor = traitlets.Instance('ast.NodeTransformer') results = traitlets.List() trace = traitlets.Any() + update = traitlets.Bool(True) @traitlets.default('trace') def _default_trace(self): @@ -49,8 +50,9 @@ we formally test code incrementally during interactive computing. def stub(self): return self.trace.stub() def post_execute(self): - for test in self.results: - if self.trace.enabled: - with self.trace: test.test() - else: test.test() - test.update() + if self.update: + for test in self.results: + if self.trace.enabled: + with self.trace: test.test() + else: test.test() + test.update()