git.iko.soy/typeable/pandoc
on master help sign in
Mardkown reader: Implemented Ext_markdown_attribute.
6f3e228John MacFarlane
src/Text/Pandoc/Options.hs+1
@@ -64,6 +64,7 @@ data Extension = Ext_footnotes
64 | Ext_delimited_code_blocks
64 | Ext_delimited_code_blocks
65 | Ext_inline_code_attributes
65 | Ext_inline_code_attributes
66 | Ext_markdown_in_html_blocks
66 | Ext_markdown_in_html_blocks
67+ | Ext_markdown_attribute
67 | Ext_escaped_line_breaks
68 | Ext_escaped_line_breaks
68 | Ext_autolink_code_spans
69 | Ext_autolink_code_spans
69 | Ext_fancy_lists
70 | Ext_fancy_lists
src/Text/Pandoc/Readers/Markdown.hs+23−14
@@ -52,6 +52,7 @@ import Control.Applicative ((<$>), (<*), (*>), (<$))
52import Control.Monad
52import Control.Monad
53import Text.HTML.TagSoup
53import Text.HTML.TagSoup
54import Text.HTML.TagSoup.Match (tagOpen)
54import Text.HTML.TagSoup.Match (tagOpen)
55+import qualified Data.Set as Set
55
56
56-- | Read markdown from an input string and return a Pandoc document.
57-- | Read markdown from an input string and return a Pandoc document.
57readMarkdown :: ReaderOptions -- ^ Reader options
58readMarkdown :: ReaderOptions -- ^ Reader options
@@ -720,13 +721,13 @@ htmlBlock' = try $ do
720strictHtmlBlock :: Parser [Char] ParserState String
721strictHtmlBlock :: Parser [Char] ParserState String
721strictHtmlBlock = htmlInBalanced (not . isInlineTag)
722strictHtmlBlock = htmlInBalanced (not . isInlineTag)
722
723
723−rawVerbatimBlock :: Parser [Char] ParserState String
724+rawVerbatimBlock :: Parser [Char] ParserState (Tag String, String)
724rawVerbatimBlock = try $ do
725rawVerbatimBlock = try $ do
725− (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
726+ (TagOpen tag as, open) <- htmlTag (tagOpen (\t ->
726 t == "pre" || t == "style" || t == "script")
727 t == "pre" || t == "style" || t == "script")
727 (const True))
728 (const True))
728 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
729 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
729− return $ open ++ contents ++ renderTags [TagClose tag]
730+ return (TagOpen tag as, open ++ contents ++ renderTags [TagClose tag])
730
731
731rawTeXBlock :: Parser [Char] ParserState (F Blocks)
732rawTeXBlock :: Parser [Char] ParserState (F Blocks)
732rawTeXBlock = do
733rawTeXBlock = do
@@ -738,17 +739,25 @@ rawTeXBlock = do
738
739
739rawHtmlBlocks :: Parser [Char] ParserState String
740rawHtmlBlocks :: Parser [Char] ParserState String
740rawHtmlBlocks = do
741rawHtmlBlocks = do
741− htmlBlocks <- many1 $ do blk <- rawVerbatimBlock <|>
742+ htmlBlocks <- many1 $ try $ do
742− liftM snd (htmlTag isBlockTag)
743+ (t,s) <- rawVerbatimBlock <|> htmlTag isBlockTag
744+ exts <- getOption readerExtensions
745+ -- if open tag, need markdown=1 if
746+ -- markdown_attributes extension is set
747+ when (Ext_markdown_attribute `Set.member` exts
748+ && isTagOpen t) $ guard
749+ $ case t of
750+ TagOpen _ as -> "markdown" `elem` map fst as
751+ _ -> False
743− sps <- do sp1 <- many spaceChar
752+ sps <- do sp1 <- many spaceChar
744− sp2 <- option "" (blankline >> return "\n")
753+ sp2 <- option "" (blankline >> return "\n")
745− sp3 <- many spaceChar
754+ sp3 <- many spaceChar
746− sp4 <- option "" blanklines
755+ sp4 <- option "" blanklines
747− return $ sp1 ++ sp2 ++ sp3 ++ sp4
756+ return $ sp1 ++ sp2 ++ sp3 ++ sp4
748− -- note: we want raw html to be able to
757+ -- note: we want raw html to be able to
749− -- precede a code block, when separated
758+ -- precede a code block, when separated
750− -- by a blank line
759+ -- by a blank line
751− return $ blk ++ sps
760+ return $ s ++ sps
752 let combined = concat htmlBlocks
761 let combined = concat htmlBlocks
753 return $ if last combined == '\n' then init combined else combined
762 return $ if last combined == '\n' then init combined else combined
754
763