Files
pandoc/test/command/7744.md
T
Jeremy Levartovsky 8605c4aa6e ipynb: make ANSI escape stripping linear. (#12007)
filterIpynbOutput stripped ANSI escapes from output code blocks by
rebuilding the text one character at a time with T.cons, so time was
quadratic in the length of the output. A notebook with one 32,000-line
stream output took 4.3 s to convert to HTML; the notebooks attached to
#7744 took 42 s. Split at each ESC [ with T.breakOn and join the pieces
once instead. Output is unchanged.

Add test/command/7744.md, since nothing tested the stripping itself.

Closes #7744.
2026-10-28 11:46:04 -07:00

1.3 KiB

ANSI escape sequences are stripped from code in output cells unless the output is ipynb (#5633). This used to take time quadratic in the length of the output (#7744).

% pandoc -f ipynb -t native
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[1;31mError\u001b[0m: café 日本\n",
      "[0m and \u001b(B are kept\n",
      "\u001b[32m\u001b[1mok\u001b[0m\u001b[0m\n",
      "\u001b[2K\n",
      "loading model\n",
      "\u001b[31 \u001b[0m tail\n",
      "\u001b[1\u001b(Bm end\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "cut \u001b[31 at the end"
     ]
    }
   ],
   "source": [
    "print(x)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 5
}
^D
[ Div
    ( ""
    , [ "cell" , "code" ]
    , [ ( "execution_count" , "1" ) ]
    )
    [ CodeBlock ( "" , [ "python" ] , [] ) "print(x)"
    , Div
        ( "" , [ "output" , "stream" , "stdout" ] , [] )
        [ CodeBlock
            ( "" , [] , [] )
            "Error: caf\233 \26085\26412\n[0m and \ESC(B are kept\nok\nodel\n tail\n end\n"
        ]
    , Div
        ( "" , [ "output" , "stream" , "stderr" ] , [] )
        [ CodeBlock ( "" , [] , [] ) "cut " ]
    ]
]