git.iko.soy/typeable/pandoc
on master help sign in
HTML reader: Use pandoc Div and Span for raw "<div>", "<span>".

Only if --parse-raw.

commit732f6abe15b75724c2eb7a8bf0763f054b2dc500 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 3 Nov 2013, 11:17 (13 years ago) parent0d95c15
1 file changed+25−10
src/Text/Pandoc/Readers/HTML.hs+25−10
src/Text/Pandoc/Readers/HTML.hs+25−10
@@ -92,6 +92,7 @@ block = choice
9292 , pHead
9393 , pBody
9494 , pPlain
95+ , pDiv
9596 , pRawHtmlBlock
9697 ]
9798
@@ -177,6 +178,13 @@ pRawTag = do
177178 then return []
178179 else return $ renderTags' [tag]
179180
181+pDiv :: TagParser [Block]
182+pDiv = try $ do
183+ getOption readerParseRaw >>= guard
184+ TagOpen _ attr <- lookAhead $ pSatisfy $ tagOpen (=="div") (const True)
185+ contents <- pInTags "div" block
186+ return [Div (mkAttr attr) contents]
187+
180188pRawHtmlBlock :: TagParser [Block]
181189pRawHtmlBlock = do
182190 raw <- pHtmlBlock "script" <|> pHtmlBlock "style" <|> pRawTag
@@ -295,11 +303,7 @@ pCodeBlock = try $ do
295303 let result = case reverse result' of
296304 '\n':_ -> init result'
297305 _ -> result'
298− let attribsId = fromMaybe "" $ lookup "id" attr
299− let attribsClasses = words $ fromMaybe "" $ lookup "class" attr
300− let attribsKV = filter (\(k,_) -> k /= "class" && k /= "id") attr
301− let attribs = (attribsId, attribsClasses, attribsKV)
302− return [CodeBlock attribs result]
306+ return [CodeBlock (mkAttr attr) result]
303307
304308inline :: TagParser [Inline]
305309inline = choice
@@ -314,6 +318,7 @@ inline = choice
314318 , pLink
315319 , pImage
316320 , pCode
321+ , pSpan
317322 , pRawHtmlInline
318323 ]
319324
@@ -397,11 +402,14 @@ pCode :: TagParser [Inline]
397402pCode = try $ do
398403 (TagOpen open attr) <- pSatisfy $ tagOpen (`elem` ["code","tt"]) (const True)
399404 result <- manyTill pAnyTag (pCloses open)
400− let ident = fromMaybe "" $ lookup "id" attr
401− let classes = words $ fromMaybe [] $ lookup "class" attr
402− let rest = filter (\(x,_) -> x /= "id" && x /= "class") attr
403− return [Code (ident,classes,rest)
404− $ intercalate " " $ lines $ innerText result]
405+ return [Code (mkAttr attr) $ intercalate " " $ lines $ innerText result]
406+
407+pSpan :: TagParser [Inline]
408+pSpan = try $ do
409+ getOption readerParseRaw >>= guard
410+ TagOpen _ attr <- lookAhead $ pSatisfy $ tagOpen (=="span") (const True)
411+ contents <- pInTags "span" inline
412+ return [Span (mkAttr attr) contents]
405413
406414pRawHtmlInline :: TagParser [Inline]
407415pRawHtmlInline = do
@@ -648,3 +656,10 @@ htmlTag f = try $ do
648656 _ -> do
649657 rendered <- manyTill anyChar (char '>')
650658 return (next, rendered ++ ">")
659+
660+mkAttr :: [(String, String)] -> Attr
661+mkAttr attr = (attribsId, attribsClasses, attribsKV)
662+ where attribsId = fromMaybe "" $ lookup "id" attr
663+ attribsClasses = words $ fromMaybe "" $ lookup "class" attr
664+ attribsKV = filter (\(k,_) -> k /= "class" && k /= "id") attr
665+