diff --git a/yi-misc-modes/src/Yi/Config/Default/MiscModes.hs b/yi-misc-modes/src/Yi/Config/Default/MiscModes.hs index 07e89abac..1d9374ead 100644 --- a/yi-misc-modes/src/Yi/Config/Default/MiscModes.hs +++ b/yi-misc-modes/src/Yi/Config/Default/MiscModes.hs @@ -21,3 +21,4 @@ configureMiscModes = do addMode gnuMakeMode addMode ottMode addMode whitespaceMode + addMode markdownMode diff --git a/yi-misc-modes/src/Yi/Lexer/Markdown.x b/yi-misc-modes/src/Yi/Lexer/Markdown.x new file mode 100644 index 000000000..4234251c9 --- /dev/null +++ b/yi-misc-modes/src/Yi/Lexer/Markdown.x @@ -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 } +} + + +{ + ^\`\`\` { 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" +} diff --git a/yi-misc-modes/src/Yi/Modes.hs b/yi-misc-modes/src/Yi/Modes.hs index d4b1b1be6..bdb7afd2f 100644 --- a/yi-misc-modes/src/Yi/Modes.hs +++ b/yi-misc-modes/src/Yi/Modes.hs @@ -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 ((%~), (&), (.~)) @@ -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) @@ -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" diff --git a/yi-misc-modes/yi-misc-modes.cabal b/yi-misc-modes/yi-misc-modes.cabal index 15fac2a75..a4d1ed0b4 100644 --- a/yi-misc-modes/yi-misc-modes.cabal +++ b/yi-misc-modes/yi-misc-modes.cabal @@ -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