git.iko.soy/typeable/pandoc
on master help sign in
Add Reader support for HTML <samp> element (#5843)
d50f46dAmogh Rathore
src/Text/Pandoc/Readers/HTML.hs+9
@@ -652,6 +652,7 @@ inline = choice
652 , pLink
652 , pLink
653 , pImage
653 , pImage
654 , pCode
654 , pCode
655+ , pSamp
655 , pSpan
656 , pSpan
656 , pMath False
657 , pMath False
657 , pScriptMath
658 , pScriptMath
@@ -781,6 +782,14 @@ pImage = do
781 let kvs = concatMap getAtt ["width", "height", "sizes", "srcset"]
782 let kvs = concatMap getAtt ["width", "height", "sizes", "srcset"]
782 return $ B.imageWith (uid, cls, kvs) (escapeURI url) title (B.text alt)
783 return $ B.imageWith (uid, cls, kvs) (escapeURI url) title (B.text alt)
783
784
785+pSamp :: PandocMonad m => TagParser m Inlines
786+pSamp = try $ do
787+ TagOpen open attr' <- pSatisfy $ tagOpen (=="samp") (const True)
788+ result <- manyTill pAny (pCloses open)
789+ let (ids,cs,kvs) = mkAttr . toStringAttr $ attr'
790+ return . B.codeWith (ids,"sample":cs,kvs) .
791+ unwords . lines . T.unpack . innerText $ result
792+
784pCode :: PandocMonad m => TagParser m Inlines
793pCode :: PandocMonad m => TagParser m Inlines
785pCode = try $ do
794pCode = try $ do
786 (TagOpen open attr') <- pSatisfy $ tagOpen (`elem` ["code","tt"]) (const True)
795 (TagOpen open attr') <- pSatisfy $ tagOpen (`elem` ["code","tt"]) (const True)
test/Tests/Readers/HTML.hs+6
@@ -89,6 +89,12 @@ tests = [ testGroup "base tag"
89 , test htmlNativeDivs "<main> followed by text" $ "<main>main content</main>non-main content" =?>
89 , test htmlNativeDivs "<main> followed by text" $ "<main>main content</main>non-main content" =?>
90 doc (divWith ("", [], [("role", "main")]) (plain (text "main content")) <> plain (text "non-main content"))
90 doc (divWith ("", [], [("role", "main")]) (plain (text "main content")) <> plain (text "non-main content"))
91 ]
91 ]
92+ , testGroup "samp"
93+ [
94+ test html "inline samp block" $
95+ "<samp>Answer is 42</samp>" =?>
96+ plain (codeWith ("",["sample"],[]) "Answer is 42")
97+ ]
92 , askOption $ \(QuickCheckTests numtests) ->
98 , askOption $ \(QuickCheckTests numtests) ->
93 testProperty "Round trip" $
99 testProperty "Round trip" $
94 withMaxSuccess (if QuickCheckTests numtests == defaultValue
100 withMaxSuccess (if QuickCheckTests numtests == defaultValue