File: AsciiDoc.hs

package info (click to toggle)
haskell-pandoc 3.1.11.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,052 kB
  • sloc: haskell: 81,285; xml: 3,855; makefile: 13
file content (95 lines) | stat: -rw-r--r-- 3,878 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{-# LANGUAGE OverloadedStrings #-}
module Tests.Writers.AsciiDoc (tests) where

import Data.Text (unpack)
import Test.Tasty
import Tests.Helpers
import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder

asciidoc :: (ToPandoc a) => a -> String
asciidoc = unpack . purely (writeAsciiDocLegacy def) . toPandoc

asciidoctor :: (ToPandoc a) => a -> String
asciidoctor = unpack . purely (writeAsciiDoc def) . toPandoc

testAsciidoc :: (ToString a, ToPandoc a)
             => String
             -> (a, String)
             -> TestTree
testAsciidoc = test asciidoc

testAsciidoctor :: (ToString a, ToPandoc a)
             => String
             -> (a, String)
             -> TestTree
testAsciidoctor = test asciidoctor

tests :: [TestTree]
tests = [ testGroup "emphasis"
          [ testAsciidoc "emph word before" $
               para (text "foo" <> emph (text "bar")) =?>
                 "foo__bar__"
          , testAsciidoc "emph word after" $
               para (emph (text "foo") <> text "bar") =?>
                 "__foo__bar"
          , testAsciidoc "emph quoted" $
               para (doubleQuoted (emph (text "foo"))) =?>
                 "``__foo__''"
          , testAsciidoc "strong word before" $
               para (text "foo" <> strong (text "bar")) =?>
                 "foo**bar**"
          , testAsciidoc "strong word after" $
               para (strong (text "foo") <> text "bar") =?>
                 "**foo**bar"
          , testAsciidoc "strong quoted" $
               para (singleQuoted (strong (text "foo"))) =?>
                 "`**foo**'"
          ]
        , testGroup "blocks"
          [ testAsciidoc "code block without line numbers" $
               codeBlockWith ("", [ "haskell" ], []) "foo" =?> unlines
                                           [ "[source,haskell]"
                                           , "----"
                                           , "foo"
                                           , "----"
                                           ]
          , testAsciidoc "code block with line numbers" $
               codeBlockWith ("", [ "haskell", "numberLines" ], []) "foo" =?> unlines
                                           [ "[source%linesnum,haskell]"
                                           , "----"
                                           , "foo"
                                           , "----"
                                           ]
          ]
        , testGroup "tables"
          [ testAsciidoc "empty cells" $
               simpleTable [] [[mempty],[mempty]] =?> unlines
                                           [ "[cols=\"\",]"
                                           , "|==="
                                           , "|"
                                           , "|"
                                           , "|==="
                                           ]
          , test asciidoc "multiblock cells" $
               simpleTable [] [[para (text "Para 1") <> para (text "Para 2")]]
                                           =?> unlines
                                           [ "[cols=\"\",]"
                                           , "|==="
                                           , "a|"
                                           , "Para 1"
                                           , ""
                                           , "Para 2"
                                           , ""
                                           , "|==="
                                           ]
          ]
        , testGroup "lists"
          [ testAsciidoctor "bullet task list" $
               bulletList [plain "☐ a", plain "☒ b"] =?> unlines
                                           [ "* [ ] a"
                                           , "* [x] b"
                                           ]
          ]
        ]