diff --git a/include/eepp/ui/doc/syntaxdefinition.hpp b/include/eepp/ui/doc/syntaxdefinition.hpp index 7eb8788cf..efb58c4f2 100644 --- a/include/eepp/ui/doc/syntaxdefinition.hpp +++ b/include/eepp/ui/doc/syntaxdefinition.hpp @@ -42,6 +42,7 @@ struct EE_API SyntaxPattern { IsRootSelfInclude = 1 << 3, IsRangedMatch = 1 << 5, IsSourceInclude = 1 << 6, + IsAutomaticallyAdded = 1 << 7, }; static SyntaxDefMap SyntaxStyleTypeCache; @@ -108,6 +109,8 @@ struct EE_API SyntaxPattern { inline bool isRangedMatch() const { return flags & Flags::IsRangedMatch; } + inline bool isAutomaticallyAdded() const { return flags & Flags::IsAutomaticallyAdded; } + inline bool isSimpleRangedMatch() const { return isRangedMatch() && !hasContentScope() && !hasSyntax(); } diff --git a/src/eepp/ui/doc/languages/markdown.cpp b/src/eepp/ui/doc/languages/markdown.cpp index aa1cce3b8..2f082ebea 100644 --- a/src/eepp/ui/doc/languages/markdown.cpp +++ b/src/eepp/ui/doc/languages/markdown.cpp @@ -15,21 +15,52 @@ void addMarkdown() { { "Markdown", { "%.md$", "%.markdown$" }, { - { { "\\." }, "normal" }, { { "```[%w \t%+%-#]+", "```" }, "function", dynSyntax }, + { { "include", "#comments" }, "normal" }, + { { "include", "#strings" }, "normal" }, + { { "include", "#enumerations" }, "normal" }, + { { "include", "#decorations" }, "normal" }, + { { "include", "#headings" }, "normal" }, + { { "include", "#links" }, "normal" }, + }, + {}, + "", + {} } ); + + sd.addRepositories( { + + { "comments", + { { { "" }, "comment" }, - { { "```", "```" }, "string" }, - { { "``", "``" }, "string" }, - { { "`", "`" }, "string" }, - { { "~~", "~~", "\\" }, "type" }, { { "%-%-%-+" }, "comment" }, - { { "%*%s+" }, "operator" }, - { { "%*", "[%*\n]", "\\" }, "operator" }, - { { "%s%_", "[%_\n]", "\\" }, "type" }, - { { "^%_", "[%_\n]", "\\" }, "type" }, - { { "^#.-\n" }, "keyword" }, - { { "\n#.-\n" }, "keyword" }, - { { "\n%_", "[%_\n]", "\\" }, "type" }, + } }, + + { "strings", + { + { { "```", "```" }, "string" }, + { { "``", "(``|\n)" }, { "string" }, {}, "", SyntaxPatternMatchType::RegEx }, + { { "`", "[`\n]" }, "string" }, + { { "^%s*>+%s.*" }, "string" }, + } }, + + { "enumerations", + { + { { "^%s*%*%s" }, "number" }, + { { "^%s*%-%s" }, "number" }, + { { "^%s*%+%s" }, "number" }, + { { "^%s*[0-9]+[%.%)]%s" }, "number" }, + { { "%*%s+" }, "number" }, + } }, + + { "headings", + { + { { "^#.+\n" }, "keyword" }, + { { "\n#.+\n" }, "keyword" }, + { { "^=+\n" }, "keyword" }, + } }, + + { "links", + { { { "%[!%[([^%]]-)%]%((https?://[%w_.~!*:@&+$/?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/" "?[%w_.~!*:@&+$/?%%#=-]*)%)%]%((https?://[%w_.~!*:@&+$/" "?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/?[%w_.~!*:@&+$/?%%#=-]*)%)" }, @@ -43,16 +74,108 @@ void addMarkdown() { { { "https?://[%w_.~!*:@&+$/?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/?[%w_.~!*:@&+$/" "?%%#=-]*" }, "link" }, + } }, - }, + { "decorations_bold", { + { { "\\*\\*(?!\\*)", "(\\*\\*|\n)" }, + { "type,bold", "type,bold", "type,bold" }, + {}, + "", + SyntaxPatternMatchType::RegEx, + { + { { "include", "$self" }, "type,bold" }, + } }, + { { "__(?!_)", "(__|\n)" }, + { "type,bold", "type,bold", "type,bold" }, + {}, + "", + SyntaxPatternMatchType::RegEx, + { + { { "include", "$self" }, "type,bold" }, + } }, + } }, - }, - "", - {} + { "decorations_italic", + { + { { "%s%_%f[^_]", "[%_\n]" }, + { "type,italic" }, + {}, + "", + SyntaxPatternMatchType::LuaPattern, + { + { { "include", "$self" }, + "type,italic", + "", + SyntaxPatternMatchType::LuaPattern }, + } }, - } ); + { { "^%_%f[^_]", "[%_\n]" }, + { "type,italic" }, + {}, + "", + SyntaxPatternMatchType::LuaPattern, + { + { { "include", "$self" }, "type,italic" }, + } }, + { { "%s%*%f[^*]", "[%*\n]" }, + { "type,italic" }, + {}, + "", + SyntaxPatternMatchType::LuaPattern, + { + { { "include", "$self" }, "type,italic" }, + } }, + + { { "^%*%f[^*]", "[%*\n]" }, + { "type,italic" }, + {}, + "", + SyntaxPatternMatchType::LuaPattern, + { + { { "include", "$self" }, "type,italic" }, + } }, + + { { "\n%_%f[^_]", "[%_\n]" }, + { "type,italic" }, + {}, + "", + SyntaxPatternMatchType::LuaPattern, + { + { { "include", "$self" }, "type,italic" }, + } }, + } }, + + { "decorations_strikethrough", + { + { { "~~~" }, "normal" }, + { { "~~", "(~~|\n)" }, + { "type,strikethrough" }, + {}, + "", + SyntaxPatternMatchType::RegEx, + { + { { "include", "$self" }, "type,strikethrough" }, + } }, + { { "~", "(~|\n)" }, + { "type,strikethrough" }, + {}, + "", + SyntaxPatternMatchType::RegEx, + { + { { "include", "$self" }, "type,strikethrough" }, + } }, + } }, + + { "decorations", + { + { { "include", "#decorations_bold" }, "normal" }, + { { "include", "#decorations_italic" }, "normal" }, + { { "include", "#decorations_strikethrough" }, "normal" }, + } }, + + } ); sd.setFoldRangeType( FoldRangeType::Markdown ); sd.setBlockComment( { "" } ); } diff --git a/src/eepp/ui/doc/syntaxdefinition.cpp b/src/eepp/ui/doc/syntaxdefinition.cpp index 2c0ed9cd1..d3456752d 100644 --- a/src/eepp/ui/doc/syntaxdefinition.cpp +++ b/src/eepp/ui/doc/syntaxdefinition.cpp @@ -169,6 +169,7 @@ SyntaxDefinition::SyntaxDefinition( updatePatternsState( *this, mPatterns ); mPatterns.emplace_back( SyntaxPattern{ { "%s+" }, "normal" } ); mPatterns.emplace_back( SyntaxPattern{ { "%w+%f[%s]" }, "normal" } ); + mPatterns.back().flags |= SyntaxPattern::Flags::IsAutomaticallyAdded; } for ( const auto& symbol : mSymbolNames ) { mSymbolsHashes.insert( diff --git a/src/eepp/ui/doc/syntaxtokenizer.cpp b/src/eepp/ui/doc/syntaxtokenizer.cpp index 7b9ff4708..35e54ffb9 100644 --- a/src/eepp/ui/doc/syntaxtokenizer.cpp +++ b/src/eepp/ui/doc/syntaxtokenizer.cpp @@ -716,6 +716,9 @@ _tokenize( const SyntaxDefinition& syntax, const std::string& text, const Syntax innerPtrn->patterns[0][0] == '^' ) continue; + if ( patternStack.size() > 1 && innerPtrn->isAutomaticallyAdded() ) + continue; + if ( std::find( triedPatterns.begin(), triedPatterns.end(), patternState ) != triedPatterns.end() ) continue;