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

Support Markdown diff highilighting #380

Open
wants to merge 170 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
2ceb56b
Initial commit
MDeiml Nov 18, 2021
29a65c9
Create README.md
MDeiml Nov 18, 2021
b026a06
Fix README.md
MDeiml Nov 18, 2021
c59305b
Fix README.md again
MDeiml Nov 18, 2021
48eb1e9
Add documentation for external tokens
MDeiml Nov 18, 2021
31f61e3
Add external tokens for parsing emphasis
MDeiml Nov 18, 2021
42be6c0
Explicit whitespaces, _last_character_whitespace, _last_character_pun…
MDeiml Nov 19, 2021
55dd78b
Implement (single) emphasis with star delmiters
MDeiml Nov 19, 2021
5b31419
Implement strong emphasis (star)
MDeiml Nov 19, 2021
2811a8e
Implement emphasis with underscores
MDeiml Nov 19, 2021
c37435f
Update README.md
MDeiml Nov 19, 2021
104f9ca
Appease some tests
MDeiml Nov 19, 2021
74729f3
Fix fenced code block info strings with backticks
MDeiml Nov 19, 2021
5c969db
Remove lazy continuations
MDeiml Nov 20, 2021
9acf5ff
Remove _matching_done
MDeiml Nov 20, 2021
a4124c1
Make _block_continuation match all blocks
MDeiml Nov 20, 2021
7000f9c
Add lazy continuation
MDeiml Nov 20, 2021
7dc54a3
Tune dynamic precedence
MDeiml Nov 20, 2021
2b4a28a
More tests
MDeiml Nov 20, 2021
83e3fdd
Compress state
MDeiml Nov 20, 2021
3f7ab8d
Start implementing html stuff
MDeiml Nov 21, 2021
2b74ffe
Implement negative regexes for html_block
MDeiml Nov 22, 2021
7f6dbb7
Better html comments
MDeiml Nov 22, 2021
080715d
Update README.md
MDeiml Nov 22, 2021
6b80fa3
Better html tags
MDeiml Nov 22, 2021
c1487af
Avoid undefined behaviour
dimbleby Nov 22, 2021
c9d180a
Merge pull request #1 from dimbleby/undefined-behaviour
MDeiml Nov 23, 2021
b7ac10d
Remove explicit line breaks
MDeiml Nov 23, 2021
6e222a1
Update tests
MDeiml Nov 23, 2021
a1149e7
Fix infinite loop (#1)
MDeiml Nov 23, 2021
b2af030
Small fix for emphasis delmiters
MDeiml Nov 23, 2021
8408609
Emphasis does not actually work yet
MDeiml Nov 23, 2021
b970eb2
Update a bit of documentation
MDeiml Nov 23, 2021
55bae26
Metaprogramming and fix emphasis a bit
MDeiml Nov 23, 2021
f47f2b2
More robust newlines
MDeiml Nov 24, 2021
b00face
Nicer punctuation
MDeiml Nov 24, 2021
921ce06
Work on link_reference_definition
MDeiml Nov 24, 2021
a712b77
Fix #2
MDeiml Nov 24, 2021
b09f958
Inital implementation of link reference definitions done
MDeiml Nov 25, 2021
9c51158
Clean up corpus
MDeiml Nov 25, 2021
d1cd82a
Update README.md
MDeiml Nov 25, 2021
1aae8cb
Don't need external scanner for looseness
MDeiml Nov 26, 2021
2dc33d9
Trailing blank lines don't make list loose
MDeiml Nov 26, 2021
70513c8
Leading blank lines don't make list loose
MDeiml Nov 26, 2021
6a78a5e
Fix fenced code block
MDeiml Nov 27, 2021
432de1e
Fix example 258
MDeiml Nov 27, 2021
8e50beb
Fix example 261
MDeiml Nov 27, 2021
289c4cf
Update documentation. Rename some rules
MDeiml Nov 28, 2021
7e63613
html block type 7 does not interrupt paragraph
MDeiml Nov 28, 2021
8961396
Apparently I don't know how to write parenthesis. Fix #3
MDeiml Nov 28, 2021
2b986de
Don't parse inline html as one regex
MDeiml Nov 28, 2021
e7bc295
Implement hard line break
MDeiml Nov 28, 2021
51c5363
Fix ordered list items indentation
MDeiml Nov 28, 2021
84be099
Implement autolinks
MDeiml Nov 28, 2021
5737f91
Fix lists interrupting paragraphs a bit
MDeiml Nov 29, 2021
f2e91a5
Clean up code
MDeiml Nov 29, 2021
4fee7b6
More list item interrupting paragraph stuff
MDeiml Nov 29, 2021
cefba23
Fix Example 285
MDeiml Nov 29, 2021
e8d8ce4
Improve tight / loose lists
MDeiml Nov 29, 2021
be561ab
Rename list markers
MDeiml Nov 29, 2021
80b3e35
More loose / tight
MDeiml Nov 29, 2021
7ffeafa
Minor test fixes
MDeiml Nov 29, 2021
a27f5ae
Implement strong emphasis
MDeiml Nov 29, 2021
79f24b7
Fix example 474
MDeiml Nov 29, 2021
566b3ac
Fix some tests
MDeiml Nov 29, 2021
3e69456
Unfix some tests
MDeiml Nov 29, 2021
8d920f5
Rename shortcut link
MDeiml Nov 29, 2021
713130b
Begin implementing inline links
MDeiml Nov 29, 2021
f8614d2
More inline link tests
MDeiml Nov 29, 2021
47c49cb
No extras
MDeiml Nov 30, 2021
932df62
Don't need token.immediate any more
MDeiml Nov 30, 2021
d72a596
Begin implementing inlines in links
MDeiml Nov 30, 2021
727fbd4
Disallow brackets in link text
MDeiml Nov 30, 2021
7dc51ed
Start implementing images
MDeiml Nov 30, 2021
507dfb4
Fix some tests
MDeiml Nov 30, 2021
a9fe694
More tests
MDeiml Nov 30, 2021
05672fd
More tests
MDeiml Nov 30, 2021
7056158
Fix a lot of tests and implement reference links
MDeiml Nov 30, 2021
39e7d66
Correct remaining tests and fix some stuff
MDeiml Nov 30, 2021
4809bd0
Update README.md
MDeiml Nov 30, 2021
a1c0aed
Don't differentiate between tight and loose lists
MDeiml Dec 1, 2021
0f20e75
Fix example 163
MDeiml Dec 1, 2021
4ffc365
Fix example 258
MDeiml Dec 1, 2021
74d4b65
Better dynamic precedence
MDeiml Dec 1, 2021
a2ea2df
Investigate failing test cases
MDeiml Dec 1, 2021
8845d15
Fix #4
MDeiml Dec 1, 2021
10df88f
Add query files
MDeiml Dec 1, 2021
39bd0f8
Address some TODOs
MDeiml Dec 1, 2021
b2b4eef
Compile external scanner in rust build script
maxbrunsfeld Dec 6, 2021
ad8c329
Merge pull request #13 from maxbrunsfeld/main
MDeiml Dec 7, 2021
d2cf711
Fix #18
MDeiml Dec 15, 2021
110c1bb
Fix #17
MDeiml Dec 15, 2021
7451bb5
Add language node in info_string
MDeiml Dec 17, 2021
c5757bb
Document grammar.js
MDeiml Dec 29, 2021
cb10958
Create LICENSE
MDeiml Dec 29, 2021
c89e8ce
Begin documenting scanner
MDeiml Jan 7, 2022
77b90ae
Add block quote markers
MDeiml Jan 8, 2022
330ecab
Add delimiter nodes
MDeiml Jan 11, 2022
2fc0c57
More documentation for scanner.cc
MDeiml Jan 16, 2022
0024b79
Merge branch 'add-documentation' into main
MDeiml Jan 16, 2022
526bea8
Seperate failing test cases
MDeiml Jan 16, 2022
0cced45
Fix #12
MDeiml Jan 16, 2022
1e38fb2
Fix emphasis marker after newline
MDeiml Jan 16, 2022
59d8aba
Fix strong emphasis beginning with whitespace
MDeiml Jan 16, 2022
9e5fa28
Fix nested emphasis
MDeiml Jan 16, 2022
8bee14c
Update failing tests
MDeiml Jan 16, 2022
b49b2da
Fix #33
MDeiml Feb 26, 2022
0bed572
Expose highlights in rust binding
Mar 29, 2022
5a32b3b
Merge pull request #35 from Tiggilyboo/expose-highlights
MDeiml Mar 30, 2022
d24196f
Update README.md
MDeiml Mar 30, 2022
6d112e7
Change cargo name
MDeiml Apr 26, 2022
dc3cc5f
Initialize new strucutre and update RADME
MDeiml Jun 11, 2022
34d018e
Implement block grammar
MDeiml Jun 11, 2022
f8da36c
Implement inline grammar
MDeiml Jun 11, 2022
c6e26de
fixup! Implement block grammar
MDeiml Jun 11, 2022
941cddb
Add entity and numeric references to block grammar
MDeiml Jun 11, 2022
e54688a
Add queries
MDeiml Jun 11, 2022
5719a96
Fix emphasis at the end of inline spans
MDeiml Jun 12, 2022
51a527d
Mark soft line breaks as inline
MDeiml Jun 12, 2022
03ad62c
Implement rust bindings
MDeiml Jun 13, 2022
fa598cb
Remove unnecessary rule
MDeiml Jun 13, 2022
29195e1
Move html starting tokens to external parser
MDeiml Jun 18, 2022
973721f
Parse paragraphs without conflicts using lookahead
MDeiml Jun 18, 2022
3f72d80
Clean up
MDeiml Jun 18, 2022
b1f441e
Make it fast
MDeiml Jun 18, 2022
6fc8631
Benchmark
MDeiml Jun 18, 2022
af0156c
Optimize external scanner state
MDeiml Jun 20, 2022
889820a
Remove unnecessary conflicts in inline grammar
MDeiml Jun 20, 2022
450f059
Add initial section
MDeiml Jun 20, 2022
dbbeea6
Add edit to benchmark
MDeiml Jun 21, 2022
866a1d7
Simplify inlines
MDeiml Jun 21, 2022
5bfd7b6
Use single parser in rust bindings
MDeiml Jun 21, 2022
a3a4e0b
Fix syntax error in block grammar scanner
MDeiml Jun 22, 2022
9b4c773
Update README.md
MDeiml Jun 23, 2022
f7a3ac1
Fix inline injections for rust bindings
MDeiml Jun 23, 2022
296bcd9
Better sections
MDeiml Jun 23, 2022
535250d
Join common rules
MDeiml Jun 23, 2022
5b36748
Fix compiler warnings
MDeiml Jun 24, 2022
4bf17db
Remove log files
MDeiml Jun 24, 2022
acb0978
Update tree-sitter-cli to version 0.20.6
MDeiml Jun 24, 2022
134c7f8
Update lib.rs
dzhou121 Jun 27, 2022
12d3aa4
Merge pull request #46 from dzhou121/split_parser
MDeiml Jun 27, 2022
df01163
Update queries
MDeiml Jun 28, 2022
8282011
Include more queries in bindings
MDeiml Jun 28, 2022
382e37b
Implement task list items
MDeiml Jun 28, 2022
b48148a
Delete autogenerated Cargo.toml files
MDeiml Jun 28, 2022
40113da
Bump rust bindings version to 0.1.0
MDeiml Jun 28, 2022
ee4a658
Include query files in cargo package
MDeiml Jun 28, 2022
5261e18
Include benchmark in cargo package
MDeiml Jun 28, 2022
032568d
fix path to repository
ghishadow Jun 29, 2022
8bac940
Merge pull request #47 from ghishadow/patch-1
MDeiml Jun 29, 2022
69d9f46
Bump version to update repository URL
MDeiml Jun 29, 2022
5f2f63b
Implement metadata blocks
MDeiml Jul 2, 2022
9a4096f
Implement strikethrough
MDeiml Jul 2, 2022
142a5b4
Fix indentation in block_continuation
MDeiml Jul 4, 2022
11ef9ef
Fix parentheses in link_destination #51
MDeiml Jul 24, 2022
d057e6d
Implement pipe tables
MDeiml Jul 27, 2022
204611c
Add CONTRIBUTING.md
MDeiml Aug 1, 2022
d6bb2e9
Update issue templates
MDeiml Aug 1, 2022
3c7a438
Update issue templates
MDeiml Aug 1, 2022
88d5817
Set up build scripts
MDeiml Aug 2, 2022
b334b6d
Add CI
MDeiml Aug 2, 2022
79a7456
Update CONTRIBUTING.md
MDeiml Aug 2, 2022
f9c2aa9
In CI check generated code is up to date
MDeiml Aug 5, 2022
c265d30
Remove autogenerated files
MDeiml Aug 5, 2022
4365f3a
Allow files without trailing newline
MDeiml Aug 5, 2022
e375ba9
Reset indentation after soft line break
MDeiml Aug 5, 2022
9cacf84
Add 'vendor/tree-sitter-markdown/' from commit 'e375ba95ff9a12418f9b9…
gurjeet Sep 20, 2022
83693a5
Support Markdown diff highilighting
gurjeet Sep 20, 2022
9cc4994
wip
gurjeet Sep 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,11 @@ fn main() {
src_dir: "vendor/tree-sitter-zig-src",
extra_files: vec![],
},
TreeSitterParser {
name: "tree-sitter-markdown",
src_dir: "vendor/tree-sitter-markdown-src",
extra_files: vec!["scanner.cc"],
},
];

