git.iko.soy/typeable/pandoc
on master help sign in
Make filterIpynbOutput strip ANSI escapes from code in output...
5454aadJohn MacFarlane
src/Text/Pandoc/Shared.hs+10−1
@@ -688,7 +688,8 @@ splitSentences xs =
688
688
689-- | Process ipynb output cells. If mode is Nothing,
689-- | Process ipynb output cells. If mode is Nothing,
690-- remove all output. If mode is Just format, select
690-- remove all output. If mode is Just format, select
691−-- best output for the format.
691+-- best output for the format. If format is not ipynb,
692+-- strip out ANSI escape sequences from CodeBlocks (see #5633).
692filterIpynbOutput :: Maybe Format -> Pandoc -> Pandoc
693filterIpynbOutput :: Maybe Format -> Pandoc -> Pandoc
693filterIpynbOutput mode = walk go
694filterIpynbOutput mode = walk go
694 where go (Div (ident, ("output":os), kvs) bs) =
695 where go (Div (ident, ("output":os), kvs) bs) =
@@ -699,6 +700,7 @@ filterIpynbOutput mode = walk go
699 | fmt == Format "ipynb"
700 | fmt == Format "ipynb"
700 -> Div (ident, ("output":os), kvs) bs
701 -> Div (ident, ("output":os), kvs) bs
701 | otherwise -> Div (ident, ("output":os), kvs) $
702 | otherwise -> Div (ident, ("output":os), kvs) $
703+ walk removeANSI $
702 take 1 $ sortBy (comparing rank) bs
704 take 1 $ sortBy (comparing rank) bs
703 where
705 where
704 rank (RawBlock (Format "html") _)
706 rank (RawBlock (Format "html") _)
@@ -714,6 +716,13 @@ filterIpynbOutput mode = walk go
714 | otherwise = 3
716 | otherwise = 3
715 rank (Para [Image{}]) = 1
717 rank (Para [Image{}]) = 1
716 rank _ = 2
718 rank _ = 2
719+ removeANSI (CodeBlock attr code) =
720+ CodeBlock attr (removeANSIEscapes code)
721+ removeANSI x = x
722+ removeANSIEscapes [] = []
723+ removeANSIEscapes ('\x1b':'[':cs) =
724+ removeANSIEscapes (drop 1 $ dropWhile (/='m') cs)
725+ removeANSIEscapes (c:cs) = c : removeANSIEscapes cs
717 go x = x
726 go x = x
718
727
719--
728--