diff options
Diffstat (limited to 'Text/Pandoc/Readers/Plain.hs')
-rw-r--r-- | Text/Pandoc/Readers/Plain.hs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/Text/Pandoc/Readers/Plain.hs b/Text/Pandoc/Readers/Plain.hs index 600e5f8..cb8fb9b 100644 --- a/Text/Pandoc/Readers/Plain.hs +++ b/Text/Pandoc/Readers/Plain.hs @@ -6,15 +6,24 @@ Portability : portable -} {-# LANGUAGE OverloadedStrings #-} -module Text.Pandoc.Readers.Plain ( readPlain ) where +module Text.Pandoc.Readers.Plain ( readPlain + , lineToInlines + ) where import Text.Pandoc.Definition import Text.Pandoc.Error -import Data.List + + +-- | Translates a text line into a list of 'Inline' elements suitable +-- for further processing. +lineToInlines :: String -> [Inline] +lineToInlines [] = [] +lineToInlines (' ':rest) = Space : lineToInlines rest +lineToInlines s = let (cur, next) = break (== ' ') s + in Str cur : lineToInlines next -- | Reads plain text, always succeeding and producing a single -- 'Plain' block. readPlain :: String -> Either PandocError Pandoc readPlain = Right . Pandoc mempty . pure . Plain . - concatMap (\l -> (intersperse Space $ map Str $ words l) ++ [LineBreak]) . lines - -- or Right . Pandoc mempty . pure . RawBlock "plain" + concatMap (\l -> (lineToInlines l) ++ [LineBreak]) . lines |