// Only rerun if relevant files in the vendor/ directory change.
Expand Down
15 changes: 9 additions & 6 deletions sample_files/compare.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
sample_files/Session_before.kt sample_files/Session_after.kt
46994b58bb24200f82866951013f03ce -

sample_files/b2_math_before.h sample_files/b2_math_after.h
637e91c1528894ec0529bc845ef79c88 -

Expand Down Expand Up @@ -55,12 +58,12 @@ sample_files/haskell_before.hs sample_files/haskell_after.hs
sample_files/hcl_before.hcl sample_files/hcl_after.hcl
48b5599f3c6131a7eccaba73254fd599 -

sample_files/helpful_before.el sample_files/helpful_after.el
bce74573e003cc6b729a63a4bc34c4af -

sample_files/helpful-unit-test-before.el sample_files/helpful-unit-test-after.el
79597af48ff80bcf9f5d02d20c51606d -

sample_files/helpful_before.el sample_files/helpful_after.el
bce74573e003cc6b729a63a4bc34c4af -

sample_files/html_before.html sample_files/html_after.html
5bf6a3d864706e18932c8cd027cb4c0b -

Expand Down Expand Up @@ -103,6 +106,9 @@ sample_files/load_before.js sample_files/load_after.js
sample_files/lua_before.lua sample_files/lua_after.lua
c3d81271c060bd97dd246c1c5ea6a138 -

