aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-12-20 19:34:47 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-20 19:36:40 -0800
commit8889ae8b5b091eb9d35bdf4698d39c562cb2e374 (patch)
tree35cf17094e260b47bee07a1f8842269ffed6d00b /src/Text/Pandoc/Writers
parent0086329c36a09342b3ad5cade5bc4259b04c3bfb (diff)
downloadpandoc-8889ae8b5b091eb9d35bdf4698d39c562cb2e374.tar.gz
Markdown writer: Use delimited code block if there are attributes.
(Unless in strict mode.)
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 135f7a7f6..50bf05a54 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -229,8 +229,27 @@ blockToMarkdown opts (CodeBlock (_,classes,_) str)
| "haskell" `elem` classes && "literate" `elem` classes &&
writerLiterateHaskell opts =
return $ prefixed "> " (text str) <> blankline
-blockToMarkdown opts (CodeBlock _ str) = return $
- nest (writerTabStop opts) (text str) <> blankline
+blockToMarkdown opts (CodeBlock attribs str) = return $
+ if writerStrictMarkdown opts || attribs == ([],[],[])
+ then nest (writerTabStop opts) (text str) <> blankline
+ else -- use delimited code block
+ flush $ tildes <> space <> attrs <> cr <> text str <>
+ cr <> tildes <> blankline
+ where tildes = text "~~~~"
+ attrs = braces $ hsep [attribId, attribClasses, attribKeys]
+ attribId = case attribs of
+ ([],_,_) -> empty
+ (i,_,_) -> "#" <> text i
+ attribClasses = case attribs of
+ (_,[],_) -> empty
+ (_,cs,_) -> hsep $
+ map (text . ('.':))
+ cs
+ attribKeys = case attribs of
+ (_,_,[]) -> empty
+ (_,_,ks) -> hsep $
+ map (\(k,v) -> text k
+ <> "=\"" <> text v <> "\"") ks
blockToMarkdown opts (BlockQuote blocks) = do
st <- get
-- if we're writing literate haskell, put a space before the bird tracks