summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-07-25 20:20:03 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2012-07-25 22:05:06 -0700
commit856aa8c244b86a51d4229bf7c5f3799d231570f7 (patch)
treec1ad40da3b54b859be20a01c8307d1651df7a7af
parent1dba82f25ee17590bf03b00659662240460b7824 (diff)
Moved stateLiterateHaskell to readerLiterateHaskell in Options.
-rw-r--r--Benchmark.hs12
-rw-r--r--src/Tests/Readers/Markdown.hs3
-rw-r--r--src/Text/Pandoc.hs12
-rw-r--r--src/Text/Pandoc/Options.hs30
-rw-r--r--src/Text/Pandoc/Parsing.hs4
-rw-r--r--src/pandoc.hs7
6 files changed, 39 insertions, 29 deletions
diff --git a/Benchmark.hs b/Benchmark.hs
index e7ff718e5..f47980905 100644
--- a/Benchmark.hs
+++ b/Benchmark.hs
@@ -3,6 +3,7 @@ import Text.Pandoc.Shared (readDataFile, normalize)
import Criterion.Main
import Data.List (isSuffixOf)
import Text.JSON.Generic
+import Data.Default
readerBench :: Pandoc
-> (String, ParserState -> String -> Pandoc)
@@ -18,10 +19,11 @@ readerBench doc (name, reader) =
getLength (Pandoc (Meta a b c) d) =
length a + length b + length c + length d
in bench (name ++ " reader") $ whnf (getLength .
- reader defaultParserState{ stateSmart = True
- , stateStandalone = True
- , stateLiterateHaskell =
- "+lhs" `isSuffixOf` name }) inp
+ reader def{ stateOptions = def{
+ readerSmart = True
+ , readerLiterateHaskell = "+lhs" `isSuffixOf` name
+ }
+ }) inp
writerBench :: Pandoc
-> (String, WriterOptions -> Pandoc -> String)
@@ -38,7 +40,7 @@ normalizeBench doc = [ bench "normalize - with" $ nf (encodeJSON . normalize) do
main = do
inp <- readDataFile (Just ".") "README"
- let ps = defaultParserState{ stateSmart = True }
+ let ps = defaultParserState{ stateOptions = def{ readerSmart = True }}
let doc = readMarkdown ps inp
let readerBs = map (readerBench doc) readers
let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
diff --git a/src/Tests/Readers/Markdown.hs b/src/Tests/Readers/Markdown.hs
index e6612f475..ca7dc457b 100644
--- a/src/Tests/Readers/Markdown.hs
+++ b/src/Tests/Readers/Markdown.hs
@@ -93,7 +93,8 @@ tests = [ testGroup "inline code"
=?> para (note (para "See [^1]"))
]
, testGroup "lhs"
- [ test (readMarkdown defaultParserState{stateLiterateHaskell = True})
+ [ test (readMarkdown def{stateOptions =
+ def{readerLiterateHaskell = True}})
"inverse bird tracks and html" $
"> a\n\n< b\n\n<div>\n"
=?> codeBlockWith ("",["sourceCode","literate","haskell"],[]) "a"
diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs
index 193755dff..95fec7360 100644
--- a/src/Text/Pandoc.hs
+++ b/src/Text/Pandoc.hs
@@ -170,16 +170,22 @@ readers = [("native" , \_ -> readNative)
,("json" , \_ -> decodeJSON)
,("markdown" , readMarkdown)
,("markdown+lhs" , \st ->
- readMarkdown st{ stateLiterateHaskell = True})
+ readMarkdown st{ stateOptions =
+ let oldopts = stateOptions st
+ in oldopts{ readerLiterateHaskell = True} })
,("rst" , readRST)
,("rst+lhs" , \st ->
- readRST st{ stateLiterateHaskell = True})
+ readRST st{ stateOptions =
+ let oldopts = stateOptions st
+ in oldopts{ readerLiterateHaskell = True} })
,("docbook" , readDocBook)
,("textile" , readTextile) -- TODO : textile+lhs
,("html" , readHtml)
,("latex" , readLaTeX)
,("latex+lhs" , \st ->
- readLaTeX st{ stateLiterateHaskell = True})
+ readLaTeX st{ stateOptions =
+ let oldopts = stateOptions st
+ in oldopts{ readerLiterateHaskell = True} })
]
data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
diff --git a/src/Text/Pandoc/Options.hs b/src/Text/Pandoc/Options.hs
index bd04a4373..063162718 100644
--- a/src/Text/Pandoc/Options.hs
+++ b/src/Text/Pandoc/Options.hs
@@ -51,24 +51,26 @@ data Extension = Footnotes
deriving (Show, Read, Enum, Eq, Ord, Bounded)
data ReaderOptions = ReaderOptions{
- readerExtensions :: Set Extension -- ^ Syntax extensions
- , readerSmart :: Bool -- ^ Smart punctuation
- , readerStrict :: Bool -- ^ FOR TRANSITION ONLY
- , readerParseRaw :: Bool -- ^ Parse raw HTML, LaTeX
- , readerColumns :: Int -- ^ Number of columns in terminal
- , readerTabStop :: Int -- ^ Tab stop
- , readerOldDashes :: Bool -- ^ Use pandoc <= 1.8.2.1 behavior
+ readerExtensions :: Set Extension -- ^ Syntax extensions
+ , readerSmart :: Bool -- ^ Smart punctuation
+ , readerStrict :: Bool -- ^ FOR TRANSITION ONLY
+ , readerParseRaw :: Bool -- ^ Parse raw HTML, LaTeX
+ , readerColumns :: Int -- ^ Number of columns in terminal
+ , readerTabStop :: Int -- ^ Tab stop
+ , readerOldDashes :: Bool -- ^ Use pandoc <= 1.8.2.1 behavior
-- in parsing dashes; -- is em-dash;
-- - before numerial is en-dash
+ , readerLiterateHaskell :: Bool -- ^ Interpret as literate Haskell
} deriving (Show, Read)
instance Default ReaderOptions
where def = ReaderOptions{
- readerExtensions = Set.fromList [minBound..maxBound]
- , readerSmart = False
- , readerStrict = False
- , readerParseRaw = False
- , readerColumns = 80
- , readerTabStop = 4
- , readerOldDashes = False
+ readerExtensions = Set.fromList [minBound..maxBound]
+ , readerSmart = False
+ , readerStrict = False
+ , readerParseRaw = False
+ , readerColumns = 80
+ , readerTabStop = 4
+ , readerOldDashes = False
+ , readerLiterateHaskell = False
}
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index 9c553a9ed..a266c527e 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -395,7 +395,7 @@ failIfStrict = getOption readerStrict >>= guard . not
-- | Fail unless we're in literate haskell mode.
failUnlessLHS :: Parsec [tok] ParserState ()
-failUnlessLHS = getState >>= guard . stateLiterateHaskell
+failUnlessLHS = getOption readerLiterateHaskell >>= guard
-- | Parses backslash, then applies character parser.
escaped :: Parsec [Char] st Char -- ^ Parser for character to escape
@@ -698,7 +698,6 @@ data ParserState = ParserState
stateTitle :: [Inline], -- ^ Title of document
stateAuthors :: [[Inline]], -- ^ Authors of document
stateDate :: [Inline], -- ^ Date of document
- stateLiterateHaskell :: Bool, -- ^ Treat input as literate haskell
stateHeaderTable :: [HeaderType], -- ^ Ordered list of header types used
stateIndentedCodeClasses :: [String], -- ^ Classes to use for indented code blocks
stateNextExample :: Int, -- ^ Number of next example
@@ -726,7 +725,6 @@ defaultParserState =
stateTitle = [],
stateAuthors = [],
stateDate = [],
- stateLiterateHaskell = False,
stateHeaderTable = [],
stateIndentedCodeClasses = [],
stateNextExample = 1,
diff --git a/src/pandoc.hs b/src/pandoc.hs
index ba8c19dad..884e851f9 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -936,9 +936,7 @@ main = do
then "."
else takeDirectory (head sources)
- let startParserState = def{ stateLiterateHaskell = "+lhs" `isSuffixOf` readerName' ||
- lhsExtension sources,
- stateCitations = map CSL.refId refs,
+ let startParserState = def{ stateCitations = map CSL.refId refs,
stateOptions = def{
readerStrict = strict
, readerSmart = smart || (texLigatures &&
@@ -947,6 +945,9 @@ main = do
, readerColumns = columns
, readerTabStop = tabStop
, readerOldDashes = oldDashes
+ , readerLiterateHaskell =
+ "+lhs" `isSuffixOf` readerName' ||
+ lhsExtension sources
},
stateIndentedCodeClasses = codeBlockClasses,
stateApplyMacros = not laTeXOutput