1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Tests.Readers.HTML (tests) where
7import qualified Data.Text as T
9import Test.Tasty.QuickCheck
12import Text.Pandoc.Arbitrary ()
13import Text.Pandoc.Builder
14import Text.Pandoc.Walk (walk)
17html = purely $ readHtml def
19htmlNativeDivs :: Text -> Pandoc
20htmlNativeDivs = purely $ readHtml def { readerExtensions = enableExtension Ext_native_divs $ readerExtensions def }
22makeRoundTrip :: Block -> Block
23makeRoundTrip CodeBlock{} = Para [Str "code block was here"]
24makeRoundTrip LineBlock{} = Para [Str "line block was here"]
25makeRoundTrip RawBlock{} = Para [Str "raw block was here"]
28removeRawInlines :: Inline -> Inline
29removeRawInlines RawInline{} = Str "raw inline was here"
32roundTrip :: Blocks -> Bool
33roundTrip b = d'' == d'''
34 where d = walk removeRawInlines $
35 walk makeRoundTrip $ Pandoc nullMeta $ toList b
39 rewrite = html . T.pack . (++ "\n") . T.unpack .
40 purely (writeHtml5String def
41 { writerWrapText = WrapPreserve })
44tests = [ testGroup "base tag"
45 [ test html "simple" $
46 "<head><base href=\"http://www.w3schools.com/images/foo\" ></head><body><img src=\"stickman.gif\" alt=\"Stickman\"></head>" =?>
47 plain (image "http://www.w3schools.com/images/stickman.gif" "" (text "Stickman"))
48 , test html "slash at end of base" $
49 "<head><base href=\"http://www.w3schools.com/images/\" ></head><body><img src=\"stickman.gif\" alt=\"Stickman\"></head>" =?>
50 plain (image "http://www.w3schools.com/images/stickman.gif" "" (text "Stickman"))
51 , test html "slash at beginning of href" $
52 "<head><base href=\"http://www.w3schools.com/images/\" ></head><body><img src=\"/stickman.gif\" alt=\"Stickman\"></head>" =?>
53 plain (image "http://www.w3schools.com/stickman.gif" "" (text "Stickman"))
54 , test html "absolute URL" $
55 "<head><base href=\"http://www.w3schools.com/images/\" ></head><body><img src=\"http://example.com/stickman.gif\" alt=\"Stickman\"></head>" =?>
56 plain (image "http://example.com/stickman.gif" "" (text "Stickman"))
59 [ test html "anchor without href" $ "<a name=\"anchor\"/>" =?>
60 plain (spanWith ("anchor",[],[]) mempty)
63 [ test html "lang on <html>" $ "<html lang=\"es\">hola" =?>
64 setMeta "lang" (text "es") (doc (plain (text "hola")))
65 , test html "xml:lang on <html>" $ "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"es\"><head></head><body>hola</body></html>" =?>
66 setMeta "lang" (text "es") (doc (plain (text "hola")))
69 [ test htmlNativeDivs "<main> becomes <div role=main>" $ "<main>hello</main>" =?>
70 doc (divWith ("", [], [("role", "main")]) (plain (text "hello")))
71 , test htmlNativeDivs "<main role=X> becomes <div role=X>" $ "<main role=foobar>hello</main>" =?>
72 doc (divWith ("", [], [("role", "foobar")]) (plain (text "hello")))
73 , test htmlNativeDivs "<main> has attributes preserved" $ "<main id=foo class=bar data-baz=qux>hello</main>" =?>
74 doc (divWith ("foo", ["bar"], [("role", "main"), ("data-baz", "qux")]) (plain (text "hello")))
75 , test htmlNativeDivs "<main> closes <p>" $ "<p>hello<main>main content</main>" =?>
76 doc (para (text "hello") <> divWith ("", [], [("role", "main")]) (plain (text "main content")))
77 , test htmlNativeDivs "<main> followed by text" $ "<main>main content</main>non-main content" =?>
78 doc (divWith ("", [], [("role", "main")]) (plain (text "main content")) <> plain (text "non-main content"))
80 , testProperty "Round trip" (withMaxSuccess 25 roundTrip)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list