@@ -1,11 +1,10 @@
1−{-# LANGUAGE
2− FlexibleContexts
3−, GeneralizedNewtypeDeriving
4−, TypeSynonymInstances
5−, MultiParamTypeClasses
6−, FlexibleInstances
7−, IncoherentInstances #-}
8−
1+{-# LANGUAGE ExplicitForAll #-}
2+{-# LANGUAGE FlexibleContexts #-}
3+{-# LANGUAGE FlexibleInstances #-}
4+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
5+{-# LANGUAGE IncoherentInstances #-}
6+{-# LANGUAGE MultiParamTypeClasses #-}
7+{-# LANGUAGE TypeSynonymInstances #-}
98{-
109Copyright (C) 2006-2017 John MacFarlane <jgm@berkeley.edu>
1110
@@ -187,34 +186,34 @@ module Text.Pandoc.Parsing ( takeWhileP,
187186 )
188187where
189188
189+import Control.Monad.Identity
190+import Control.Monad.Reader
191+import Data.Char (chr, isAlphaNum, isAscii, isHexDigit, isPunctuation, isSpace,
192+ ord, toLower, toUpper)
193+import Data.Default
194+import Data.List (intercalate, isSuffixOf, transpose)
195+import qualified Data.Map as M
196+import Data.Maybe (catMaybes)
197+import Data.Monoid ((<>))
198+import qualified Data.Set as Set
190199import Data.Text (Text)
200+import Text.HTML.TagSoup.Entity (lookupEntity)
201+import Text.Pandoc.Asciify (toAsciiChar)
202+import Text.Pandoc.Builder (Blocks, HasMeta (..), Inlines, trimInlines)
203+import qualified Text.Pandoc.Builder as B
204+import Text.Pandoc.Class (PandocMonad, readFileFromDirs, report)
191205import Text.Pandoc.Definition
206+import Text.Pandoc.Logging
192207import Text.Pandoc.Options
193−import Text.Pandoc.Builder (Blocks, Inlines, HasMeta(..), trimInlines)
194−import qualified Text.Pandoc.Builder as B
195−import Text.Pandoc.XML (fromEntities)
208+import Text.Pandoc.Readers.LaTeX.Types (Macro)
209+import Text.Pandoc.Shared
196210import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
211+import Text.Pandoc.XML (fromEntities)
197212import Text.Parsec hiding (token)
198−import Text.Parsec.Pos (newPos, initialPos, updatePosString)
199−import Data.Char ( toLower, toUpper, ord, chr, isAscii, isAlphaNum,
200− isHexDigit, isSpace, isPunctuation )
201−import Data.List ( intercalate, transpose, isSuffixOf )
202−import Text.Pandoc.Shared
203−import qualified Data.Map as M
204−import Text.Pandoc.Readers.LaTeX.Types (Macro)
205−import Text.HTML.TagSoup.Entity ( lookupEntity )
206−import Text.Pandoc.Asciify (toAsciiChar)
207−import Data.Monoid ((<>))
208−import Text.Pandoc.Class (PandocMonad, readFileFromDirs, report)
209−import Text.Pandoc.Logging
210−import Data.Default
211−import qualified Data.Set as Set
212−import Control.Monad.Reader
213−import Control.Monad.Identity
214−import Data.Maybe (catMaybes)
213+import Text.Parsec.Pos (initialPos, newPos, updatePosString)
215214
216−import Text.Pandoc.Error
217215import Control.Monad.Except
216+import Text.Pandoc.Error
218217
219218type Parser t s = Parsec t s
220219
@@ -670,9 +669,9 @@ withRaw parser = do
670669 let (l2,c2) = (sourceLine pos2, sourceColumn pos2)
671670 let inplines = take ((l2 - l1) + 1) $ lines inp
672671 let raw = case inplines of
673− [] -> ""
674− [l] -> take (c2 - c1) l
675− ls -> unlines (init ls) ++ take (c2 - 1) (last ls)
672+ [] -> ""
673+ [l] -> take (c2 - c1) l
674+ ls -> unlines (init ls) ++ take (c2 - 1) (last ls)
676675 return (result, raw)
677676
678677-- | Parses backslash, then applies character parser.
@@ -688,11 +687,11 @@ characterReference = try $ do
688687 ent <- many1Till nonspaceChar (char ';')
689688 let ent' = case ent of
690689 '#':'X':xs -> '#':'x':xs -- workaround tagsoup bug
691− '#':_ -> ent
692− _ -> ent ++ ";"
690+ '#':_ -> ent
691+ _ -> ent ++ ";"
693692 case lookupEntity ent' of
694− Just (c : _) -> return c
695− _ -> fail "entity not found"
693+ Just (c : _) -> return c
694+ _ -> fail "entity not found"
696695
697696-- | Parses an uppercase roman numeral and returns (UpperRoman, number).
698697upperRoman :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
@@ -1006,7 +1005,7 @@ removeOneLeadingSpace xs =
10061005 if all startsWithSpace xs
10071006 then map (drop 1) xs
10081007 else xs
1009− where startsWithSpace "" = True
1008+ where startsWithSpace "" = True
10101009 startsWithSpace (y:_) = y == ' '
10111010
10121011-- | Parse footer for a grid table.
@@ -1042,36 +1041,36 @@ testStringWith parser str = UTF8.putStrLn $ show $
10421041
10431042-- | Parsing options.
10441043data ParserState = ParserState
1045− { stateOptions :: ReaderOptions, -- ^ User options
1046− stateParserContext :: ParserContext, -- ^ Inside list?
1047− stateQuoteContext :: QuoteContext, -- ^ Inside quoted environment?
1048− stateAllowLinks :: Bool, -- ^ Allow parsing of links
1049− stateMaxNestingLevel :: Int, -- ^ Max # of nested Strong/Emph
1050− stateLastStrPos :: Maybe SourcePos, -- ^ Position after last str parsed
1051− stateKeys :: KeyTable, -- ^ List of reference keys
1052− stateHeaderKeys :: KeyTable, -- ^ List of implicit header ref keys
1053− stateSubstitutions :: SubstTable, -- ^ List of substitution references
1054− stateNotes :: NoteTable, -- ^ List of notes (raw bodies)
1055− stateNotes' :: NoteTable', -- ^ List of notes (parsed bodies)
1056− stateNoteRefs :: Set.Set String, -- ^ List of note references used
1057− stateMeta :: Meta, -- ^ Document metadata
1058− stateMeta' :: F Meta, -- ^ Document metadata
1059− stateCitations :: M.Map String String, -- ^ RST-style citations
1060− stateHeaderTable :: [HeaderType], -- ^ Ordered list of header types used
1061− stateHeaders :: M.Map Inlines String, -- ^ List of headers and ids (used for implicit ref links)
1062− stateIdentifiers :: Set.Set String, -- ^ Header identifiers used
1063− stateNextExample :: Int, -- ^ Number of next example
1064− stateExamples :: M.Map String Int, -- ^ Map from example labels to numbers
1065− stateMacros :: M.Map Text Macro, -- ^ Table of macros defined so far
1066− stateRstDefaultRole :: String, -- ^ Current rST default interpreted text role
1067− stateRstCustomRoles :: M.Map String (String, Maybe String, Attr), -- ^ Current rST custom text roles
1044+ { stateOptions :: ReaderOptions, -- ^ User options
1045+ stateParserContext :: ParserContext, -- ^ Inside list?
1046+ stateQuoteContext :: QuoteContext, -- ^ Inside quoted environment?
1047+ stateAllowLinks :: Bool, -- ^ Allow parsing of links
1048+ stateMaxNestingLevel :: Int, -- ^ Max # of nested Strong/Emph
1049+ stateLastStrPos :: Maybe SourcePos, -- ^ Position after last str parsed
1050+ stateKeys :: KeyTable, -- ^ List of reference keys
1051+ stateHeaderKeys :: KeyTable, -- ^ List of implicit header ref keys
1052+ stateSubstitutions :: SubstTable, -- ^ List of substitution references
1053+ stateNotes :: NoteTable, -- ^ List of notes (raw bodies)
1054+ stateNotes' :: NoteTable', -- ^ List of notes (parsed bodies)
1055+ stateNoteRefs :: Set.Set String, -- ^ List of note references used
1056+ stateMeta :: Meta, -- ^ Document metadata
1057+ stateMeta' :: F Meta, -- ^ Document metadata
1058+ stateCitations :: M.Map String String, -- ^ RST-style citations
1059+ stateHeaderTable :: [HeaderType], -- ^ Ordered list of header types used
1060+ stateHeaders :: M.Map Inlines String, -- ^ List of headers and ids (used for implicit ref links)
1061+ stateIdentifiers :: Set.Set String, -- ^ Header identifiers used
1062+ stateNextExample :: Int, -- ^ Number of next example
1063+ stateExamples :: M.Map String Int, -- ^ Map from example labels to numbers
1064+ stateMacros :: M.Map Text Macro, -- ^ Table of macros defined so far
1065+ stateRstDefaultRole :: String, -- ^ Current rST default interpreted text role
1066+ stateRstCustomRoles :: M.Map String (String, Maybe String, Attr), -- ^ Current rST custom text roles
10681067 -- Triple represents: 1) Base role, 2) Optional format (only for :raw:
10691068 -- roles), 3) Additional classes (rest of Attr is unused)).
1070− stateCaption :: Maybe Inlines, -- ^ Caption in current environment
1071− stateInHtmlBlock :: Maybe String, -- ^ Tag type of HTML block being parsed
1072− stateFencedDivLevel :: Int, -- ^ Depth of fenced div
1073− stateContainers :: [String], -- ^ parent include files
1074− stateLogMessages :: [LogMessage], -- ^ log messages
1069+ stateCaption :: Maybe Inlines, -- ^ Caption in current environment
1070+ stateInHtmlBlock :: Maybe String, -- ^ Tag type of HTML block being parsed
1071+ stateFencedDivLevel :: Int, -- ^ Depth of fenced div
1072+ stateContainers :: [String], -- ^ parent include files
1073+ stateLogMessages :: [LogMessage], -- ^ log messages
10751074 stateMarkdownAttribute :: Bool -- ^ True if in markdown=1 context
10761075 }
10771076