aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/Ipynb.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-03-29 21:08:00 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-03-29 21:08:00 -0700
commitacab2087bb7ad5ebeaec79e451e95c97da505642 (patch)
tree6859eafc518079b504b02f217be1d9006d6fdb11 /src/Text/Pandoc/Writers/Ipynb.hs
parent93ee73e1dc0405ddf71417d907656c2a8726f133 (diff)
downloadpandoc-acab2087bb7ad5ebeaec79e451e95c97da505642.tar.gz
ipynb writer - consolidate adjacent raw blocks.
Sometimes pandoc creates two HTML blocks, e.g. one for the open tag and one for a close tag. If these aren't consolidated, only one will show up in output cell.
Diffstat (limited to 'src/Text/Pandoc/Writers/Ipynb.hs')
-rw-r--r--src/Text/Pandoc/Writers/Ipynb.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Ipynb.hs b/src/Text/Pandoc/Writers/Ipynb.hs
index f31cc38fd..2a95f669e 100644
--- a/src/Text/Pandoc/Writers/Ipynb.hs
+++ b/src/Text/Pandoc/Writers/Ipynb.hs
@@ -133,7 +133,7 @@ extractCells opts (Div (_id,classes,kvs) xs : bs)
, cellAttachments = Nothing } :) <$> extractCells opts bs
| "cell" `elem` classes
, "raw" `elem` classes =
- case xs of
+ case consolidateAdjacentRawBlocks xs of
[RawBlock (Format f) raw] -> do
let format' =
case f of
@@ -195,7 +195,7 @@ blockToOutput _ = return Nothing
extractData :: PandocMonad m => [Block] -> m (MimeBundle, JSONMeta)
extractData bs = do
- (mmap, meta) <- foldM go mempty bs
+ (mmap, meta) <- foldM go mempty $ consolidateAdjacentRawBlocks bs
return (MimeBundle mmap, meta)
where
go (mmap, meta) b@(Para [Image (_,_,kvs) _ (src,_)]) = do
@@ -227,3 +227,11 @@ pairsToJSONMeta kvs =
| (k,v) <- kvs
, k /= "execution_count"
]
+
+consolidateAdjacentRawBlocks :: [Block] -> [Block]
+consolidateAdjacentRawBlocks [] = []
+consolidateAdjacentRawBlocks (RawBlock f1 x : RawBlock f2 y : xs)
+ | f1 == f2
+ = consolidateAdjacentRawBlocks (RawBlock f1 (x <> "\n" <> y) : xs)
+consolidateAdjacentRawBlocks (x : xs) =
+ x : consolidateAdjacentRawBlocks xs