Add tree-sitter-markdown, set up simple markdown higlighting

This commit is contained in:
Max Brunsfeld 2021-12-05 21:37:31 -08:00
parent 026c3476db
commit b1ed9c88a4
7 changed files with 61 additions and 2 deletions

View file

@ -86,6 +86,7 @@ tiny_http = "0.8"
toml = "0.5"
tree-sitter = "0.20.0"
tree-sitter-rust = "0.20.0"
tree-sitter-markdown = { git = "https://github.com/maxbrunsfeld/tree-sitter-markdown", rev = "b2b4eefd51ada972ef8bb581b83b6b8e7a28c7a6" }
url = "2.2"
[dev-dependencies]

View file

@ -50,3 +50,10 @@ comment = "#6a9955"
property = "#4e94ce"
variant = "#4fc1ff"
constant = "#9cdcfe"
title = { color = "#9cdcfe", weight = "bold" }
emphasis = "#4ec9b0"
"emphasis.strong" = { color = "#4ec9b0", weight = "bold" }
link_uri = { color = "#6a9955", underline = true }
link_text = { color = "#cb8f77", italic = true }
list_marker = "#4e94ce"

View file

@ -50,3 +50,10 @@ comment = "#6a9955"
property = "#4e94ce"
variant = "#4fc1ff"
constant = "#9cdcfe"
title = { color = "#9cdcfe", weight = "bold" }
emphasis = "#4ec9b0"
"emphasis.strong" = { color = "#4ec9b0", weight = "bold" }
link_uri = { color = "#6a9955", underline = true }
link_text = { color = "#cb8f77", italic = true }
list_marker = "#4e94ce"

View file

@ -49,4 +49,11 @@ number = "#b5cea8"
comment = "#6a9955"
property = "#4e94ce"
variant = "#4fc1ff"
constant = "#9cdcfe"
constant = "#5a9ccc"
title = { color = "#5a9ccc", weight = "bold" }
emphasis = "#267f29"
"emphasis.strong" = { color = "#267f29", weight = "bold" }
link_uri = { color = "#6a9955", underline = true }
link_text = { color = "#a82121", italic = true }
list_marker = "#4e94ce"

View file

@ -0,0 +1,24 @@
(emphasis) @emphasis
(strong_emphasis) @emphasis.strong
[
(atx_heading)
(setext_heading)
] @title
[
(list_marker_plus)
(list_marker_minus)
(list_marker_star)
(list_marker_dot)
(list_marker_parenthesis)
] @list_marker
[
(indented_code_block)
(fenced_code_block)
(code_span)
] @text.literal
(link_destination) @link_uri
(link_text) @link_text

View file

@ -27,8 +27,11 @@ fn rust() -> Language {
}
fn markdown() -> Language {
let grammar = tree_sitter_markdown::language();
let config = toml::from_slice(&LanguageDir::get("markdown/config.toml").unwrap().data).unwrap();
Language::new(config, None)
Language::new(config, Some(grammar))
.with_highlights_query(load_query("markdown/highlights.scm").as_ref())
.unwrap()
}
fn load_query(path: &str) -> Cow<'static, str> {