Skip to content

Commit 2d710ab

Browse files
authored
Merge pull request #68 from AnswerDotAI/ansi_fix
Ansi fix
2 parents bbb44d9 + 6d05569 commit 2d710ab

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

execnb/shell.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ def render_outputs(outputs, ansi_renderer=_strip, include_imgs=True, pygments=Fa
170170
def render_output(out):
171171
otype = out['output_type']
172172
if otype == 'stream':
173-
txt = ansi_renderer(''.join(out['text']))
173+
txt = ansi_renderer(''.join(out["text"]))
174174
xtra = '' if out['name']=='stdout' else "class='stderr'"
175-
return f"<pre {xtra}><code>{txt}</code></pre>"
175+
is_err = '<span class' in txt
176+
return f"<pre {xtra}><code class='{'nohighlight hljs' if is_err else ''}'>{txt}</code></pre>"
176177
elif otype in ('display_data','execute_result'):
177178
data = out['data']
178179
_g = lambda t: ''.join(data[t]) if t in data else None

nbs/02_shell.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,9 +986,10 @@
986986
" def render_output(out):\n",
987987
" otype = out['output_type']\n",
988988
" if otype == 'stream':\n",
989-
" txt = ansi_renderer(''.join(out['text']))\n",
989+
" txt = ansi_renderer(''.join(out[\"text\"]))\n",
990990
" xtra = '' if out['name']=='stdout' else \"class='stderr'\"\n",
991-
" return f\"<pre {xtra}><code>{txt}</code></pre>\"\n",
991+
" is_err = '<span class' in txt\n",
992+
" return f\"<pre {xtra}><code class='{'nohighlight hljs' if is_err else ''}'>{txt}</code></pre>\"\n",
992993
" elif otype in ('display_data','execute_result'):\n",
993994
" data = out['data']\n",
994995
" _g = lambda t: ''.join(data[t]) if t in data else None\n",

0 commit comments

Comments
 (0)