git.iko.soy/typeable/pandoc
on master help sign in
Textile reader: Improved handling of `<pre>` blocks.

* Closed #927 (a bug in which `<pre>` in certain contexts was not recognized as a code block). * Remove internal HTML tags in code blocks, rather than printing them verbatim. * Parse attributes on `<pre>` tag for code blocks.

commit85cc140744b01148da944a58948d9e4a87cb64c4 authorJohn MacFarlane <fiddlosopher@gmail.com> dateThu 25 Jul 2013, 09:45 (13 years ago) parent2e5edbb
2 files changed+11−5
src/Text/Pandoc/Readers/Textile.hs+10−4 tests/textile-reader.native+1−1
src/Text/Pandoc/Readers/Textile.hs+10−4
@@ -57,6 +57,7 @@ import Text.Pandoc.Options
5757import Text.Pandoc.Parsing
5858import Text.Pandoc.Readers.HTML ( htmlTag, isInlineTag, isBlockTag )
5959import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
60+import Text.HTML.TagSoup (parseTags, innerText, fromAttrib, Tag(..))
6061import Text.HTML.TagSoup.Match
6162import Data.List ( intercalate )
6263import Data.Char ( digitToInt, isUpper )
@@ -152,8 +153,10 @@ codeBlockBc = try $ do
152153-- | Code Blocks in Textile are between <pre> and </pre>
153154codeBlockPre :: Parser [Char] ParserState Block
154155codeBlockPre = try $ do
155− htmlTag (tagOpen (=="pre") null)
156− result' <- manyTill anyChar (try $ htmlTag (tagClose (=="pre")) >> blockBreak)
156+ (t@(TagOpen _ attrs),_) <- htmlTag (tagOpen (=="pre") (const True))
157+ result' <- (innerText . parseTags) `fmap` -- remove internal tags
158+ manyTill anyChar (htmlTag (tagClose (=="pre")))
159+ optional blanklines
157160 -- drop leading newline if any
158161 let result'' = case result' of
159162 '\n':xs -> xs
@@ -162,7 +165,10 @@ codeBlockPre = try $ do
162165 let result''' = case reverse result'' of
163166 '\n':_ -> init result''
164167 _ -> result''
165− return $ CodeBlock ("",[],[]) result'''
168+ let classes = words $ fromAttrib "class" t
169+ let ident = fromAttrib "id" t
170+ let kvs = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
171+ return $ CodeBlock (ident,classes,kvs) result'''
166172
167173-- | Header of the form "hN. content" with N in 1..6
168174header :: Parser [Char] ParserState Block
@@ -275,7 +281,7 @@ definitionListItem = try $ do
275281-- blocks support, we have to lookAhead for a rawHtmlBlock.
276282blockBreak :: Parser [Char] ParserState ()
277283blockBreak = try (newline >> blanklines >> return ()) <|>
278− (lookAhead rawHtmlBlock >> return ())
284+ try (optional spaces >> lookAhead rawHtmlBlock >> return ())
279285
280286-- raw content
281287
tests/textile-reader.native+1−1
@@ -139,7 +139,7 @@ Pandoc (Meta {unMeta = fromList []})
139139,Header 1 ("",[],[]) [Str "Raw",Space,Str "HTML"]
140140,Para [Str "However",Str ",",Space,RawInline "html" "<strong>",Space,Str "raw",Space,Str "HTML",Space,Str "inlines",Space,RawInline "html" "</strong>",Space,Str "are",Space,Str "accepted",Str ",",Space,Str "as",Space,Str "well",Space,Str "as",Space,Str ":"]
141141,RawBlock "html" "<div class=\"foobar\">"
142−,Para [Str "any",Space,Strong [Str "Raw",Space,Str "HTML",Space,Str "Block"],Space,Str "with",Space,Str "bold",LineBreak]
142+,Para [Str "any",Space,Strong [Str "Raw",Space,Str "HTML",Space,Str "Block"],Space,Str "with",Space,Str "bold"]
143143,RawBlock "html" "</div>"
144144,Para [Str "Html",Space,Str "blocks",Space,Str "can",Space,Str "be"]
145145,RawBlock "html" "<div>"