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

Max Brunsfeld created

Change summary

Cargo.lock                                   | 10 +++++++++
crates/zed/Cargo.toml                        |  1 
crates/zed/assets/themes/black.toml          |  7 ++++++
crates/zed/assets/themes/dark.toml           |  7 ++++++
crates/zed/assets/themes/light.toml          |  9 +++++++
crates/zed/languages/markdown/highlights.scm | 24 ++++++++++++++++++++++
crates/zed/src/language.rs                   |  5 +++
7 files changed, 61 insertions(+), 2 deletions(-)

Detailed changes

Cargo.lock 🔗

@@ -5143,6 +5143,15 @@ dependencies = [
  "regex",
 ]
 
+[[package]]
+name = "tree-sitter-markdown"
+version = "0.0.1"
+source = "git+https://github.com/maxbrunsfeld/tree-sitter-markdown?rev=b2b4eefd51ada972ef8bb581b83b6b8e7a28c7a6#b2b4eefd51ada972ef8bb581b83b6b8e7a28c7a6"
+dependencies = [
+ "cc",
+ "tree-sitter",
+]
+
 [[package]]
 name = "tree-sitter-rust"
 version = "0.20.0"
@@ -5730,6 +5739,7 @@ dependencies = [
  "tiny_http",
  "toml",
  "tree-sitter",
+ "tree-sitter-markdown",
  "tree-sitter-rust",
  "unindent",
  "url",

crates/zed/Cargo.toml 🔗

@@ -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]

crates/zed/assets/themes/black.toml 🔗

@@ -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"

crates/zed/assets/themes/dark.toml 🔗

@@ -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"

crates/zed/assets/themes/light.toml 🔗

@@ -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"

crates/zed/languages/markdown/highlights.scm 🔗

@@ -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

crates/zed/src/language.rs 🔗

@@ -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> {