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

Highlight Mint code in Markdown content. #677

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gdotdesign
Copy link
Member

This PR implements highlighting for Mint language blocks in Markdown content in here documents.

@gdotdesign gdotdesign added the enhancement New feature or request label Sep 29, 2023
@gdotdesign gdotdesign added this to the 0.20.0 milestone Sep 29, 2023
@gdotdesign gdotdesign self-assigned this Sep 29, 2023
@farism
Copy link
Contributor

farism commented Sep 29, 2023

This will be useful for static docs generator too. 👍

I was not a huge fan of this

Comment on lines +73 to +94
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
Copy link
Member

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
Suggested change
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

@gdotdesign
Copy link
Member Author

This PR is now outdated and will be superseded by the compiler refactor in #680 and will close when that's merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

3 participants