@farvardin/lezer-parser-markdown 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +279 -0
- package/LICENSE +21 -0
- package/README.md +719 -0
- package/bin/build-readme.cjs +39 -0
- package/build.js +16 -0
- package/dist/index.cjs +2357 -0
- package/dist/index.d.cts +600 -0
- package/dist/index.d.ts +600 -0
- package/dist/index.js +2340 -0
- package/package.json +37 -0
- package/publish.sh +1 -0
- package/src/README.md +83 -0
- package/src/extension.ts +301 -0
- package/src/index.ts +5 -0
- package/src/markdown.ts +1966 -0
- package/src/nest.ts +46 -0
- package/test/compare-tree.ts +14 -0
- package/test/spec.ts +79 -0
- package/test/test-extension.ts +277 -0
- package/test/test-incremental.ts +265 -0
- package/test/test-markdown.ts +3574 -0
- package/test/test-nesting.ts +86 -0
- package/test/tsconfig.json +12 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import {Tree, NodeProp} from "@lezer/common"
|
|
2
|
+
import {parser as html} from "@lezer/html"
|
|
3
|
+
import ist from "ist"
|
|
4
|
+
import {parser, parseCode} from "../dist/index.js"
|
|
5
|
+
|
|
6
|
+
let full = parser.configure(parseCode({
|
|
7
|
+
codeParser(str) { return !str || str == "html" ? html : null },
|
|
8
|
+
htmlParser: html.configure({dialect: "noMatch"})
|
|
9
|
+
}))
|
|
10
|
+
|
|
11
|
+
function findMounts(tree: Tree) {
|
|
12
|
+
let result = []
|
|
13
|
+
for (let cur = tree.cursor(); cur.next();) {
|
|
14
|
+
let mount = cur.tree?.prop(NodeProp.mounted)
|
|
15
|
+
if (mount) result.push({at: cur.from, mount})
|
|
16
|
+
}
|
|
17
|
+
return result
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function test(doc: string, ...nest: [string, ...number[]][]) {
|
|
21
|
+
return () => {
|
|
22
|
+
let tree = full.parse(doc), mounts = findMounts(tree)
|
|
23
|
+
ist(mounts.length, nest.length)
|
|
24
|
+
nest.forEach(([repr, ...ranges], i) => {
|
|
25
|
+
let {mount, at} = mounts[i]
|
|
26
|
+
ist(mount.tree.toString(), "Document(" + repr + ")")
|
|
27
|
+
ist(mount.overlay!.map(r => (r.from + at) + "," + (r.to + at)).join(), ranges.join())
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe("Code parsing", () => {
|
|
33
|
+
it("parses HTML blocks", test(`
|
|
34
|
+
Paragraph
|
|
35
|
+
|
|
36
|
+
<div id=x>
|
|
37
|
+
Hello & goodbye
|
|
38
|
+
</div>`, ["Element(OpenTag(StartTag,TagName,Attribute(AttributeName,Is,UnquotedAttributeValue),EndTag),Text,EntityReference,Text,CloseTag(StartCloseTag,TagName,EndTag))", 12, 51]))
|
|
39
|
+
|
|
40
|
+
it("parses inline HTML", test(
|
|
41
|
+
`Paragraph with <em>inline tags</em> in it.`,
|
|
42
|
+
["Element(OpenTag(StartTag,TagName,EndTag))", 15, 19],
|
|
43
|
+
["CloseTag(StartCloseTag,TagName,EndTag)", 30, 35]))
|
|
44
|
+
|
|
45
|
+
it("parses indented code", test(`
|
|
46
|
+
Paragraph.
|
|
47
|
+
|
|
48
|
+
<!doctype html>
|
|
49
|
+
Hi
|
|
50
|
+
`, ["DoctypeDecl,Text", 17, 33, 37, 39]))
|
|
51
|
+
|
|
52
|
+
it("parses fenced code", test(`
|
|
53
|
+
Okay
|
|
54
|
+
|
|
55
|
+
~~~
|
|
56
|
+
<p>
|
|
57
|
+
Hey
|
|
58
|
+
</p>
|
|
59
|
+
~~~`, ["Element(OpenTag(StartTag,TagName,EndTag),Text,CloseTag(StartCloseTag,TagName,EndTag))", 11, 25]))
|
|
60
|
+
|
|
61
|
+
it("allows gaps in fenced code", test(`
|
|
62
|
+
- >~~~
|
|
63
|
+
><!doctype html>
|
|
64
|
+
>yay
|
|
65
|
+
> ~~~`, ["DoctypeDecl,Text", 11, 27, 30, 33]))
|
|
66
|
+
|
|
67
|
+
it("passes fenced code info", test(`
|
|
68
|
+
~~~html
|
|
69
|
+
»
|
|
70
|
+
~~~
|
|
71
|
+
|
|
72
|
+
~~~python
|
|
73
|
+
False
|
|
74
|
+
~~~`, ["EntityReference", 9, 16]))
|
|
75
|
+
|
|
76
|
+
it("can parse disjoint ranges", () => {
|
|
77
|
+
let tree = parser.parse(`==foo\n==\n==ba==r\n==`, undefined,
|
|
78
|
+
[{from: 2, to: 6}, {from: 8, to: 9}, {from: 11, to: 13}, {from: 15, to: 17}])
|
|
79
|
+
ist(tree.toString(), "Document(Paragraph,Paragraph)")
|
|
80
|
+
ist(tree.length, 15)
|
|
81
|
+
ist(tree.topNode.firstChild!.from, 0)
|
|
82
|
+
ist(tree.topNode.firstChild!.to, 3)
|
|
83
|
+
ist(tree.topNode.lastChild!.from, 9)
|
|
84
|
+
ist(tree.topNode.lastChild!.to, 14)
|
|
85
|
+
})
|
|
86
|
+
})
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"lib": ["es2017"],
|
|
4
|
+
"noImplicitReturns": true,
|
|
5
|
+
"noUnusedLocals": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"target": "es6",
|
|
8
|
+
"module": "es2015",
|
|
9
|
+
"newLine": "lf",
|
|
10
|
+
"stripInternal": true,
|
|
11
|
+
"moduleResolution": "node"
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/*.ts"]
|
|
14
|
+
}
|