Skip to content

Commit 25c51d2

Browse files
committed
add Markdown support
1 parent f2c195f commit 25c51d2

File tree

5 files changed

+1886
-0
lines changed

5 files changed

+1886
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ For example:
8686
- Elm
8787
- Haskell
8888
- JavaScript
89+
- Markdown
8990
- PHP
9091
- Ruby
9192
- Rust

build.rs

+18
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@ fn main() {
9292
.file(javascript_dir.join("scanner.c"))
9393
.compile("tree_sitter_javascript_scanner");
9494

95+
// markdown
96+
let markdown_dir: PathBuf = ["vendor", "tree-sitter-markdown", "src"].iter().collect();
97+
98+
println!("cargo:rerun-if-changed=vendor/tree-sitter-markdown/src/parser.c");
99+
cc::Build::new()
100+
.include(&markdown_dir)
101+
.warnings(false)
102+
.file(markdown_dir.join("parser.c"))
103+
.compile("tree-sitter-markdown");
104+
105+
println!("cargo:rerun-if-changed=vendor/tree-sitter-markdown/src/scanner.cc");
106+
cc::Build::new()
107+
.include(&markdown_dir)
108+
.cpp(true)
109+
.warnings(false)
110+
.file(markdown_dir.join("scanner.cc"))
111+
.compile("tree_sitter_markdown_scanner");
112+
95113
// php
96114
let php_dir: PathBuf = ["vendor", "tree-sitter-php", "src"].iter().collect();
97115

src/language.rs

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub enum Language {
99
Elm,
1010
Haskell,
1111
JavaScript,
12+
Markdown,
1213
Php,
1314
Ruby,
1415
Rust,
@@ -23,6 +24,7 @@ impl Language {
2324
Language::Elm,
2425
Language::Haskell,
2526
Language::JavaScript,
27+
Language::Markdown,
2628
Language::Php,
2729
Language::Ruby,
2830
Language::Rust,
@@ -38,6 +40,7 @@ impl Language {
3840
Language::Elm => tree_sitter_elm(),
3941
Language::Haskell => tree_sitter_haskell(),
4042
Language::JavaScript => tree_sitter_javascript(),
43+
Language::Markdown => tree_sitter_markdown(),
4144
Language::Php => tree_sitter_php(),
4245
Language::Ruby => tree_sitter_ruby(),
4346
Language::Rust => tree_sitter_rust(),
@@ -57,6 +60,7 @@ impl Language {
5760
Language::Elm => "elm",
5861
Language::Haskell => "haskell",
5962
Language::JavaScript => "js",
63+
Language::Markdown => "markdown",
6064
Language::Php => "php",
6165
Language::Ruby => "ruby",
6266
Language::Rust => "rust",
@@ -75,6 +79,7 @@ impl FromStr for Language {
7579
"elm" => Ok(Language::Elm),
7680
"haskell" => Ok(Language::Haskell),
7781
"javascript" => Ok(Language::JavaScript),
82+
"markdown" => Ok(Language::Markdown),
7883
"php" => Ok(Language::Php),
7984
"ruby" => Ok(Language::Ruby),
8085
"rust" => Ok(Language::Rust),
@@ -100,6 +105,7 @@ impl Display for Language {
100105
Language::Elm => f.write_str("elm"),
101106
Language::Haskell => f.write_str("haskell"),
102107
Language::JavaScript => f.write_str("javascript"),
108+
Language::Markdown => f.write_str("markdown"),
103109
Language::Php => f.write_str("php"),
104110
Language::Ruby => f.write_str("ruby"),
105111
Language::Rust => f.write_str("rust"),
@@ -148,6 +154,7 @@ extern "C" {
148154
fn tree_sitter_elm() -> tree_sitter::Language;
149155
fn tree_sitter_haskell() -> tree_sitter::Language;
150156
fn tree_sitter_javascript() -> tree_sitter::Language;
157+
fn tree_sitter_markdown() -> tree_sitter::Language;
151158
fn tree_sitter_php() -> tree_sitter::Language;
152159
fn tree_sitter_ruby() -> tree_sitter::Language;
153160
fn tree_sitter_rust() -> tree_sitter::Language;

src/main.rs

+14
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,20 @@ mod tests {
326326
]))
327327
}
328328

329+
#[test]
330+
fn all_markdown() {
331+
insta::assert_snapshot!(call(&[
332+
"tree-grepper",
333+
"-q",
334+
"markdown",
335+
"(_)",
336+
"--format=pretty-json",
337+
"--sort",
338+
"--no-gitignore",
339+
"vendor/tree-sitter-markdown/README.md",
340+
]))
341+
}
342+
329343
#[test]
330344
fn all_php() {
331345
insta::assert_snapshot!(call(&[

0 commit comments

Comments
 (0)