git.iko.soy/typeable/pandoc
on master help sign in
Add Reader support for HTML <samp> element (#5843)

The `<samp>` element is parsed as a Span with class `sample`. Closes #5792.

commitd50f46d26d8584a03b775394de8878e028f8d8a4 authorAmogh Rathore <amoghdroid09@gmail.com> dateThu 24 Oct 2019, 00:44 (7 years ago) parentb80bd17
2 files changed+15
src/Text/Pandoc/Readers/HTML.hs+9 test/Tests/Readers/HTML.hs+6
src/Text/Pandoc/Readers/HTML.hs+9
@@ -652,6 +652,7 @@ inline = choice
652652 , pLink
653653 , pImage
654654 , pCode
655+ , pSamp
655656 , pSpan
656657 , pMath False
657658 , pScriptMath
@@ -781,6 +782,14 @@ pImage = do
781782 let kvs = concatMap getAtt ["width", "height", "sizes", "srcset"]
782783 return $ B.imageWith (uid, cls, kvs) (escapeURI url) title (B.text alt)
783784
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+
784793pCode :: PandocMonad m => TagParser m Inlines
785794pCode = try $ do
786795 (TagOpen open attr') <- pSatisfy $ tagOpen (`elem` ["code","tt"]) (const True)
test/Tests/Readers/HTML.hs+6
@@ -89,6 +89,12 @@ tests = [ testGroup "base tag"
8989 , test htmlNativeDivs "<main> followed by text" $ "<main>main content</main>non-main content" =?>
9090 doc (divWith ("", [], [("role", "main")]) (plain (text "main content")) <> plain (text "non-main content"))
9191 ]
92+ , testGroup "samp"
93+ [
94+ test html "inline samp block" $
95+ "<samp>Answer is 42</samp>" =?>
96+ plain (codeWith ("",["sample"],[]) "Answer is 42")
97+ ]
9298 , askOption $ \(QuickCheckTests numtests) ->
9399 testProperty "Round trip" $
94100 withMaxSuccess (if QuickCheckTests numtests == defaultValue