mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 11:32:13 +00:00
Merge pull request #78312 from Calinou/editor-add-markdown-highlighting
Add Markdown syntax highlighting to the script editor
This commit is contained in:
commit
fd75707035
@ -261,6 +261,52 @@ Ref<EditorSyntaxHighlighter> EditorJSONSyntaxHighlighter::_create() const {
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
void EditorMarkdownSyntaxHighlighter::_update_cache() {
|
||||
highlighter->set_text_edit(text_edit);
|
||||
highlighter->clear_keyword_colors();
|
||||
highlighter->clear_member_keyword_colors();
|
||||
highlighter->clear_color_regions();
|
||||
|
||||
// Disable automatic symbolic highlights, as these don't make sense for prose.
|
||||
highlighter->set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/text_color"));
|
||||
highlighter->set_number_color(EDITOR_GET("text_editor/theme/highlighting/text_color"));
|
||||
highlighter->set_member_variable_color(EDITOR_GET("text_editor/theme/highlighting/text_color"));
|
||||
highlighter->set_function_color(EDITOR_GET("text_editor/theme/highlighting/text_color"));
|
||||
|
||||
// Headings (any level).
|
||||
const Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color");
|
||||
highlighter->add_color_region("#", "", function_color);
|
||||
|
||||
// Bold.
|
||||
highlighter->add_color_region("**", "**", function_color);
|
||||
// `__bold__` syntax is not supported as color regions must begin with a symbol,
|
||||
// not a character that is valid in an identifier.
|
||||
|
||||
// Code (both inline code and triple-backticks code blocks).
|
||||
const Color code_color = EDITOR_GET("text_editor/theme/highlighting/engine_type_color");
|
||||
highlighter->add_color_region("`", "`", code_color);
|
||||
|
||||
// Link (both references and inline links with URLs). The URL is not highlighted.
|
||||
const Color link_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color");
|
||||
highlighter->add_color_region("[", "]", link_color);
|
||||
|
||||
// Quote.
|
||||
const Color quote_color = EDITOR_GET("text_editor/theme/highlighting/string_color");
|
||||
highlighter->add_color_region(">", "", quote_color, true);
|
||||
|
||||
// HTML comment, which is also supported in Markdown.
|
||||
const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color");
|
||||
highlighter->add_color_region("<!--", "-->", comment_color);
|
||||
}
|
||||
|
||||
Ref<EditorSyntaxHighlighter> EditorMarkdownSyntaxHighlighter::_create() const {
|
||||
Ref<EditorMarkdownSyntaxHighlighter> syntax_highlighter;
|
||||
syntax_highlighter.instantiate();
|
||||
return syntax_highlighter;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*** SCRIPT EDITOR ****/
|
||||
@ -4414,6 +4460,10 @@ ScriptEditor::ScriptEditor(WindowWrapper *p_wrapper) {
|
||||
json_syntax_highlighter.instantiate();
|
||||
register_syntax_highlighter(json_syntax_highlighter);
|
||||
|
||||
Ref<EditorMarkdownSyntaxHighlighter> markdown_syntax_highlighter;
|
||||
markdown_syntax_highlighter.instantiate();
|
||||
register_syntax_highlighter(markdown_syntax_highlighter);
|
||||
|
||||
_update_online_doc();
|
||||
}
|
||||
|
||||
|
@ -120,6 +120,24 @@ public:
|
||||
EditorJSONSyntaxHighlighter() { highlighter.instantiate(); }
|
||||
};
|
||||
|
||||
class EditorMarkdownSyntaxHighlighter : public EditorSyntaxHighlighter {
|
||||
GDCLASS(EditorMarkdownSyntaxHighlighter, EditorSyntaxHighlighter)
|
||||
|
||||
private:
|
||||
Ref<CodeHighlighter> highlighter;
|
||||
|
||||
public:
|
||||
virtual void _update_cache() override;
|
||||
virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); }
|
||||
|
||||
virtual PackedStringArray _get_supported_languages() const override { return PackedStringArray{ "md", "markdown" }; }
|
||||
virtual String _get_name() const override { return TTR("Markdown"); }
|
||||
|
||||
virtual Ref<EditorSyntaxHighlighter> _create() const override;
|
||||
|
||||
EditorMarkdownSyntaxHighlighter() { highlighter.instantiate(); }
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ScriptEditorQuickOpen : public ConfirmationDialog {
|
||||
|
Loading…
Reference in New Issue
Block a user