sample_files/markdown_before.md sample_files/markdown_after.md
aca6d38a647626d96bcb0a0cb791eaaa -

sample_files/metadata_before.clj sample_files/metadata_after.clj
b71577801352071fd1c6a9079f2d9dbc -

Expand Down Expand Up @@ -154,9 +160,6 @@ d88046b43f826a34bbd4a7b9d6bb704d -
sample_files/scala_before.scala sample_files/scala_after.scala
bb18213033492a633e7f978ab9711ae1 -

sample_files/Session_before.kt sample_files/Session_after.kt
46994b58bb24200f82866951013f03ce -

sample_files/simple_before.js sample_files/simple_after.js
b1fe2c184a9a358e314e21aabb0f3cb7 -

Expand Down
1 change: 1 addition & 0 deletions sample_files/markdown_after.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Title of the Document Goes Here
1 change: 1 addition & 0 deletions sample_files/markdown_before.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Title of the Doc Goes Here
3 changes: 3 additions & 0 deletions src/parse/guess_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum Language {
Kotlin,
Lua,
Make,
Markdown,
Nix,
OCaml,
OCamlInterface,
Expand Down Expand Up @@ -99,6 +100,7 @@ pub fn language_name(language: Language) -> &'static str {
Kotlin => "Kotlin",
Lua => "Lua",
Make => "Make",
Markdown => "Markdown",
Nix => "Nix",
OCaml => "OCaml",
OCamlInterface => "OCaml Interface",
Expand Down Expand Up @@ -182,6 +184,7 @@ pub const LANG_EXTENSIONS: &'static [(Language, &[&str])] = &[
(Kotlin, &["kt", "ktm", "kts"]),
(Lua, &["lua"]),
(Make, &["mak", "d", "make", "makefile", "mk", "mkfile"]),
(Markdown, &["md", "markdown"]),
(Nix, &["nix"]),
(OCaml, &["ml"]),
(OCamlInterface, &["mli"]),
Expand Down
14 changes: 14 additions & 0 deletions src/parse/tree_sitter_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ extern "C" {
fn tree_sitter_kotlin() -> ts::Language;
fn tree_sitter_lua() -> ts::Language;
fn tree_sitter_make() -> ts::Language;
fn tree_sitter_markdown_inline() -> ts::Language;
fn tree_sitter_nix() -> ts::Language;
fn tree_sitter_ocaml() -> ts::Language;
fn tree_sitter_ocaml_interface() -> ts::Language;
Expand Down Expand Up @@ -535,6 +536,19 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig {
.unwrap(),
}
}
Markdown => {
let language = unsafe { tree_sitter_markdown_inline() };
TreeSitterConfig {
language,
atom_nodes: vec![].into_iter().collect(),
delimiter_tokens: vec![],
highlight_query: ts::Query::new(
language,
include_str!("../../vendor/highlights/markdown.scm"),
)
.unwrap(),
}
}
Nix => {
let language = unsafe { tree_sitter_nix() };
TreeSitterConfig {
Expand Down
1 change: 1 addition & 0 deletions vendor/highlights/markdown.scm
1 change: 1 addition & 0 deletions vendor/tree-sitter-markdown-src
20 changes: 20 additions & 0 deletions vendor/tree-sitter-markdown/.github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**

**Code example**
```markdown
Your example here
```

**Expected behavior**
<!-- consider linking to a relevant section in a spec like https://github.github.com/gfm/ -->

**Actual behavior**
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

<!-- consider linking a relevant section from a spec -->
<!-- extensions from any spec (rmarkdown, pandoc, ...) are welcome -->
28 changes: 28 additions & 0 deletions vendor/tree-sitter-markdown/.github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ "split_parser" ]
pull_request:
branches: [ "split_parser" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js 14
uses: actions/setup-node@v3
with:
node-version: 14
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- name: Check grammar is compiled correctly
run: git diff --exit-code
- run: npm test
3 changes: 3 additions & 0 deletions vendor/tree-sitter-markdown/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
target
70 changes: 70 additions & 0 deletions vendor/tree-sitter-markdown/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Contributing

All contributions are welcome. Specifically, if you found a bug or have a
suggestion for a new feature or markdown extension, you can always open an
[issue] or [pull request].

## Issues

If you open an issue please give a short description of your bug or feature
along with a code example. If there is a relevant spec like the [CommonMark
Spec][commonmark] or the [GitHub Flavored Markdown Spec][gfm] please link it in
the issue.

Any feature suggestions are welcome. The grammar should by default only support
very common syntax, but any extension can be implemented behind a compile time
flag. (See below)

Some bug reports belong in other repositories if they only concern the
implementation of the grammar in a specific context like `nvim-treesitter`, but
you can always open an issue here and I will point you in the right direction.

## Code Overview

Please refer to the [tree-sitter spec] for more details on how to write a tree-
sitter grammar.

This parse is split into two grammars. One for block structure, which can be
found in the `tree-sitter-markdown` folder, and one for inline structure, which
can be found in the `tree-sitter-markdown-inline` folder. Components that are
parts of either grammar can be found in the `common` folder.

For either of the grammar the most important files are the `grammar.js` which
defines most nodes and the `src/scanner.cc` which defines nodes that cannot
be parsed with normal tree-sitter rules. All other files in the `src` subfolder
are auto-generated by running `tree-sitter generate --no-bindings`. (You need to
install the [tree-sitter cli tool][tree-sitter-cli] first.)

Some syntactical components can be enabled or disabled by environment variables
at compile time. The logic for this can be found in the `common/grammar.js`
file.

Tests are located in the `corpus` subfolder:
* `spec.txt` is taken from the examples in the [GFM spec][gfm].
* `failing.txt` are those examples from the spec that do not pass yet.
* `issues.txt` are test cases covering solved issues.
* `extension_<>.txt` are covering specific extensions. Some of these are also
taken from the GFM spec.

## Pull Requests

I will happily accept any pull requests.

Before submitting any code please check the following:

* You ran `tree-sitter generate --no-bindings` in the `tree-sitter-markdown` or
`tree-sitter-markdown-inline` directories respecively after modifying any
`grammar.js` file.
* When running `tree-sitter test` only the cases defined in `failing.txt` or
`extension_<>.txt` for not activated extensions fail for **both** gramars.
* If you implemented new behavior please add tests. (In most cases these belong
in a `extension_<>.txt`.)
* You deleted any auto-generated bindings and files for debugging purposes
like `log.html`

[issue]: https://github.com/MDeiml/tree-sitter-markdown/issues/new
[pull request]: https://github.com/MDeiml/tree-sitter-markdown/compare
[gfm]: https://github.github.com/gfm/
[commonmark]: https://spec.commonmark.org/
[tree-sitter spec]: https://tree-sitter.github.io/tree-sitter/
[tree-sitter-cli]: https://github.com/tree-sitter/tree-sitter/blob/master/cli/README.md
35 changes: 35 additions & 0 deletions vendor/tree-sitter-markdown/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "tree-sitter-md"
description = "markdown grammar for the tree-sitter parsing library"
version = "0.1.1"
keywords = ["incremental", "parsing", "markdown"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/MDeiml/tree-sitter-markdown"
edition = "2018"
license = "MIT"

build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"tree-sitter-markdown/src/*",
"tree-sitter-markdown-inline/src/*",
"tree-sitter-markdown/queries/*",
"tree-sitter-markdown-inline/queries/*",
"benchmark/main.rs",
]

[lib]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = "~0.20"

[build-dependencies]
cc = "1.0"

[[bin]]
name = "benchmark"
path = "benchmark/main.rs"

[profile.release]
debug = true
21 changes: 21 additions & 0 deletions vendor/tree-sitter-markdown/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Matthias Deiml

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
16 changes: 16 additions & 0 deletions vendor/tree-sitter-markdown/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# tree-sitter-markdown
A markdown parser for tree-sitter

For now this implements the [CommonMark Spec](https://spec.commonmark.org/). Maybe it will be extended to support [Github flavored markdown](https://github.github.com/gfm/)

## Structure

The parser is spit into two grammars. One for the [block structure](https://spec.commonmark.org/0.30/#blocks-and-inlines) which can be found in `/tree-sitter-markdown` and one for the [inline structure](https://spec.commonmark.org/0.30/#inlines) which is in `/tree-sitter-markdown-inline`.
Because of this the entire document has to be scanned twice in order to be fully parsed.
This is motivated by the [parsing strategy section](https://spec.commonmark.org/0.30/#appendix-a-parsing-strategy) of the CommonMark Spec which suggests doing exactly this: Parsing the document twice, first determining the block structure and then parsing any inline content.

It also helps managing complexity, which was a problem with earlier versions of this parser, by allowing block and inline structure to be considered seperately. This was not the case as tree-sitters dynamic precedence can create hard to predict effects.

## Usage

To use the two grammars, first parse the document with the block grammar. Then perform a second parse with the inline grammar using `ts_parser_set_included_ranges` to specify which parts are inline content. These parts are marked as `inline` nodes. Children of those inline nodes should be excluded from these ranges. For an example implementation see `lib.rs` in the `bindings` folder.
21 changes: 21 additions & 0 deletions vendor/tree-sitter-markdown/benchmark/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use tree_sitter_md::*;

fn main() {
let mut parser = MarkdownParser::default();
let filename = std::env::args().nth(1).unwrap();
let source = std::fs::read(filename).unwrap();
let mut tree = parser.parse(&source, None).unwrap();
tree.edit(&tree_sitter::InputEdit {
start_byte: 0,
old_end_byte: 1,
new_end_byte: 0,
start_position: tree_sitter::Point::new(0, 0),
old_end_position: tree_sitter::Point::new(0, 1),
new_end_position: tree_sitter::Point::new(0, 0),
});
reparse(&mut parser, &source[1..], tree);
}

fn reparse(parser: &mut MarkdownParser, source: &[u8], old_tree: MarkdownTree) {
parser.parse(source, Some(&old_tree));
}
23 changes: 23 additions & 0 deletions vendor/tree-sitter-markdown/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"targets": [
{
"target_name": "tree_sitter_markdown_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"tree-sitter-markdown/src",
"tree-sitter-markdown-inline/src",
],
"sources": [
"tree-sitter-markdown/src/parser.c",
"tree-sitter-markdown/src/scanner.cc",
"tree-sitter-markdown-inline/src/parser.c",
"tree-sitter-markdown-inline/src/scanner.cc",
"bindings/node/binding.cc"
],
"cflags_c": [
"-std=c99"
]
}
]
}

Loading