Skip to content

Commit 20f34da

Browse files
Add markdown-mode
1 parent 2fa57e3 commit 20f34da

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

yi-misc-modes/src/Yi/Config/Default/MiscModes.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ configureMiscModes = do
2121
addMode gnuMakeMode
2222
addMode ottMode
2323
addMode whitespaceMode
24+
addMode markdownMode
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
-- -*- haskell -*-
2+
-- Lexer for Markdown-file
3+
-- This is based off the syntax as described in the github manual:
4+
-- https://guides.github.com/features/mastering-markdown/
5+
-- Maintainer: Junji Hashimoto
6+
{
7+
{-# OPTIONS -w #-}
8+
module Yi.Lexer.Markdown ( lexer ) where
9+
import Yi.Lexer.Alex hiding (tokenToStyle)
10+
import Yi.Style
11+
( Style ( .. )
12+
, StyleName
13+
)
14+
import qualified Yi.Style as Style
15+
}
16+
17+
$varChar = $printable # [\: \# \= \ \{ \} \( \)]
18+
19+
20+
$space = [\ ]
21+
22+
markdown :-
23+
24+
<0>
25+
{
26+
^\`\`\` { m (const InComment) Style.commentStyle }
27+
^\#+ { c Style.keywordStyle }
28+
^$space*[\+\-\*] { c Style.keywordStyle }
29+
^$space*[0-9]+\. { c Style.keywordStyle }
30+
\!\[[^\]]*\]\([^\)]*\) { c Style.quoteStyle }
31+
\[[^\]]*\]\([^\)]*\) { c Style.quoteStyle }
32+
\[[^\]]*\]\[[^\]]*\] { c Style.quoteStyle }
33+
\*[^\*]*\* { c Style.stringStyle }
34+
\_[^\_]*\_ { c Style.stringStyle }
35+
\*\*[^\*]*\*\* { c Style.stringStyle }
36+
\_\_[^\_]*\_\_ { c Style.stringStyle }
37+
\n
38+
{ c Style.defaultStyle }
39+
.
40+
{ c Style.defaultStyle }
41+
}
42+
43+
<comment>
44+
{
45+
^\`\`\` { m (const TopLevel) Style.commentStyle }
46+
\n
47+
{ c Style.commentStyle }
48+
.
49+
{ c Style.commentStyle }
50+
}
51+
52+
{
53+
data HlState =
54+
TopLevel
55+
| InComment
56+
deriving Show
57+
stateToInit TopLevel = 0
58+
stateToInit InComment = comment
59+
60+
initState :: HlState
61+
initState = TopLevel
62+
63+
type Token = StyleName
64+
65+
lexer :: StyleLexerASI HlState Token
66+
lexer = StyleLexer
67+
{ _tokenToStyle = id
68+
, _styleLexer = commonLexer alexScanToken initState
69+
}
70+
71+
#include "common.hsinc"
72+
}

yi-misc-modes/src/Yi/Modes.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Yi.Modes (cMode, objectiveCMode, cppMode, cabalMode, clojureMode,
1515
srmcMode, ocamlMode, ottMode, gnuMakeMode,
1616
perlMode, pythonMode, javaMode, jsonMode, anyExtension,
1717
svnCommitMode, whitespaceMode,
18-
gitCommitMode, rubyMode
18+
gitCommitMode, rubyMode, markdownMode
1919
) where
2020

2121
import Lens.Micro.Platform ((%~), (&), (.~))
@@ -32,6 +32,7 @@ import qualified Yi.Lexer.GitCommit as GitCommit (Token, lexer)
3232
import qualified Yi.Lexer.GNUMake as GNUMake (lexer)
3333
import qualified Yi.Lexer.Java as Java (lexer)
3434
import qualified Yi.Lexer.JSON as JSON (lexer)
35+
import qualified Yi.Lexer.Markdown as Markdown (lexer)
3536
import qualified Yi.Lexer.ObjectiveC as ObjectiveC (lexer)
3637
import qualified Yi.Lexer.OCaml as OCaml (Token, lexer)
3738
import qualified Yi.Lexer.Ott as Ott (lexer)
@@ -138,6 +139,11 @@ gnuMakeMode = styleMode GNUMake.lexer
138139
matches "GNUmakefile" = True
139140
matches filename = extensionMatches [ "mk" ] filename
140141

142+
markdownMode :: TokenBasedMode StyleName
143+
markdownMode = styleMode Markdown.lexer
144+
& modeNameA .~ "markdown"
145+
& modeAppliesA .~ anyExtension [ "md" ]
146+
141147
ottMode :: TokenBasedMode StyleName
142148
ottMode = styleMode Ott.lexer
143149
& modeNameA .~ "ott"

yi-misc-modes/yi-misc-modes.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ library
5151
Yi.Lexer.JSON
5252
Yi.Lexer.Java
5353
Yi.Lexer.Latex
54+
Yi.Lexer.Markdown
5455
Yi.Lexer.OCaml
5556
Yi.Lexer.ObjectiveC
5657
Yi.Lexer.Ott

0 commit comments

Comments
 (0)