Skip to content

Commit

Permalink
Add markdown-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
junjihashimoto committed Jun 11, 2018
1 parent 2fa57e3 commit 75d1cae
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 1 deletion.
1 change: 1 addition & 0 deletions yi-misc-modes/src/Yi/Config/Default/MiscModes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ configureMiscModes = do
addMode gnuMakeMode
addMode ottMode
addMode whitespaceMode
addMode markdownMode
72 changes: 72 additions & 0 deletions yi-misc-modes/src/Yi/Lexer/Markdown.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
-- -*- haskell -*-
-- Lexer for Markdown-file
-- This is based off the syntax as described in the github manual:
-- https://guides.github.com/features/mastering-markdown/
-- Maintainer: Junji Hashimoto
{
{-# OPTIONS -w #-}
module Yi.Lexer.Markdown ( lexer ) where
import Yi.Lexer.Alex hiding (tokenToStyle)
import Yi.Style
( Style ( .. )
, StyleName
)
import qualified Yi.Style as Style
}

$varChar = $printable # [\: \# \= \ \{ \} \( \)]


$space = [\ ]

markdown :-

<0>
{
^\`\`\` { m (const InComment) Style.commentStyle }
^\#+ { c Style.keywordStyle }
^$space*[\+\-\*] { c Style.keywordStyle }
^$space*[0-9]+\. { c Style.keywordStyle }
\!\[[^\]]*\]\([^\)]*\) { c Style.quoteStyle }
\[[^\]]*\]\([^\)]*\) { c Style.quoteStyle }
\[[^\]]*\]\[[^\]]*\] { c Style.quoteStyle }
\*[^\*]*\* { c Style.stringStyle }
\_[^\_]*\_ { c Style.stringStyle }
\*\*[^\*]*\*\* { c Style.stringStyle }
\_\_[^\_]*\_\_ { c Style.stringStyle }
\n
{ c Style.defaultStyle }
.
{ c Style.defaultStyle }
}

<comment>
{
^\`\`\` { m (const TopLevel) Style.commentStyle }
\n
{ c Style.commentStyle }
.
{ c Style.commentStyle }
}

{
data HlState =
TopLevel
| InComment
deriving Show
stateToInit TopLevel = 0
stateToInit InComment = comment

initState :: HlState
initState = TopLevel

type Token = StyleName

lexer :: StyleLexerASI HlState Token
lexer = StyleLexer
{ _tokenToStyle = id
, _styleLexer = commonLexer alexScanToken initState
}

#include "common.hsinc"
}
8 changes: 7 additions & 1 deletion yi-misc-modes/src/Yi/Modes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Yi.Modes (cMode, objectiveCMode, cppMode, cabalMode, clojureMode,
srmcMode, ocamlMode, ottMode, gnuMakeMode,
perlMode, pythonMode, javaMode, jsonMode, anyExtension,
svnCommitMode, whitespaceMode,
gitCommitMode, rubyMode
gitCommitMode, rubyMode, markdownMode
) where

import Lens.Micro.Platform ((%~), (&), (.~))
Expand All @@ -32,6 +32,7 @@ import qualified Yi.Lexer.GitCommit as GitCommit (Token, lexer)
import qualified Yi.Lexer.GNUMake as GNUMake (lexer)
import qualified Yi.Lexer.Java as Java (lexer)
import qualified Yi.Lexer.JSON as JSON (lexer)
import qualified Yi.Lexer.Markdown as Markdown (lexer)
import qualified Yi.Lexer.ObjectiveC as ObjectiveC (lexer)
import qualified Yi.Lexer.OCaml as OCaml (Token, lexer)
import qualified Yi.Lexer.Ott as Ott (lexer)
Expand Down Expand Up @@ -138,6 +139,11 @@ gnuMakeMode = styleMode GNUMake.lexer
matches "GNUmakefile" = True
matches filename = extensionMatches [ "mk" ] filename

markdownMode :: TokenBasedMode StyleName
markdownMode = styleMode Markdown.lexer
& modeNameA .~ "markdown"
& modeAppliesA .~ anyExtension [ "md", "markdown", "mdown", "mkdn", "mdwn", "mkd" ]

ottMode :: TokenBasedMode StyleName
ottMode = styleMode Ott.lexer
& modeNameA .~ "ott"
Expand Down
1 change: 1 addition & 0 deletions yi-misc-modes/yi-misc-modes.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ library
Yi.Lexer.JSON
Yi.Lexer.Java
Yi.Lexer.Latex
Yi.Lexer.Markdown
Yi.Lexer.OCaml
Yi.Lexer.ObjectiveC
Yi.Lexer.Ott
Expand Down

0 comments on commit 75d1cae

Please sign in to comment.