-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Highlight Mint code in Markdown content. #677
Conversation
This will be useful for static docs generator too. 👍 I was not a huge fan of this |
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
if language == "mint" | ||
parser = Parser.new(node.text, "source.mint") | ||
parser.parse_any | ||
|
||
parts = | ||
SemanticTokenizer.tokenize(parser.ast) | ||
|
||
parts.each do |item| | ||
case item | ||
in String | ||
@io << '`' << item.gsub('`', "\\`") << '`' | ||
in Tuple(SemanticTokenizer::TokenType, String) | ||
tag("span", {"className" => item[0].to_s.underscore}) | ||
@io << '`' << item[1].gsub('`', "\\`") << '`' | ||
tag_end | ||
end | ||
|
||
@io << ',' | ||
end | ||
else | ||
@io << '`' << node.text.gsub('`', "\\`").strip << '`' | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest extracting this into a dedicated method:
def inline_code(io, code)
io << '`' << code.gsub('`', "\\`") << '`'
end
if language == "mint" | |
parser = Parser.new(node.text, "source.mint") | |
parser.parse_any | |
parts = | |
SemanticTokenizer.tokenize(parser.ast) | |
parts.each do |item| | |
case item | |
in String | |
@io << '`' << item.gsub('`', "\\`") << '`' | |
in Tuple(SemanticTokenizer::TokenType, String) | |
tag("span", {"className" => item[0].to_s.underscore}) | |
@io << '`' << item[1].gsub('`', "\\`") << '`' | |
tag_end | |
end | |
@io << ',' | |
end | |
else | |
@io << '`' << node.text.gsub('`', "\\`").strip << '`' | |
end | |
if language == "mint" | |
parser = Parser.new(node.text, "source.mint") | |
parser.parse_any | |
parts = | |
SemanticTokenizer.tokenize(parser.ast) | |
parts.each do |item| | |
case item | |
in String | |
inline_code(@io, item) | |
in Tuple(SemanticTokenizer::TokenType, String) | |
tag("span", {"className" => item[0].to_s.underscore}) | |
inline_code(@io, item[1]) | |
tag_end | |
end | |
@io << ',' | |
end | |
else | |
inline_code(@io, node.text.strip) | |
end |
This PR is now outdated and will be superseded by the compiler refactor in #680 and will close when that's merged. |
Closing, since this is included in the |
This PR implements highlighting for Mint language blocks in Markdown content in here documents.