@@ -112,12 +112,6 @@ litChar = escapedChar'
112 <|> noneOf "\n"
112 <|> noneOf "\n"
113 <|> (newline >> notFollowedBy blankline >> return ' ')
113 <|> (newline >> notFollowedBy blankline >> return ' ')
115−-- | Fail unless we're at beginning of a line.
116−failUnlessBeginningOfLine :: Parser [tok] st ()
117−failUnlessBeginningOfLine = do
119− if sourceColumn pos == 1 then return () else fail "not beginning of line"
121-- | Parse a sequence of inline elements between square brackets,
115-- | Parse a sequence of inline elements between square brackets,
122-- including inlines between balanced pairs of square brackets.
116-- including inlines between balanced pairs of square brackets.
123inlinesInBalancedBrackets :: Parser [Char] ParserState Inline
117inlinesInBalancedBrackets :: Parser [Char] ParserState Inline
@@ -165,7 +159,7 @@ dateLine = try $ do
166titleBlock :: Parser [Char] ParserState ([Inline], [[Inline]], [Inline])
160titleBlock :: Parser [Char] ParserState ([Inline], [[Inline]], [Inline])
167titleBlock = try $ do
161titleBlock = try $ do
168− failIfStrict
162+ guardEnabled Ext_pandoc_title_blocks
169 title <- option [] titleLine
163 title <- option [] titleLine
170 author <- option [] authorsLine
164 author <- option [] authorsLine
171 date <- option [] dateLine
165 date <- option [] dateLine
@@ -181,10 +175,10 @@ parseMarkdown = do
181 startPos <- getPosition
175 startPos <- getPosition
182 -- go through once just to get list of reference keys and notes
176 -- go through once just to get list of reference keys and notes
183 -- docMinusKeys is the raw document with blanks where the keys/notes were...
177 -- docMinusKeys is the raw document with blanks where the keys/notes were...
185 let firstPassParser = referenceKey
178 let firstPassParser = referenceKey
186− <|> (if readerStrict (stateOptions st) then mzero else noteBlock)
179+ <|> (guardEnabled Ext_footnotes >> noteBlock)
180+ <|> (guardEnabled Ext_delimited_code_blocks >>
187− <|> liftM snd (withRaw codeBlockDelimited)
181+ liftM snd (withRaw codeBlockDelimited))
188 <|> lineClump
182 <|> lineClump
189 docMinusKeys <- liftM concat $ manyTill firstPassParser eof
183 docMinusKeys <- liftM concat $ manyTill firstPassParser eof
190 setInput docMinusKeys
184 setInput docMinusKeys
@@ -292,35 +286,22 @@ parseBlocks :: Parser [Char] ParserState [Block]
292parseBlocks = manyTill block eof
286parseBlocks = manyTill block eof
294block :: Parser [Char] ParserState Block
288block :: Parser [Char] ParserState Block
297− choice (if readerStrict (stateOptions st)
308− else [ codeBlockDelimited
289+block = choice [ codeBlockDelimited
309− , macro
290+ , guardEnabled Ext_latex_macros >> macro
310− , header
291+ , header
312− , codeBlockIndented
293+ , codeBlockIndented
313− , lhsCodeBlock
294+ , lhsCodeBlock
314− , blockQuote
295+ , blockQuote
316− , bulletList
297+ , bulletList
317− , orderedList
298+ , orderedList
318− , definitionList
299+ , definitionList
319− , rawTeXBlock
300+ , rawTeXBlock
321− , rawHtmlBlocks
302+ , htmlBlock
323− , nullBlock ]) <?> "block"
304+ , nullBlock ] <?> "block"
326-- header blocks
307-- header blocks
@@ -431,8 +412,9 @@ keyValAttr = try $ do
431 <|> many nonspaceChar
412 <|> many nonspaceChar
432 return ("",[],[(key,val)])
413 return ("",[],[(key,val)])
434−codeBlockDelimited :: Parser [Char] st Block
415+codeBlockDelimited :: Parser [Char] ParserState Block
435codeBlockDelimited = try $ do
416codeBlockDelimited = try $ do
417+ guardEnabled Ext_delimited_code_blocks
436 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
418 (size, attr, c) <- blockDelimiter (\c -> c == '~' || c == '`') Nothing
437 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
419 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
438 blanklines
420 blanklines
@@ -635,6 +617,7 @@ defListMarker = do
636definitionListItem :: Parser [Char] ParserState ([Inline], [[Block]])
618definitionListItem :: Parser [Char] ParserState ([Inline], [[Block]])
637definitionListItem = try $ do
619definitionListItem = try $ do
620+ guardEnabled Ext_definition_lists
638 -- first, see if this has any chance of being a definition list:
621 -- first, see if this has any chance of being a definition list:
639 lookAhead (anyLine >> optional blankline >> defListMarker)
622 lookAhead (anyLine >> optional blankline >> defListMarker)
640 term <- manyTill inline newline
623 term <- manyTill inline newline
@@ -694,9 +677,9 @@ para = try $ do
694 guard $ not . all isHtmlOrBlank $ result
677 guard $ not . all isHtmlOrBlank $ result
695 option (Plain result) $ try $ do
678 option (Plain result) $ try $ do
697− blanklines <|>
680+ (blanklines >> return Null)
698− (getState >>= guard . readerStrict . stateOptions >>
699− lookAhead (blockQuote <|> header) >> return "")
681+ <|> (guardDisabled Ext_blank_before_blockquote >> lookAhead blockQuote)
682+ <|> (guardDisabled Ext_blank_before_header >> lookAhead header)
700 return $ Para result
683 return $ Para result
702plain :: Parser [Char] ParserState Block
685plain :: Parser [Char] ParserState Block
@@ -710,12 +693,16 @@ htmlElement :: Parser [Char] ParserState [Char]
710htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
693htmlElement = strictHtmlBlock <|> liftM snd (htmlTag isBlockTag)
712htmlBlock :: Parser [Char] ParserState Block
695htmlBlock :: Parser [Char] ParserState Block
713−htmlBlock = try $ do
696+htmlBlock = RawBlock "html" `fmap`
714− failUnlessBeginningOfLine
697+ ((guardEnabled Ext_markdown_in_html_blocks >> rawHtmlBlocks)
700+htmlBlock' :: Parser [Char] ParserState String
701+htmlBlock' = try $ do
715 first <- htmlElement
702 first <- htmlElement
716 finalSpace <- many spaceChar
703 finalSpace <- many spaceChar
717 finalNewlines <- many newline
704 finalNewlines <- many newline
718− return $ RawBlock "html" $ first ++ finalSpace ++ finalNewlines
705+ return $ first ++ finalSpace ++ finalNewlines
720strictHtmlBlock :: Parser [Char] ParserState [Char]
707strictHtmlBlock :: Parser [Char] ParserState [Char]
721strictHtmlBlock = htmlInBalanced (not . isInlineTag)
708strictHtmlBlock = htmlInBalanced (not . isInlineTag)
@@ -730,13 +717,13 @@ rawVerbatimBlock = try $ do
731rawTeXBlock :: Parser [Char] ParserState Block
718rawTeXBlock :: Parser [Char] ParserState Block
732rawTeXBlock = do
719rawTeXBlock = do
733− failIfStrict
720+ guardEnabled Ext_raw_tex
734 result <- liftM (RawBlock "latex") rawLaTeXBlock
721 result <- liftM (RawBlock "latex") rawLaTeXBlock
735 <|> liftM (RawBlock "context") rawConTeXtEnvironment
722 <|> liftM (RawBlock "context") rawConTeXtEnvironment
737 return result
724 return result
739−rawHtmlBlocks :: Parser [Char] ParserState Block
726+rawHtmlBlocks :: Parser [Char] ParserState String
740rawHtmlBlocks = do
727rawHtmlBlocks = do
741 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
728 htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
742 liftM snd (htmlTag isBlockTag)
729 liftM snd (htmlTag isBlockTag)
@@ -750,8 +737,7 @@ rawHtmlBlocks = do
750 -- by a blank line
737 -- by a blank line
751 return $ blk ++ sps
738 return $ blk ++ sps
752 let combined = concat htmlBlocks
739 let combined = concat htmlBlocks
753− let combined' = if last combined == '\n' then init combined else combined
740+ return $ if last combined == '\n' then init combined else combined
754− return $ RawBlock "html" combined'
@@ -826,6 +812,7 @@ multilineRow indices = do
826-- and followed by blank lines.
812-- and followed by blank lines.
827tableCaption :: Parser [Char] ParserState [Inline]
813tableCaption :: Parser [Char] ParserState [Inline]
828tableCaption = try $ do
814tableCaption = try $ do
815+ guardEnabled Ext_table_captions
829 skipNonindentSpaces
816 skipNonindentSpaces
830 string ":" <|> string "Table:"
817 string ":" <|> string "Table:"
831 result <- many1 inline
818 result <- many1 inline
@@ -961,10 +948,14 @@ table :: Parser [Char] ParserState Block
961table = try $ do
948table = try $ do
962 frontCaption <- option [] tableCaption
949 frontCaption <- option [] tableCaption
963 Table _ aligns widths heads lines' <-
950 Table _ aligns widths heads lines' <-
951+ try (guardEnabled Ext_pipe_tables >> scanForPipe >>
964− try (scanForPipe >> (pipeTable True <|> pipeTable False)) <|>
952+ (pipeTable True <|> pipeTable False)) <|>
953+ try (guardEnabled Ext_multiline_tables >>
965− multilineTable False <|> simpleTable True <|>
954+ (multilineTable False <|> simpleTable True)) <|>
955+ try (guardEnabled Ext_simple_tables >>
966− simpleTable False <|> multilineTable True <|>
956+ (simpleTable False <|> multilineTable True)) <|>
957+ try (guardEnabled Ext_grid_tables >>
967− gridTable False <|> gridTable True <?> "table"
958+ (gridTable False <|> gridTable True)) <?> "table"
968 optional blanklines
959 optional blanklines
969 caption <- if null frontCaption
960 caption <- if null frontCaption
970 then option [] tableCaption
961 then option [] tableCaption
@@ -1008,10 +999,8 @@ inlineParsers = [ whitespace
1008escapedChar' :: Parser [Char] ParserState Char
999escapedChar' :: Parser [Char] ParserState Char
1009escapedChar' = try $ do
1000escapedChar' = try $ do
1010 char '\\'
1001 char '\\'
1011− state <- getState
1002+ (guardEnabled Ext_all_symbols_escapable >> satisfy (not . isAlphaNum))
1012− if readerStrict (stateOptions state)
1013− then oneOf "\\`*_{}[]()>#+-.!~"
1003+ <|> oneOf "\\`*_{}[]()>#+-.!~"
1014− else satisfy (not . isAlphaNum)
1016escapedChar :: Parser [Char] ParserState Inline
1005escapedChar :: Parser [Char] ParserState Inline
1017escapedChar = do
1006escapedChar = do
@@ -1023,10 +1012,9 @@ escapedChar = do
1024ltSign :: Parser [Char] ParserState Inline
1013ltSign :: Parser [Char] ParserState Inline
1025ltSign = do
1014ltSign = do
1026− st <- getState
1015+ guardDisabled Ext_markdown_in_html_blocks
1027− if readerStrict (stateOptions st)
1029− else notFollowedBy' rawHtmlBlocks >> char '<' -- unless it starts html
1016+ <|> (notFollowedBy' rawHtmlBlocks >> return ())
1030 return $ Str ['<']
1018 return $ Str ['<']
1032exampleRef :: Parser [Char] ParserState Inline
1020exampleRef :: Parser [Char] ParserState Inline
@@ -1072,13 +1060,13 @@ math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
1073mathDisplay :: Parser [Char] ParserState String
1061mathDisplay :: Parser [Char] ParserState String
1074mathDisplay = try $ do
1062mathDisplay = try $ do
1075− failIfStrict
1063+ guardEnabled Ext_tex_math
1076 string "$$"
1064 string "$$"
1077 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1065 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string "$$")
1079mathInline :: Parser [Char] ParserState String
1067mathInline :: Parser [Char] ParserState String
1080mathInline = try $ do
1068mathInline = try $ do
1081− failIfStrict
1069+ guardEnabled Ext_tex_math
1082 char '$'
1070 char '$'
1083 notFollowedBy space
1071 notFollowedBy space
1084 words' <- sepBy1 mathWord (many1 (spaceChar <|> (newline >>~ notFollowedBy' blankline)))
1072 words' <- sepBy1 mathWord (many1 (spaceChar <|> (newline >>~ notFollowedBy' blankline)))
@@ -1135,18 +1123,18 @@ strong = Strong `liftM` nested
1136strikeout :: Parser [Char] ParserState Inline
1124strikeout :: Parser [Char] ParserState Inline
1137strikeout = Strikeout `liftM`
1125strikeout = Strikeout `liftM`
1138− (failIfStrict >> inlinesBetween strikeStart strikeEnd)
1126+ (guardEnabled Ext_strikeout >> inlinesBetween strikeStart strikeEnd)
1139 where strikeStart = string "~~" >> lookAhead nonspaceChar
1127 where strikeStart = string "~~" >> lookAhead nonspaceChar
1140 >> notFollowedBy (char '~')
1128 >> notFollowedBy (char '~')
1141 strikeEnd = try $ string "~~"
1129 strikeEnd = try $ string "~~"
1143superscript :: Parser [Char] ParserState Inline
1131superscript :: Parser [Char] ParserState Inline
1144−superscript = failIfStrict >> enclosed (char '^') (char '^')
1132+superscript = guardEnabled Ext_superscript >> enclosed (char '^') (char '^')
1145 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1133 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1146 return . Superscript
1134 return . Superscript
1148subscript :: Parser [Char] ParserState Inline
1136subscript :: Parser [Char] ParserState Inline
1149−subscript = failIfStrict >> enclosed (char '~') (char '~')
1137+subscript = guardEnabled Ext_subscript >> enclosed (char '~') (char '~')
1150 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1138 (notFollowedBy spaceChar >> inline) >>= -- may not contain Space
1151 return . Subscript
1139 return . Subscript
@@ -1163,7 +1151,8 @@ str = do
1163 smart <- (readerSmart . stateOptions) `fmap` getState
1151 smart <- (readerSmart . stateOptions) `fmap` getState
1164 a <- alphaNum
1152 a <- alphaNum
1165 as <- many $ alphaNum
1153 as <- many $ alphaNum
1154+ <|> (guardEnabled Ext_intraword_underscores >>
1166− <|> (try $ char '_' >>~ lookAhead alphaNum)
1155+ try (char '_' >>~ lookAhead alphaNum))
1167 <|> if smart
1156 <|> if smart
1168 then (try $ satisfy (\c -> c == '\'' || c == '\x2019') >>
1157 then (try $ satisfy (\c -> c == '\'' || c == '\x2019') >>
1169 lookAhead alphaNum >> return '\x2019')
1158 lookAhead alphaNum >> return '\x2019')
@@ -1200,11 +1189,10 @@ endline :: Parser [Char] ParserState Inline
1200endline = try $ do
1189endline = try $ do
1202 notFollowedBy blankline
1191 notFollowedBy blankline
1204− when (readerStrict (stateOptions st)) $ do
1205− notFollowedBy emailBlockQuoteStart
1192+ guardEnabled Ext_blank_before_blockquote <|> notFollowedBy emailBlockQuoteStart
1206− notFollowedBy (char '#') -- atx header
1193+ guardEnabled Ext_blank_before_header <|> notFollowedBy (char '#') -- atx header
1207 -- parse potential list-starts differently if in a list:
1194 -- parse potential list-starts differently if in a list:
1208 when (stateParserContext st == ListItemState) $ do
1196 when (stateParserContext st == ListItemState) $ do
1209 notFollowedBy' bulletListStart
1197 notFollowedBy' bulletListStart
1210 notFollowedBy' anyOrderedListStart
1198 notFollowedBy' anyOrderedListStart
@@ -1282,10 +1270,9 @@ autoLink = try $ do
1282 char '<'
1270 char '<'
1283 (orig, src) <- uri <|> emailAddress
1271 (orig, src) <- uri <|> emailAddress
1284 char '>'
1272 char '>'
1285− st <- getState
1273+ (guardEnabled Ext_autolink_code_spans >>
1286− return $ if readerStrict (stateOptions st)
1287− then Link [Str orig] (src, "")
1288− else Link [Code ("",["url"],[]) orig] (src, "")
1274+ return (Link [Code ("",["url"],[]) orig] (src, "")))
1275+ <|> return (Link [Str orig] (src, ""))
1290image :: Parser [Char] ParserState Inline
1277image :: Parser [Char] ParserState Inline
1291image = try $ do
1278image = try $ do
@@ -1296,7 +1283,7 @@ image = try $ do
1297note :: Parser [Char] ParserState Inline
1284note :: Parser [Char] ParserState Inline
1298note = try $ do
1285note = try $ do
1299− failIfStrict
1286+ guardEnabled Ext_footnotes
1300 ref <- noteMarker
1287 ref <- noteMarker
1301 state <- getState
1288 state <- getState
1302 let notes = stateNotes state
1289 let notes = stateNotes state
@@ -1313,14 +1300,14 @@ note = try $ do
1314inlineNote :: Parser [Char] ParserState Inline
1301inlineNote :: Parser [Char] ParserState Inline
1315inlineNote = try $ do
1302inlineNote = try $ do
1316− failIfStrict
1303+ guardEnabled Ext_inline_notes
1317 char '^'
1304 char '^'
1318 contents <- inlinesInBalancedBrackets inline
1305 contents <- inlinesInBalancedBrackets inline
1319 return $ Note [Para contents]
1306 return $ Note [Para contents]
1321rawLaTeXInline' :: Parser [Char] ParserState Inline
1308rawLaTeXInline' :: Parser [Char] ParserState Inline
1322rawLaTeXInline' = try $ do
1309rawLaTeXInline' = try $ do
1323− failIfStrict
1310+ guardEnabled Ext_raw_tex
1324 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
1311 lookAhead $ char '\\' >> notFollowedBy' (string "start") -- context env
1325 RawInline _ s <- rawLaTeXInline
1312 RawInline _ s <- rawLaTeXInline
1326 return $ RawInline "tex" s -- "tex" because it might be context or latex
1313 return $ RawInline "tex" s -- "tex" because it might be context or latex
@@ -1343,17 +1330,18 @@ inBrackets parser = do
1344rawHtmlInline :: Parser [Char] ParserState Inline
1331rawHtmlInline :: Parser [Char] ParserState Inline
1345rawHtmlInline = do
1332rawHtmlInline = do
1346− st <- getState
1333+ mdInHtml <- option False $
1347− (_,result) <- if readerStrict (stateOptions st)
1334+ guardEnabled Ext_markdown_in_html_blocks >> return True
1335+ (_,result) <- if mdInHtml
1336+ then htmlTag isInlineTag
1348− then htmlTag (not . isTextTag)
1337+ else htmlTag (not . isTextTag)
1349− else htmlTag isInlineTag
1350 return $ RawInline "html" result
1338 return $ RawInline "html" result
1352-- Citations
1340-- Citations
1354cite :: Parser [Char] ParserState Inline
1342cite :: Parser [Char] ParserState Inline
1355cite = do
1343cite = do
1356− failIfStrict
1344+ guardEnabled Ext_citations
1357 citations <- textualCite <|> normalCite
1345 citations <- textualCite <|> normalCite
1358 return $ Cite citations []
1346 return $ Cite citations []