git.iko.soy/typeable/pandoc
on master help sign in
Replaced writerStrict with writerExtensions in WriterOptions.

Still have not implemented individual tests for all the extensions in the markdown writer.

commitb98219773b45ed43268204e59c494f45b4455d2c authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 27 Jul 2012, 09:18 (14 years ago) parent00dc1e7
5 files changed+36−25
src/Text/Pandoc/Options.hs+4−2 src/Text/Pandoc/Readers/Markdown.hs+7−5 src/Text/Pandoc/Writers/HTML.hs+1−1 src/Text/Pandoc/Writers/Markdown.hs+20−16 src/pandoc.hs+4−1
src/Text/Pandoc/Options.hs+4−2
@@ -56,7 +56,9 @@ data Extension = Ext_footnotes
5656 | Ext_tex_math
5757 | Ext_latex_macros
5858 | Ext_delimited_code_blocks
59+ | Ext_inline_code_attributes
5960 | Ext_markdown_in_html_blocks
61+ | Ext_escaped_line_breaks
6062 | Ext_autolink_code_spans
6163 | Ext_fancy_lists
6264 | Ext_startnum
@@ -154,7 +156,7 @@ data WriterOptions = WriterOptions
154156 , writerIgnoreNotes :: Bool -- ^ Ignore footnotes (used in making toc)
155157 , writerNumberSections :: Bool -- ^ Number sections in LaTeX
156158 , writerSectionDivs :: Bool -- ^ Put sections in div tags in HTML
157− , writerStrictMarkdown :: Bool -- ^ Use strict markdown syntax
159+ , writerExtensions :: Set Extension -- ^ Markdown extensions that can be used
158160 , writerReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
159161 , writerWrapText :: Bool -- ^ Wrap text to line length
160162 , writerColumns :: Int -- ^ Characters in a line (for text wrapping)
@@ -194,7 +196,7 @@ instance Default WriterOptions where
194196 , writerIgnoreNotes = False
195197 , writerNumberSections = False
196198 , writerSectionDivs = False
197− , writerStrictMarkdown = False
199+ , writerExtensions = Set.fromList [minBound..maxBound]
198200 , writerReferenceLinks = False
199201 , writerWrapText = True
200202 , writerColumns = 72
src/Text/Pandoc/Readers/Markdown.hs+7−5
@@ -1005,10 +1005,11 @@ escapedChar' = try $ do
10051005escapedChar :: Parser [Char] ParserState Inline
10061006escapedChar = do
10071007 result <- escapedChar'
1008− return $ case result of
1009− ' ' -> Str "\160" -- "\ " is a nonbreaking space
1010− '\n' -> LineBreak -- "\[newline]" is a linebreak
1011− _ -> Str [result]
1008+ case result of
1009+ ' ' -> return $ Str "\160" -- "\ " is a nonbreaking space
1010+ '\n' -> guardEnabled Ext_escaped_line_breaks >>
1011+ return LineBreak -- "\[newline]" is a linebreak
1012+ _ -> return $ Str [result]
10121013
10131014ltSign :: Parser [Char] ParserState Inline
10141015ltSign = do
@@ -1042,7 +1043,8 @@ code = try $ do
10421043 (char '\n' >> notFollowedBy' blankline >> return " "))
10431044 (try (skipSpaces >> count (length starts) (char '`') >>
10441045 notFollowedBy (char '`')))
1045− attr <- option ([],[],[]) (try $ optional whitespace >> attributes)
1046+ attr <- option ([],[],[]) (try $ guardEnabled Ext_inline_code_attributes >>
1047+ optional whitespace >> attributes)
10461048 return $ Code attr $ removeLeadingTrailingSpace $ concat result
10471049
10481050mathWord :: Parser [Char] st [Char]
src/Text/Pandoc/Writers/HTML.hs+1−1
@@ -273,7 +273,7 @@ elementToHtml slideLevel opts (Sec level num id' title' elements) = do
273273 -- title slides have no content of their own
274274 then filter isSec elements
275275 else elements
276− let header'' = if (writerStrictMarkdown opts || writerSectionDivs opts ||
276+ let header'' = if (writerSectionDivs opts ||
277277 writerSlideVariant opts == S5Slides || slide)
278278 then header'
279279 else header' ! prefixedId opts id'
src/Text/Pandoc/Writers/Markdown.hs+20−16
@@ -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
src/pandoc.hs+4−1
@@ -969,7 +969,10 @@ main = do
969969 writerIgnoreNotes = False,
970970 writerNumberSections = numberSections,
971971 writerSectionDivs = sectionDivs,
972− writerStrictMarkdown = strict,
972+ writerExtensions = if strict
973+ then Set.empty
974+ else Set.fromList
975+ [minBound..maxBound],
973976 writerReferenceLinks = referenceLinks,
974977 writerWrapText = wrap,
975978 writerColumns = columns,