2011-01-19 18:36:27 -08:00
|
|
|
{-
|
2014-05-08 21:50:20 +02:00
|
|
|
Copyright (C) 2011-2014 John MacFarlane <jgm@berkeley.edu>
|
2011-01-19 18:36:27 -08:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
-}
|
|
|
|
|
|
|
|
{- |
|
|
|
|
Module : Text.Pandoc.Readers.Native
|
2014-05-08 21:50:20 +02:00
|
|
|
Copyright : Copyright (C) 2011-2014 John MacFarlane
|
2012-07-26 22:32:53 -07:00
|
|
|
License : GNU GPL, version 2 or above
|
2011-01-19 18:36:27 -08:00
|
|
|
|
|
|
|
Maintainer : John MacFarlane <jgm@berkeley.edu>
|
|
|
|
Stability : alpha
|
|
|
|
Portability : portable
|
|
|
|
|
2011-01-21 09:00:05 -08:00
|
|
|
Conversion of a string representation of a pandoc type (@Pandoc@,
|
|
|
|
@[Block]@, @Block@, @[Inline]@, or @Inline@) to a @Pandoc@ document.
|
2011-01-19 18:36:27 -08:00
|
|
|
-}
|
|
|
|
module Text.Pandoc.Readers.Native ( readNative ) where
|
|
|
|
|
|
|
|
import Text.Pandoc.Definition
|
2012-08-09 08:11:28 -07:00
|
|
|
import Text.Pandoc.Shared (safeRead)
|
2011-01-19 18:36:27 -08:00
|
|
|
|
|
|
|
-- | Read native formatted text and return a Pandoc document.
|
|
|
|
-- The input may be a full pandoc document, a block list, a block,
|
|
|
|
-- an inline list, or an inline. Thus, for example,
|
|
|
|
--
|
|
|
|
-- > Str "hi"
|
|
|
|
--
|
|
|
|
-- will be treated as if it were
|
|
|
|
--
|
2013-05-10 22:53:35 -07:00
|
|
|
-- > Pandoc nullMeta [Plain [Str "hi"]]
|
2011-01-19 18:36:27 -08:00
|
|
|
--
|
|
|
|
readNative :: String -- ^ String to parse (assuming @'\n'@ line endings)
|
|
|
|
-> Pandoc
|
|
|
|
readNative s =
|
2012-08-09 08:11:28 -07:00
|
|
|
case safeRead s of
|
|
|
|
Just d -> d
|
|
|
|
Nothing -> Pandoc nullMeta $ readBlocks s
|
2011-01-19 18:36:27 -08:00
|
|
|
|
|
|
|
readBlocks :: String -> [Block]
|
|
|
|
readBlocks s =
|
2012-08-09 08:11:28 -07:00
|
|
|
case safeRead s of
|
|
|
|
Just d -> d
|
|
|
|
Nothing -> [readBlock s]
|
2011-01-19 18:36:27 -08:00
|
|
|
|
|
|
|
readBlock :: String -> Block
|
|
|
|
readBlock s =
|
2012-08-09 08:11:28 -07:00
|
|
|
case safeRead s of
|
|
|
|
Just d -> d
|
|
|
|
Nothing -> Plain $ readInlines s
|
2011-01-19 18:36:27 -08:00
|
|
|
|
|
|
|
readInlines :: String -> [Inline]
|
|
|
|
readInlines s =
|
2012-08-09 08:11:28 -07:00
|
|
|
case safeRead s of
|
|
|
|
Just d -> d
|
|
|
|
Nothing -> [readInline s]
|
2011-01-19 18:36:27 -08:00
|
|
|
|
|
|
|
readInline :: String -> Inline
|
|
|
|
readInline s =
|
2012-08-09 08:11:28 -07:00
|
|
|
case safeRead s of
|
|
|
|
Just d -> d
|
|
|
|
Nothing -> error "Cannot parse document"
|
2011-01-19 18:36:27 -08:00
|
|
|
|