aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-03-06 10:36:03 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2019-03-06 10:36:03 -0800
commit5863e5c75da5dadc8ab92dac62ebc03d566d65b5 (patch)
treed390802450680429387843c1d03d120a82fe234b /src/Text/Pandoc
parent1c4c384a622ee5db7aea0d6d3d2f10f8ada891f1 (diff)
downloadpandoc-5863e5c75da5dadc8ab92dac62ebc03d566d65b5.tar.gz
Improve filterIpynbOutput.
- Ensure that images are prioritized over text. - Allow multiple RawBlocks for same format.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Shared.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 0e1c115ee..a4f4927f9 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -104,13 +104,12 @@ import Data.Char (isAlpha, isLower, isSpace, isUpper, toLower, isAlphaNum,
generalCategory, GeneralCategory(NonSpacingMark,
SpacingCombiningMark, EnclosingMark, ConnectorPunctuation))
import Data.Data (Data, Typeable)
-import Data.List (find, intercalate, intersperse, stripPrefix, sortBy)
+import Data.List (find, intercalate, intersperse, stripPrefix)
import qualified Data.Map as M
import Data.Maybe (mapMaybe)
import Data.Sequence (ViewL (..), ViewR (..), viewl, viewr)
import qualified Data.Set as Set
import qualified Data.Text as T
-import Data.Ord (comparing)
import Data.Version (showVersion)
import Network.URI (URI (uriScheme), escapeURIString, parseURI)
import Paths_pandoc (version)
@@ -684,8 +683,11 @@ filterIpynbOutput mode = walk go
| fmt == Format "ipynb"
-> Div (ident, ("output":os), kvs) bs
| otherwise -> Div (ident, ("output":os), kvs) $
- take 1 $ sortBy (comparing rank) bs
- where
+ [ b | b <- bs, rank b == highestRank ]
+ where
+ highestRank = case map rank bs of
+ [] -> 0
+ xs -> maximum xs
rank (RawBlock (Format "html") _)
| fmt == Format "html" = (1 :: Int)
| fmt == Format "markdown" = 2
@@ -697,6 +699,7 @@ filterIpynbOutput mode = walk go
rank (RawBlock f _)
| fmt == f = 1
| otherwise = 3
+ rank (Para [Image{}]) = 1
rank _ = 2
go x = x