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