aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-08-11 22:04:37 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2012-08-11 22:04:37 -0700
commite520762543f85e7457c2cd1b784355dae616bdc3 (patch)
tree5826147bb82c6b1cdb0edb8a044d404d6e70c3a7 /src/Text
parentc681ddcd7b4fa3274833353a330339d4c1c57d45 (diff)
downloadpandoc-e520762543f85e7457c2cd1b784355dae616bdc3.tar.gz
Implemented Ext_markdown_attribute in markdown writer.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 52805c1aa..be7af9b6c 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -42,6 +42,7 @@ import Text.Pandoc.Pretty
import Control.Monad.State
import qualified Data.Set as Set
import Text.Pandoc.Writers.HTML (writeHtmlString)
+import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
type Notes = [[Block]]
type Refs = [([Inline], Target)]
@@ -230,8 +231,15 @@ blockToMarkdown opts (Para inlines) = do
then text "\x200B" -- zero-width space, a hack
else empty
return $ esc <> contents <> blankline
-blockToMarkdown _ (RawBlock f str)
- | f == "html" || f == "latex" || f == "tex" || f == "markdown" = do
+blockToMarkdown opts (RawBlock f str)
+ | f == "html" = do
+ st <- get
+ if stPlain st
+ then return empty
+ else return $ if isEnabled Ext_markdown_attribute opts
+ then text (addMarkdownAttribute str) <> text "\n"
+ else text str <> text "\n"
+ | f == "latex" || f == "tex" || f == "markdown" = do
st <- get
if stPlain st
then return empty
@@ -321,6 +329,15 @@ blockToMarkdown opts (DefinitionList items) = do
contents <- mapM (definitionListItemToMarkdown opts) items
return $ cat contents <> blankline
+addMarkdownAttribute :: String -> String
+addMarkdownAttribute s =
+ case span isTagText $ reverse $ parseTags s of
+ (xs,(TagOpen t attrs:rest)) ->
+ renderTags $ reverse rest ++ (TagOpen t attrs' : reverse xs)
+ where attrs' = ("markdown","1"):[(x,y) | (x,y) <- attrs,
+ x /= "markdown"]
+ _ -> s
+
pipeTable :: Bool -> [Alignment] -> [Doc] -> [[Doc]] -> State WriterState Doc
pipeTable headless aligns rawHeaders rawRows = do
let torow cs = nowrap $ text "|" <>