summaryrefslogtreecommitdiff
path: root/Text/Pandoc/Readers/Plain.hs
blob: cb8fb9b2d013f0de00f462f5d9fab871e34e888c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{- |
Module      :  Text.Pandoc.Readers.Plain
Maintainer  :  defanor <defanor@uberspace.net>
Stability   :  unstable
Portability :  portable
-}

{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Readers.Plain ( readPlain
                                 , lineToInlines
                                 ) where

import Text.Pandoc.Definition
import Text.Pandoc.Error


-- | 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 -> (lineToInlines l) ++ [LineBreak]) . lines