git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: Use delimited code block if there are attributes.
8889ae8John MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+21−2
@@ -229,8 +229,27 @@ blockToMarkdown opts (CodeBlock (_,classes,_) str)
229 | "haskell" `elem` classes && "literate" `elem` classes &&
229 | "haskell" `elem` classes && "literate" `elem` classes &&
230 writerLiterateHaskell opts =
230 writerLiterateHaskell opts =
231 return $ prefixed "> " (text str) <> blankline
231 return $ prefixed "> " (text str) <> blankline
232−blockToMarkdown opts (CodeBlock _ str) = return $
232+blockToMarkdown opts (CodeBlock attribs str) = return $
233+ if writerStrictMarkdown opts || attribs == ([],[],[])
233− nest (writerTabStop opts) (text str) <> blankline
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
234blockToMarkdown opts (BlockQuote blocks) = do
253blockToMarkdown opts (BlockQuote blocks) = do
235 st <- get
254 st <- get
236 -- if we're writing literate haskell, put a space before the bird tracks
255 -- if we're writing literate haskell, put a space before the bird tracks