git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: Use delimited code block if there are attributes.

(Unless in strict mode.)

commit8889ae8b5b091eb9d35bdf4698d39c562cb2e374 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 20 Dec 2010, 19:34 (16 years ago) parent0086329
1 file changed+21−2
src/Text/Pandoc/Writers/Markdown.hs+21−2
src/Text/Pandoc/Writers/Markdown.hs+21−2
@@ -229,8 +229,27 @@ blockToMarkdown opts (CodeBlock (_,classes,_) str)
229229 | "haskell" `elem` classes && "literate" `elem` classes &&
230230 writerLiterateHaskell opts =
231231 return $ prefixed "> " (text str) <> blankline
232−blockToMarkdown opts (CodeBlock _ str) = return $
233− nest (writerTabStop opts) (text str) <> blankline
232+blockToMarkdown opts (CodeBlock attribs str) = return $
233+ if writerStrictMarkdown opts || attribs == ([],[],[])
234+ then nest (writerTabStop opts) (text str) <> blankline
235+ else -- use delimited code block
236+ flush $ tildes <> space <> attrs <> cr <> text str <>
237+ cr <> tildes <> blankline
238+ where tildes = text "~~~~"
239+ attrs = braces $ hsep [attribId, attribClasses, attribKeys]
240+ attribId = case attribs of
241+ ([],_,_) -> empty
242+ (i,_,_) -> "#" <> text i
243+ attribClasses = case attribs of
244+ (_,[],_) -> empty
245+ (_,cs,_) -> hsep $
246+ map (text . ('.':))
247+ cs
248+ attribKeys = case attribs of
249+ (_,_,[]) -> empty
250+ (_,_,ks) -> hsep $
251+ map (\(k,v) -> text k
252+ <> "=\"" <> text v <> "\"") ks
234253blockToMarkdown opts (BlockQuote blocks) = do
235254 st <- get
236255 -- if we're writing literate haskell, put a space before the bird tracks