File: Org.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 (89 lines) | stat: -rw-r--r-- 2,232 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
{-# LANGUAGE OverloadedStrings #-}
module Tests.Writers.Org (tests) where

import Data.Text as T
import Test.Tasty
import Test.Tasty.HUnit (HasCallStack)
import Tests.Helpers
import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder

infix 4 =:
(=:) :: (ToString a, ToPandoc a, HasCallStack)
     => String -> (a, Text) -> TestTree
(=:) = test org

defopts :: WriterOptions
defopts = def
  { writerExtensions = getDefaultExtensions "org"
  }

org :: (ToPandoc a) => a -> Text
org = orgWithOpts defopts

orgWithOpts :: (ToPandoc a) => WriterOptions -> a -> Text
orgWithOpts opts x = purely (writeOrg opts) $ toPandoc x


tests :: [TestTree]
tests =
  [ testGroup "links"
    -- See http://orgmode.org/manual/Internal-links.html#Internal-links
    [ "simple link"
      =: link "/url" "" "foo"
      =?> "[[/url][foo]]"
    , "internal link to anchor"
      =: link "#my-custom-id" "" "#my-custom-id"
      =?> "[[#my-custom-id]]"
    ]

  , testGroup "lists"
    [ "bullet task list"
      =: bulletList [plain "☐ a", plain "☒ b"]
      =?> T.unlines
          [ "- [ ] a"
          , "- [X] b"
          ]
    , "ordered task list"
      =: orderedList [plain ("☐" <> space <> "a"), plain "☒ b"]
      =?> T.unlines
          [ "1. [ ] a"
          , "2. [X] b"
          ]
    , "ordered task list with starting number"
      =: orderedListWith
         (9, DefaultStyle, DefaultDelim)
         [plain ("☐" <> space <> "a"), plain "☒ b"]
      =?> T.unlines
          [ "9. [@9] [ ] a"
          , "10. [X] b"
          ]
    , test (orgWithOpts def) "bullet without task_lists" $
      bulletList [plain "☐ a", plain "☒ b"]
      =?> T.unlines
          [ "- ☐ a"
          , "- ☒ b"
          ]
    ]

  , testGroup "code blocks"
    [ "identifier"
      =: codeBlockWith ("abc", ["python"], []) "return True"
      =?> T.unlines
      [ "#+name: abc"
      , "#+begin_src python"
      , "return True"
      , "#+end_src"
      ]

    , "attributes"
      =: codeBlockWith ("", ["python"], [("cache", "yes"), ("noweb", "yes")])
                       "'Hello'"
      =?> T.unlines
      [ "#+begin_src python :cache yes :noweb yes"
      , "'Hello'"
      , "#+end_src"
      ]
    ]
  ]