git.iko.soy/typeable/pandoc
on master help sign in
Moved stateLiterateHaskell to readerLiterateHaskell in Options.
856aa8cJohn MacFarlane
Benchmark.hs+7−5
@@ -3,6 +3,7 @@ import Text.Pandoc.Shared (readDataFile, normalize)
3import Criterion.Main
3import Criterion.Main
4import Data.List (isSuffixOf)
4import Data.List (isSuffixOf)
5import Text.JSON.Generic
5import Text.JSON.Generic
6+import Data.Default
6
7
7readerBench :: Pandoc
8readerBench :: Pandoc
8 -> (String, ParserState -> String -> Pandoc)
9 -> (String, ParserState -> String -> Pandoc)
@@ -18,10 +19,11 @@ readerBench doc (name, reader) =
18 getLength (Pandoc (Meta a b c) d) =
19 getLength (Pandoc (Meta a b c) d) =
19 length a + length b + length c + length d
20 length a + length b + length c + length d
20 in bench (name ++ " reader") $ whnf (getLength .
21 in bench (name ++ " reader") $ whnf (getLength .
21− reader defaultParserState{ stateSmart = True
22+ reader def{ stateOptions = def{
22− , stateStandalone = True
23+ readerSmart = True
23− , stateLiterateHaskell =
24− "+lhs" `isSuffixOf` name }) inp
24+ , readerLiterateHaskell = "+lhs" `isSuffixOf` name
25+ }
26+ }) inp
25
27
26writerBench :: Pandoc
28writerBench :: Pandoc
27 -> (String, WriterOptions -> Pandoc -> String)
29 -> (String, WriterOptions -> Pandoc -> String)
@@ -38,7 +40,7 @@ normalizeBench doc = [ bench "normalize - with" $ nf (encodeJSON . normalize) do
38
40
39main = do
41main = do
40 inp <- readDataFile (Just ".") "README"
42 inp <- readDataFile (Just ".") "README"
41− let ps = defaultParserState{ stateSmart = True }
43+ let ps = defaultParserState{ stateOptions = def{ readerSmart = True }}
42 let doc = readMarkdown ps inp
44 let doc = readMarkdown ps inp
43 let readerBs = map (readerBench doc) readers
45 let readerBs = map (readerBench doc) readers
44 let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
46 let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
src/Tests/Readers/Markdown.hs+2−1
@@ -93,7 +93,8 @@ tests = [ testGroup "inline code"
93 =?> para (note (para "See [^1]"))
93 =?> para (note (para "See [^1]"))
94 ]
94 ]
95 , testGroup "lhs"
95 , testGroup "lhs"
96− [ test (readMarkdown defaultParserState{stateLiterateHaskell = True})
96+ [ test (readMarkdown def{stateOptions =
97+ def{readerLiterateHaskell = True}})
97 "inverse bird tracks and html" $
98 "inverse bird tracks and html" $
98 "> a\n\n< b\n\n<div>\n"
99 "> a\n\n< b\n\n<div>\n"
99 =?> codeBlockWith ("",["sourceCode","literate","haskell"],[]) "a"
100 =?> codeBlockWith ("",["sourceCode","literate","haskell"],[]) "a"
src/Text/Pandoc.hs+9−3
@@ -170,16 +170,22 @@ readers = [("native" , \_ -> readNative)
170 ,("json" , \_ -> decodeJSON)
170 ,("json" , \_ -> decodeJSON)
171 ,("markdown" , readMarkdown)
171 ,("markdown" , readMarkdown)
172 ,("markdown+lhs" , \st ->
172 ,("markdown+lhs" , \st ->
173− readMarkdown st{ stateLiterateHaskell = True})
173+ readMarkdown st{ stateOptions =
174+ let oldopts = stateOptions st
175+ in oldopts{ readerLiterateHaskell = True} })
174 ,("rst" , readRST)
176 ,("rst" , readRST)
175 ,("rst+lhs" , \st ->
177 ,("rst+lhs" , \st ->
176− readRST st{ stateLiterateHaskell = True})
178+ readRST st{ stateOptions =
179+ let oldopts = stateOptions st
180+ in oldopts{ readerLiterateHaskell = True} })
177 ,("docbook" , readDocBook)
181 ,("docbook" , readDocBook)
178 ,("textile" , readTextile) -- TODO : textile+lhs
182 ,("textile" , readTextile) -- TODO : textile+lhs
179 ,("html" , readHtml)
183 ,("html" , readHtml)
180 ,("latex" , readLaTeX)
184 ,("latex" , readLaTeX)
181 ,("latex+lhs" , \st ->
185 ,("latex+lhs" , \st ->
182− readLaTeX st{ stateLiterateHaskell = True})
186+ readLaTeX st{ stateOptions =
187+ let oldopts = stateOptions st
188+ in oldopts{ readerLiterateHaskell = True} })
183 ]
189 ]
184
190
185data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
191data Writer = PureStringWriter (WriterOptions -> Pandoc -> String)
src/Text/Pandoc/Options.hs+16−14
@@ -51,24 +51,26 @@ data Extension = Footnotes
51 deriving (Show, Read, Enum, Eq, Ord, Bounded)
51 deriving (Show, Read, Enum, Eq, Ord, Bounded)
52
52
53data ReaderOptions = ReaderOptions{
53data ReaderOptions = ReaderOptions{
54− readerExtensions :: Set Extension -- ^ Syntax extensions
54+ readerExtensions :: Set Extension -- ^ Syntax extensions
55− , readerSmart :: Bool -- ^ Smart punctuation
55+ , readerSmart :: Bool -- ^ Smart punctuation
56− , readerStrict :: Bool -- ^ FOR TRANSITION ONLY
56+ , readerStrict :: Bool -- ^ FOR TRANSITION ONLY
57− , readerParseRaw :: Bool -- ^ Parse raw HTML, LaTeX
57+ , readerParseRaw :: Bool -- ^ Parse raw HTML, LaTeX
58− , readerColumns :: Int -- ^ Number of columns in terminal
58+ , readerColumns :: Int -- ^ Number of columns in terminal
59− , readerTabStop :: Int -- ^ Tab stop
59+ , readerTabStop :: Int -- ^ Tab stop
60− , readerOldDashes :: Bool -- ^ Use pandoc <= 1.8.2.1 behavior
60+ , readerOldDashes :: Bool -- ^ Use pandoc <= 1.8.2.1 behavior
61 -- in parsing dashes; -- is em-dash;
61 -- in parsing dashes; -- is em-dash;
62 -- - before numerial is en-dash
62 -- - before numerial is en-dash
63+ , readerLiterateHaskell :: Bool -- ^ Interpret as literate Haskell
63} deriving (Show, Read)
64} deriving (Show, Read)
64
65
65instance Default ReaderOptions
66instance Default ReaderOptions
66 where def = ReaderOptions{
67 where def = ReaderOptions{
67− readerExtensions = Set.fromList [minBound..maxBound]
68+ readerExtensions = Set.fromList [minBound..maxBound]
68− , readerSmart = False
69+ , readerSmart = False
69− , readerStrict = False
70+ , readerStrict = False
70− , readerParseRaw = False
71+ , readerParseRaw = False
71− , readerColumns = 80
72+ , readerColumns = 80
72− , readerTabStop = 4
73+ , readerTabStop = 4
73− , readerOldDashes = False
74+ , readerOldDashes = False
75+ , readerLiterateHaskell = False
74 }
76 }
src/Text/Pandoc/Parsing.hs+1−3
@@ -395,7 +395,7 @@ failIfStrict = getOption readerStrict >>= guard . not
395
395
396-- | Fail unless we're in literate haskell mode.
396-- | Fail unless we're in literate haskell mode.
397failUnlessLHS :: Parsec [tok] ParserState ()
397failUnlessLHS :: Parsec [tok] ParserState ()
398−failUnlessLHS = getState >>= guard . stateLiterateHaskell
398+failUnlessLHS = getOption readerLiterateHaskell >>= guard
399
399
400-- | Parses backslash, then applies character parser.
400-- | Parses backslash, then applies character parser.
401escaped :: Parsec [Char] st Char -- ^ Parser for character to escape
401escaped :: Parsec [Char] st Char -- ^ Parser for character to escape
@@ -698,7 +698,6 @@ data ParserState = ParserState
698 stateTitle :: [Inline], -- ^ Title of document
698 stateTitle :: [Inline], -- ^ Title of document
699 stateAuthors :: [[Inline]], -- ^ Authors of document
699 stateAuthors :: [[Inline]], -- ^ Authors of document
700 stateDate :: [Inline], -- ^ Date of document
700 stateDate :: [Inline], -- ^ Date of document
701− stateLiterateHaskell :: Bool, -- ^ Treat input as literate haskell
702 stateHeaderTable :: [HeaderType], -- ^ Ordered list of header types used
701 stateHeaderTable :: [HeaderType], -- ^ Ordered list of header types used
703 stateIndentedCodeClasses :: [String], -- ^ Classes to use for indented code blocks
702 stateIndentedCodeClasses :: [String], -- ^ Classes to use for indented code blocks
704 stateNextExample :: Int, -- ^ Number of next example
703 stateNextExample :: Int, -- ^ Number of next example
@@ -726,7 +725,6 @@ defaultParserState =
726 stateTitle = [],
725 stateTitle = [],
727 stateAuthors = [],
726 stateAuthors = [],
728 stateDate = [],
727 stateDate = [],
729− stateLiterateHaskell = False,
730 stateHeaderTable = [],
728 stateHeaderTable = [],
731 stateIndentedCodeClasses = [],
729 stateIndentedCodeClasses = [],
732 stateNextExample = 1,
730 stateNextExample = 1,
src/pandoc.hs+4−3
@@ -936,9 +936,7 @@ main = do
936 then "."
936 then "."
937 else takeDirectory (head sources)
937 else takeDirectory (head sources)
938
938
939− let startParserState = def{ stateLiterateHaskell = "+lhs" `isSuffixOf` readerName' ||
940− lhsExtension sources,
941− stateCitations = map CSL.refId refs,
939+ let startParserState = def{ stateCitations = map CSL.refId refs,
942 stateOptions = def{
940 stateOptions = def{
943 readerStrict = strict
941 readerStrict = strict
944 , readerSmart = smart || (texLigatures &&
942 , readerSmart = smart || (texLigatures &&
@@ -947,6 +945,9 @@ main = do
947 , readerColumns = columns
945 , readerColumns = columns
948 , readerTabStop = tabStop
946 , readerTabStop = tabStop
949 , readerOldDashes = oldDashes
947 , readerOldDashes = oldDashes
948+ , readerLiterateHaskell =
949+ "+lhs" `isSuffixOf` readerName' ||
950+ lhsExtension sources
950 },
951 },
951 stateIndentedCodeClasses = codeBlockClasses,
952 stateIndentedCodeClasses = codeBlockClasses,
952 stateApplyMacros = not laTeXOutput
953 stateApplyMacros = not laTeXOutput