@@ -40,6 +40,7 @@ import Text.Pandoc.Parsing hiding (blankline, char, space)
4040import Data.List ( group, isPrefixOf, find, intersperse, transpose )
4141import Text.Pandoc.Pretty
4242import Control.Monad.State
43+import qualified Data.Set as Set
4344
4445type Notes = [[Block]]
4546type Refs = [([Inline], Target)]
@@ -47,6 +48,9 @@ data WriterState = WriterState { stNotes :: Notes
4748 , stRefs :: Refs
4849 , stPlain :: Bool }
4950
51+isEnabled :: Extension -> WriterOptions -> Bool
52+isEnabled ext opts = ext `Set.member` (writerExtensions opts)
53+
5054-- | Convert Pandoc to Markdown.
5155writeMarkdown :: WriterOptions -> Pandoc -> String
5256writeMarkdown opts document =
@@ -58,7 +62,7 @@ writeMarkdown opts document =
5862-- pictures, or inline formatting).
5963writePlain :: WriterOptions -> Pandoc -> String
6064writePlain opts document =
61− evalState (pandocToMarkdown opts{writerStrictMarkdown = True}
65+ evalState (pandocToMarkdown opts{writerExtensions = Set.empty}
6266 document') WriterState{ stNotes = []
6367 , stRefs = []
6468 , stPlain = True }
@@ -215,7 +219,7 @@ blockToMarkdown opts (Para inlines) = do
215219 contents <- inlineListToMarkdown opts inlines
216220 -- escape if para starts with ordered list marker
217221 st <- get
218− let esc = if (not (writerStrictMarkdown opts)) &&
222+ let esc = if isEnabled Ext_all_symbols_escapable opts &&
219223 not (stPlain st) &&
220224 beginsWithOrderedListMarker (render Nothing contents)
221225 then text "\x200B" -- zero-width space, a hack
@@ -251,13 +255,13 @@ blockToMarkdown opts (CodeBlock (_,classes,_) str)
251255 writerLiterateHaskell opts =
252256 return $ prefixed "> " (text str) <> blankline
253257blockToMarkdown opts (CodeBlock attribs str) = return $
254− if writerStrictMarkdown opts || attribs == nullAttr
255− then nest (writerTabStop opts) (text str) <> blankline
256− else -- use delimited code block
258+ if isEnabled Ext_delimited_code_blocks opts && attribs /= nullAttr
259+ then -- use delimited code block
257260 (tildes <> space <> attrs <> cr <> text str <>
258261 cr <> tildes) <> blankline
259− where tildes = text "~~~~"
260− attrs = attrsToMarkdown attribs
262+ else nest (writerTabStop opts) (text str) <> blankline
263+ where tildes = text "~~~~"
264+ attrs = attrsToMarkdown attribs
261265blockToMarkdown opts (BlockQuote blocks) = do
262266 st <- get
263267 -- if we're writing literate haskell, put a space before the bird tracks
@@ -372,9 +376,10 @@ blockListToMarkdown opts blocks =
372376 -- insert comment between list and indented code block, or the
373377 -- code block will be treated as a list continuation paragraph
374378 where fixBlocks (b : CodeBlock attr x : rest)
375− | (writerStrictMarkdown opts || attr == nullAttr) && isListBlock b =
379+ | (not (isEnabled Ext_delimited_code_blocks opts) || attr == nullAttr)
380+ && isListBlock b =
376381 b : RawBlock "html" "<!-- -->\n" : CodeBlock attr x :
377− fixBlocks rest
382+ fixBlocks rest
378383 fixBlocks (x : xs) = x : fixBlocks xs
379384 fixBlocks [] = []
380385 isListBlock (BulletList _) = True
@@ -443,9 +448,9 @@ inlineToMarkdown opts (Code attr str) =
443448 else maximum $ map length tickGroups
444449 marker = replicate (longest + 1) '`'
445450 spacer = if (longest == 0) then "" else " "
446− attrs = if writerStrictMarkdown opts || attr == nullAttr
447− then empty
448− else attrsToMarkdown attr
451+ attrs = if isEnabled Ext_inline_code_attributes opts && attr /= nullAttr
452+ then attrsToMarkdown attr
453+ else empty
449454 in return $ text (marker ++ spacer ++ str ++ spacer ++ marker) <> attrs
450455inlineToMarkdown _ (Str str) = do
451456 st <- get
@@ -460,10 +465,9 @@ inlineToMarkdown _ (RawInline f str)
460465 | f == "html" || f == "latex" || f == "tex" || f == "markdown" =
461466 return $ text str
462467inlineToMarkdown _ (RawInline _ _) = return empty
463−inlineToMarkdown opts (LineBreak) = return $
464− if writerStrictMarkdown opts
465− then " " <> cr
466− else "\\" <> cr
468+inlineToMarkdown opts (LineBreak)
469+ | isEnabled Ext_escaped_line_breaks opts = return $ "\\" <> cr
470+ | otherwise = return $ " " <> cr
467471inlineToMarkdown _ Space = return space
468472inlineToMarkdown opts (Cite (c:cs) lst)
469473 | writerCiteMethod opts == Citeproc = inlineListToMarkdown opts lst