blob: 3e6a69a3a8726b88e98ea1724b4d3506985b1453 (
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
30
31
|
{- |
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.Class
import qualified Data.Text as T
-- | 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 :: PandocMonad m => T.Text -> m Pandoc
readPlain = pure . Pandoc mempty . pure . Plain .
concatMap (\l -> (lineToInlines $ T.unpack l) ++ [LineBreak])
. T.lines . T.filter (/= '\r')
|