summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Shared.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-12-02 15:21:59 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2017-12-02 15:21:59 -0800
commit7b8c2b6691e3816ba52ee07ee7f63573d4ae7253 (patch)
treef201d4e69ce4d86911d845ef63094c9ba4f7688b /src/Text/Pandoc/Shared.hs
parente09e6a6ffaf1c61747f1e2d87b025a61bd0ee90e (diff)
Add --strip-empty-paragraphs option.
This works for any input format.
Diffstat (limited to 'src/Text/Pandoc/Shared.hs')
-rw-r--r--src/Text/Pandoc/Shared.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index 5c13e0acb..1c3a25cc7 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -72,6 +72,7 @@ module Text.Pandoc.Shared (
inlineListToIdentifier,
isHeaderBlock,
headerShift,
+ stripEmptyParagraphs,
isTightList,
addMetaField,
makeMeta,
@@ -529,6 +530,14 @@ headerShift n = walk shift
shift (Header level attr inner) = Header (level + n) attr inner
shift x = x
+-- | Remove empty paragraphs.
+stripEmptyParagraphs :: Pandoc -> Pandoc
+stripEmptyParagraphs = walk go
+ where go :: [Block] -> [Block]
+ go = filter (not . isEmptyParagraph)
+ isEmptyParagraph (Para []) = True
+ isEmptyParagraph _ = False
+
-- | Detect if a list is tight.
isTightList :: [[Block]] -> Bool
isTightList = all firstIsPlain