git.iko.soy/typeable/pandoc
on master help sign in
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.

commit64b77cc2c5aa9db5432f616f49a660ec9dbbcc9f authorAlbert Krewinkel <albert@zeitkraut.de> dateThu 13 Oct 2016, 08:46 (10 years ago) parentcbeb72d
1 file changed+11
src/Text/Pandoc/Shared.hs+11
src/Text/Pandoc/Shared.hs+11
@@ -64,6 +64,7 @@ module Text.Pandoc.Shared (
6464 compactify,
6565 compactify',
6666 compactify'DL,
67+ linesToPara,
6768 Element (..),
6869 hierarchicalize,
6970 uniqueIdent,
@@ -630,6 +631,15 @@ compactify'DL items =
630631 | otherwise -> items
631632 _ -> items
632633
634+-- | Combine a list of lines by adding hard linebreaks.
635+combineLines :: [[Inline]] -> [Inline]
636+combineLines = intercalate [LineBreak]
637+
638+-- | Convert a list of lines into a paragraph with hard line breaks. This is
639+-- useful e.g. for rudimentary support of LineBlock elements in writers.
640+linesToPara :: [[Inline]] -> Block
641+linesToPara = Para . combineLines
642+
633643isPara :: Block -> Bool
634644isPara (Para _) = True
635645isPara _ = False
@@ -1035,6 +1045,7 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories
10351045blockToInlines :: Block -> [Inline]
10361046blockToInlines (Plain ils) = ils
10371047blockToInlines (Para ils) = ils
1048+blockToInlines (LineBlock lns) = combineLines lns
10381049blockToInlines (CodeBlock attr str) = [Code attr str]
10391050blockToInlines (RawBlock fmt str) = [RawInline fmt str]
10401051blockToInlines (BlockQuote blks) = blocksToInlines blks