{- This module was generated from data in the Kate syntax highlighting file markdown.xml, version 1.3, by Darrin Yeager, Claes Holmerson -} module Text.Highlighting.Kate.Syntax.Markdown (highlight, parseExpression, syntaxName, syntaxExtensions) where import Text.Highlighting.Kate.Types import Text.Highlighting.Kate.Common import Text.ParserCombinators.Parsec hiding (State) import Control.Monad.State import Data.Char (isSpace) -- | Full name of language. syntaxName :: String syntaxName = "Markdown" -- | Filename extensions for this language. syntaxExtensions :: String syntaxExtensions = "*.md;*.mmd;*.markdown" -- | Highlight source code using this syntax definition. highlight :: String -> [SourceLine] highlight input = evalState (mapM parseSourceLine $ lines input) startingState parseSourceLine :: String -> State SyntaxState SourceLine parseSourceLine = mkParseSourceLine (parseExpression Nothing) -- | Parse an expression using appropriate local context. parseExpression :: Maybe (String,String) -> KateParser Token parseExpression mbcontext = do (lang,cont) <- maybe currentContext return mbcontext result <- parseRules (lang,cont) optional $ do eof updateState $ \st -> st{ synStPrevChar = '\n' } pEndLine return result startingState = SyntaxState {synStContexts = [("Markdown","Normal Text")], synStLineNumber = 0, synStPrevChar = '\n', synStPrevNonspace = False, synStCaseSensitive = True, synStKeywordCaseSensitive = True, synStCaptures = []} pEndLine = do updateState $ \st -> st{ synStPrevNonspace = False } context <- currentContext contexts <- synStContexts `fmap` getState if length contexts >= 2 then case context of ("Markdown","Normal Text") -> return () ("Markdown","blockquote") -> (popContext) >> pEndLine ("Markdown","bullet") -> (popContext) >> pEndLine ("Markdown","numlist") -> (popContext) >> pEndLine ("Markdown","comment") -> return () ("Markdown","inc") -> return () _ -> return () else return () withAttribute attr txt = do when (null txt) $ fail "Parser matched no text" updateState $ \st -> st { synStPrevChar = last txt , synStPrevNonspace = synStPrevNonspace st || not (all isSpace txt) } return (attr, txt) regex_'23'5cs'2e'2a'5b'23'5d'3f'24 = compileRegex True "#\\s.*[#]?$" regex_'23'23'5cs'2e'2a'5b'23'5d'3f'24 = compileRegex True "##\\s.*[#]?$" regex_'23'23'23'5cs'2e'2a'5b'23'5d'3f'24 = compileRegex True "###\\s.*[#]?$" regex_'23'23'23'23'5cs'2e'2a'5b'23'5d'3f'24 = compileRegex True "####\\s.*[#]?$" regex_'23'23'23'23'23'5cs'2e'2a'5b'23'5d'3f'24 = compileRegex True "#####\\s.*[#]?$" regex_'23'23'23'23'23'23'5cs'2e'2a'5b'23'5d'3f'24 = compileRegex True "######\\s.*[#]?$" regex_'5cs'2a'28'5b'5c'2a'5c'2d'5f'5d'5cs'3f'29'7b3'2c'7d'5cs'2a = compileRegex True "\\s*([\\*\\-_]\\s?){3,}\\s*" regex_'28'5cs'7c'5e'29'5b'5c'2a'5f'5d'7b2'7d'5b'5e'5cs'5d'7b1'7d'5b'5e'5c'2a'5f'5d'2b'5b'5c'2a'5f'5d'7b2'7d'28'5cs'7c'5c'2e'7c'2c'7c'3b'7c'3a'7c'5c'2d'7c'5c'3f'7c'24'29 = compileRegex True "(\\s|^)[\\*_]{2}[^\\s]{1}[^\\*_]+[\\*_]{2}(\\s|\\.|,|;|:|\\-|\\?|$)" regex_'28'5cs'7c'5e'29'5b'5c'2a'5f'5d'7b1'7d'5b'5e'5cs'5d'7b1'7d'5b'5e'5c'2a'5f'5d'2b'5b'5c'2a'5f'5d'7b1'7d'28'5cs'7c'5c'2e'7c'2c'7c'3b'7c'3a'7c'5c'2d'7c'5c'3f'7c'24'29 = compileRegex True "(\\s|^)[\\*_]{1}[^\\s]{1}[^\\*_]+[\\*_]{1}(\\s|\\.|,|;|:|\\-|\\?|$)" regex_'28'5cs'7c'5e'29'5b'5c'2a'5f'5d'7b3'7d'5b'5e'5c'2a'5f'5d'2b'5b'5c'2a'5f'5d'7b3'7d'28'5cs'7c'5c'2e'7c'2c'7c'3b'7c'3a'7c'5c'2d'7c'5c'3f'7c'24'29 = compileRegex True "(\\s|^)[\\*_]{3}[^\\*_]+[\\*_]{3}(\\s|\\.|,|;|:|\\-|\\?|$)" regex_'28'5b'5cs'5d'7b4'2c'7d'7c'5ct'2b'29'2e'2a'24 = compileRegex True "([\\s]{4,}|\\t+).*$" regex_'5b'5c'2a'5c'2b'5c'2d'5d'5cs = compileRegex True "[\\*\\+\\-]\\s" regex_'5b'5cd'5d'2b'5c'2e'5cs = compileRegex True "[\\d]+\\.\\s" regex_'28Title'7cAuthor'7cDate'7cCopyright'7cRevision'7cCSS'7cLaTeX'5c_XSLT'7cCategories'7cTags'7cBaseName'7cExcerpt'29'3a'28'2e'2a'29'2b'24 = compileRegex True "(Title|Author|Date|Copyright|Revision|CSS|LaTeX\\ XSLT|Categories|Tags|BaseName|Excerpt):(.*)+$" regex_'2d'2d'3e = compileRegex True "-->" regex_'60'5b'5e'60'5d'2b'60 = compileRegex True "`[^`]+`" regex_'3c'21'2d'2d = compileRegex True "