From 64b77cc2c5aa9db5432f616f49a660ec9dbbcc9f Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Thu, 13 Oct 2016 08:46:38 +0200 Subject: Shared: add function combining lines using LineBreak The `linesToBlock` function takes a list of lines and combines them by appending a hard `LineBreak` to each line and concatenating the result, putting the result it into a `Para`. This is most useful when dealing when converting `LineBlock` elements. --- src/Text/Pandoc/Shared.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 04752a194..7e9d0f62b 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -64,6 +64,7 @@ module Text.Pandoc.Shared ( compactify, compactify', compactify'DL, + linesToPara, Element (..), hierarchicalize, uniqueIdent, @@ -630,6 +631,15 @@ compactify'DL items = | otherwise -> items _ -> items +-- | Combine a list of lines by adding hard linebreaks. +combineLines :: [[Inline]] -> [Inline] +combineLines = intercalate [LineBreak] + +-- | Convert a list of lines into a paragraph with hard line breaks. This is +-- useful e.g. for rudimentary support of LineBlock elements in writers. +linesToPara :: [[Inline]] -> Block +linesToPara = Para . combineLines + isPara :: Block -> Bool isPara (Para _) = True isPara _ = False @@ -1035,6 +1045,7 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories blockToInlines :: Block -> [Inline] blockToInlines (Plain ils) = ils blockToInlines (Para ils) = ils +blockToInlines (LineBlock lns) = combineLines lns blockToInlines (CodeBlock attr str) = [Code attr str] blockToInlines (RawBlock fmt str) = [RawInline fmt str] blockToInlines (BlockQuote blks) = blocksToInlines blks -- cgit v1.2.3