git.iko.soy/typeable/pandoc
on master help sign in
Improve filterIpynbOutput.

- Ensure that images are prioritized over text. - Allow multiple RawBlocks for same format.

commit5863e5c75da5dadc8ab92dac62ebc03d566d65b5 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 6 Mar 2019, 10:36 (8 years ago) parent1c4c384
1 file changed+7−4
src/Text/Pandoc/Shared.hs+7−4
src/Text/Pandoc/Shared.hs+7−4
@@ -104,13 +104,12 @@ import Data.Char (isAlpha, isLower, isSpace, isUpper, toLower, isAlphaNum,
104104 generalCategory, GeneralCategory(NonSpacingMark,
105105 SpacingCombiningMark, EnclosingMark, ConnectorPunctuation))
106106import Data.Data (Data, Typeable)
107−import Data.List (find, intercalate, intersperse, stripPrefix, sortBy)
107+import Data.List (find, intercalate, intersperse, stripPrefix)
108108import qualified Data.Map as M
109109import Data.Maybe (mapMaybe)
110110import Data.Sequence (ViewL (..), ViewR (..), viewl, viewr)
111111import qualified Data.Set as Set
112112import qualified Data.Text as T
113−import Data.Ord (comparing)
114113import Data.Version (showVersion)
115114import Network.URI (URI (uriScheme), escapeURIString, parseURI)
116115import Paths_pandoc (version)
@@ -684,8 +683,11 @@ filterIpynbOutput mode = walk go
684683 | fmt == Format "ipynb"
685684 -> Div (ident, ("output":os), kvs) bs
686685 | otherwise -> Div (ident, ("output":os), kvs) $
687− take 1 $ sortBy (comparing rank) bs
688− where
686+ [ b | b <- bs, rank b == highestRank ]
687+ where
688+ highestRank = case map rank bs of
689+ [] -> 0
690+ xs -> maximum xs
689691 rank (RawBlock (Format "html") _)
690692 | fmt == Format "html" = (1 :: Int)
691693 | fmt == Format "markdown" = 2
@@ -697,6 +699,7 @@ filterIpynbOutput mode = walk go
697699 rank (RawBlock f _)
698700 | fmt == f = 1
699701 | otherwise = 3
702+ rank (Para [Image{}]) = 1
700703 rank _ = 2
701704 go x = x
702705