git.iko.soy/typeable/pandoc
on ea2ea45 help sign in
54 lines 3.2 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Tests.Readers.HTML (tests) where
4import Data.Text (Text)
5import Test.Tasty
6import Tests.Helpers
7import Text.Pandoc
8import Text.Pandoc.Arbitrary ()
9import Text.Pandoc.Builder
11html :: Text -> Pandoc
12html = purely $ readHtml def
14htmlNativeDivs :: Text -> Pandoc
15htmlNativeDivs = purely $ readHtml def { readerExtensions = enableExtension Ext_native_divs $ readerExtensions def }
17tests :: [TestTree]
18tests = [ testGroup "base tag"
19 [ test html "simple" $
20 "<head><base href=\"http://www.w3schools.com/images/foo\" ></head><body><img src=\"stickman.gif\" alt=\"Stickman\"></head>" =?>
21 plain (image "http://www.w3schools.com/images/stickman.gif" "" (text "Stickman"))
22 , test html "slash at end of base" $
23 "<head><base href=\"http://www.w3schools.com/images/\" ></head><body><img src=\"stickman.gif\" alt=\"Stickman\"></head>" =?>
24 plain (image "http://www.w3schools.com/images/stickman.gif" "" (text "Stickman"))
25 , test html "slash at beginning of href" $
26 "<head><base href=\"http://www.w3schools.com/images/\" ></head><body><img src=\"/stickman.gif\" alt=\"Stickman\"></head>" =?>
27 plain (image "http://www.w3schools.com/stickman.gif" "" (text "Stickman"))
28 , test html "absolute URL" $
29 "<head><base href=\"http://www.w3schools.com/images/\" ></head><body><img src=\"http://example.com/stickman.gif\" alt=\"Stickman\"></head>" =?>
30 plain (image "http://example.com/stickman.gif" "" (text "Stickman"))
31 ]
32 , testGroup "anchors"
33 [ test html "anchor without href" $ "<a name=\"anchor\"/>" =?>
34 plain (spanWith ("anchor",[],[]) mempty)
35 ]
36 , testGroup "lang"
37 [ test html "lang on <html>" $ "<html lang=\"es\">hola" =?>
38 setMeta "lang" (text "es") (doc (plain (text "hola")))
39 , test html "xml:lang on <html>" $ "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"es\"><head></head><body>hola</body></html>" =?>
40 setMeta "lang" (text "es") (doc (plain (text "hola")))
41 ]
42 , testGroup "main"
43 [ test htmlNativeDivs "<main> becomes <div role=main>" $ "<main>hello</main>" =?>
44 doc (divWith ("", [], [("role", "main")]) (plain (text "hello")))
45 , test htmlNativeDivs "<main role=X> becomes <div role=X>" $ "<main role=foobar>hello</main>" =?>
46 doc (divWith ("", [], [("role", "foobar")]) (plain (text "hello")))
47 , test htmlNativeDivs "<main> has attributes preserved" $ "<main id=foo class=bar data-baz=qux>hello</main>" =?>
48 doc (divWith ("foo", ["bar"], [("role", "main"), ("data-baz", "qux")]) (plain (text "hello")))
49 , test htmlNativeDivs "<main> closes <p>" $ "<p>hello<main>main content</main>" =?>
50 doc (para (text "hello") <> divWith ("", [], [("role", "main")]) (plain (text "main content")))
51 , test htmlNativeDivs "<main> followed by text" $ "<main>main content</main>non-main content" =?>
52 doc (divWith ("", [], [("role", "main")]) (plain (text "main content")) <> plain (text "non-main content"))
53 ]
54 ]