Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here is a Markdown LanguageDefinition I wrote #155

Open
UnidayStudio opened this issue Aug 25, 2024 · 0 comments
Open

Here is a Markdown LanguageDefinition I wrote #155

UnidayStudio opened this issue Aug 25, 2024 · 0 comments

Comments

@UnidayStudio
Copy link

I needed Markdown code highlight to my Game Engine (Cave Engine), so I wrote this one and decided to share here in case anyone want to use it as well or to merge into master. Enjoy! 😃

const TextEditor::LanguageDefinition& TextEditor::LanguageDefinition::Markdown() {
	static bool inited = false;
	static LanguageDefinition langDef;
	if (!inited) {
		langDef.mName = "Markdown";

		// Headers
		langDef.mTokenRegexStrings.push_back(std::make_pair("#+.*", TextEditor::PaletteIndex::Keyword));

		// Emphasis
		langDef.mTokenRegexStrings.push_back(std::make_pair("\\*\\*[^\\*]+\\*\\*", TextEditor::PaletteIndex::Keyword)); // bold
		langDef.mTokenRegexStrings.push_back(std::make_pair("\\*[^\\*]+\\*", TextEditor::PaletteIndex::Keyword)); // italic
		langDef.mTokenRegexStrings.push_back(std::make_pair("~~[^~]+~~", TextEditor::PaletteIndex::Keyword)); // strikethrough

		// Links and Images
		langDef.mTokenRegexStrings.push_back(std::make_pair("\\!\\[.*\\]\\(.*\\)", TextEditor::PaletteIndex::String)); // image
		langDef.mTokenRegexStrings.push_back(std::make_pair("\\[.*\\]\\(.*\\)", TextEditor::PaletteIndex::String)); // link

		// Inline code
		langDef.mTokenRegexStrings.push_back(std::make_pair("`[^`]+`", TextEditor::PaletteIndex::Keyword));

		// Code blocks
		langDef.mTokenRegexStrings.push_back(std::make_pair("```.*```", TextEditor::PaletteIndex::Keyword));

		// Blockquotes
		langDef.mTokenRegexStrings.push_back(std::make_pair("^> .*", TextEditor::PaletteIndex::Comment));

		// Lists
		langDef.mTokenRegexStrings.push_back(std::make_pair("^- .*", TextEditor::PaletteIndex::Keyword));
		langDef.mTokenRegexStrings.push_back(std::make_pair("^\\* .*", TextEditor::PaletteIndex::Keyword));
		langDef.mTokenRegexStrings.push_back(std::make_pair("^\\d+\\. .*", TextEditor::PaletteIndex::Keyword));

		// Horizontal rules
		langDef.mTokenRegexStrings.push_back(std::make_pair("^(-{3,}|\\*{3,}|_{3,})$", TextEditor::PaletteIndex::Keyword));

		// Escaped characters
		langDef.mTokenRegexStrings.push_back(std::make_pair("\\\\.", TextEditor::PaletteIndex::Default));

		langDef.mCommentStart = "<!--";
		langDef.mCommentEnd = "-->";
		langDef.mSingleLineComment = "";

		langDef.mCaseSensitive = true;
		langDef.mAutoIndentation = false;

		langDef.mName = "Markdown";

		inited = true;
	}
	return langDef;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant