-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathUnlit.idr
More file actions
67 lines (55 loc) · 1.78 KB
/
Copy pathUnlit.idr
File metadata and controls
67 lines (55 loc) · 1.78 KB
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
module Parser.Unlit
import public Text.Literate
import Data.String
%default total
public export
data LiterateModes = Bird | Org | CMark
export
styleBird : LiterateStyle
styleBird = MkLitStyle Nil [">", "<"] [".lidr"]
export
styleOrg : LiterateStyle
styleOrg = MkLitStyle
[ ("#+BEGIN_SRC idris","#+END_SRC")
, ("#+begin_src idris","#+end_src")
, ("#+COMMENT idris","#+END_COMMENT")
, ("#+comment idris","#+end_comment")]
["#+IDRIS:"]
[".org"]
export
styleCMark : LiterateStyle
styleCMark = MkLitStyle [("```idris", "```")] Nil [".md", ".markdown"]
export
isLitFile : String -> Maybe LiterateStyle
isLitFile fname =
case isStyle styleBird of
Just s => Just s
Nothing => case isStyle styleOrg of
Just s => Just s
Nothing => isStyle styleCMark
where
hasSuffix : String -> Bool
hasSuffix ext = isSuffixOf ext fname
isStyle : LiterateStyle -> Maybe LiterateStyle
isStyle style =
if any hasSuffix (file_extensions style)
then Just style
else Nothing
export
isLitLine : String -> (Maybe String, String)
isLitLine str =
case isLiterateLine styleBird str of
(Just l, s) => (Just l, s)
otherwise => case isLiterateLine styleOrg str of
(Just l, s) => (Just l, s)
otherwise => case isLiterateLine styleCMark str of
(Just l, s) => (Just l, s)
otherwise => (Nothing, str)
export
unlit : Maybe LiterateStyle -> String -> Either LiterateError String
unlit Nothing str = Right str
unlit (Just s) str = unlit s str
export
relit : Maybe String -> String -> String
relit Nothing str = str
relit (Just mark) str = unwords [mark, str]