react-native-codepad-lang-markdown 0.0.0-stage → 0.1.1

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.
Files changed (34) hide show
  1. package/CodepadLangMarkdown.podspec +28 -0
  2. package/README.md +50 -2
  3. package/android/CMakeLists.txt +19 -0
  4. package/android/build.gradle +61 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/assets/codepad-languages/markdown +1 -0
  8. package/android/src/main/assets/codepad-languages/markdown_inline +1 -0
  9. package/android/src/main/cpp/lang.c +17 -0
  10. package/android/src/main/java/me/sectiontn/codepad/lang/markdown/CodepadLangMarkdownPackage.kt +13 -0
  11. package/android/src/main/java/me/sectiontn/codepad/lang/markdown/MarkdownLanguage.kt +169 -0
  12. package/android/src/main/java/me/sectiontn/codepad/lang/markdown_inline/MarkdownInlineLanguage.kt +156 -0
  13. package/grammar/LICENSE +21 -0
  14. package/grammar/tree-sitter-markdown/src/parser.c +59787 -0
  15. package/grammar/tree-sitter-markdown/src/scanner.c +1602 -0
  16. package/grammar/tree-sitter-markdown/src/tree_sitter/alloc.h +54 -0
  17. package/grammar/tree-sitter-markdown/src/tree_sitter/array.h +330 -0
  18. package/grammar/tree-sitter-markdown/src/tree_sitter/parser.h +286 -0
  19. package/grammar/tree-sitter-markdown-inline/src/parser.c +75709 -0
  20. package/grammar/tree-sitter-markdown-inline/src/scanner.c +397 -0
  21. package/grammar/tree-sitter-markdown-inline/src/tree_sitter/alloc.h +54 -0
  22. package/grammar/tree-sitter-markdown-inline/src/tree_sitter/array.h +330 -0
  23. package/grammar/tree-sitter-markdown-inline/src/tree_sitter/parser.h +286 -0
  24. package/ios/CPLangMarkdown.h +11 -0
  25. package/ios/CPLangMarkdown.swift +162 -0
  26. package/ios/CPLangMarkdownInline.h +11 -0
  27. package/ios/CPLangMarkdownInline.swift +149 -0
  28. package/package.json +40 -4
  29. package/queries/markdown/highlights.scm +123 -0
  30. package/queries/markdown/indents.scm +1 -0
  31. package/queries/markdown/injections.scm +25 -0
  32. package/queries/markdown_inline/highlights.scm +128 -0
  33. package/queries/markdown_inline/injections.scm +7 -0
  34. package/src/index.ts +2 -0
@@ -0,0 +1,162 @@
1
+ import Foundation
2
+ import Codepad
3
+
4
+ @objc(CPLangMarkdown)
5
+ public final class CPLangMarkdown: NSObject, CPLanguageProvider {
6
+ public let id: String = "markdown"
7
+ public var languagePointer: UnsafeRawPointer { UnsafeRawPointer(tree_sitter_markdown()) }
8
+ public let highlights: String = #"""
9
+ ;From MDeiml/tree-sitter-markdown & Helix
10
+ (setext_heading
11
+ (paragraph) @markup.heading.1
12
+ (setext_h1_underline) @markup.heading.1)
13
+
14
+ (setext_heading
15
+ (paragraph) @markup.heading.2
16
+ (setext_h2_underline) @markup.heading.2)
17
+
18
+ (atx_heading
19
+ (atx_h1_marker)) @markup.heading.1
20
+
21
+ (atx_heading
22
+ (atx_h2_marker)) @markup.heading.2
23
+
24
+ (atx_heading
25
+ (atx_h3_marker)) @markup.heading.3
26
+
27
+ (atx_heading
28
+ (atx_h4_marker)) @markup.heading.4
29
+
30
+ (atx_heading
31
+ (atx_h5_marker)) @markup.heading.5
32
+
33
+ (atx_heading
34
+ (atx_h6_marker)) @markup.heading.6
35
+
36
+ (info_string) @label
37
+
38
+ (pipe_table_header
39
+ (pipe_table_cell) @markup.heading)
40
+
41
+ (pipe_table_header
42
+ "|" @punctuation.special)
43
+
44
+ (pipe_table_row
45
+ "|" @punctuation.special)
46
+
47
+ (pipe_table_delimiter_row
48
+ "|" @punctuation.special)
49
+
50
+ (pipe_table_delimiter_cell) @punctuation.special
51
+
52
+ ; Code blocks (conceal backticks and language annotation)
53
+ (indented_code_block) @markup.raw.block
54
+
55
+ ((fenced_code_block) @markup.raw.block
56
+ (#set! priority 90))
57
+
58
+ (fenced_code_block
59
+ (fenced_code_block_delimiter) @markup.raw.block
60
+ (#set! conceal "")
61
+ (#set! conceal_lines ""))
62
+
63
+ (fenced_code_block
64
+ (info_string
65
+ (language) @label
66
+ (#set! conceal "")
67
+ (#set! conceal_lines "")))
68
+
69
+ (link_destination) @markup.link.url
70
+
71
+ [
72
+ (link_title)
73
+ (link_label)
74
+ ] @markup.link.label
75
+
76
+ ((link_label)
77
+ .
78
+ ":" @punctuation.delimiter)
79
+
80
+ [
81
+ (list_marker_plus)
82
+ (list_marker_minus)
83
+ (list_marker_star)
84
+ (list_marker_dot)
85
+ (list_marker_parenthesis)
86
+ ] @markup.list
87
+
88
+ ; NOTE: The following has been commented out due to issues with spaces in the
89
+ ; list marker nodes generated by the parser. If those spaces ever get captured
90
+ ; by a different node (e.g. block_continuation) we can safely re-add these
91
+ ; conceals.
92
+ ; ;; Conceal bullet points
93
+ ; ([(list_marker_plus) (list_marker_star)]
94
+ ; @punctuation.special
95
+ ; (#offset! @punctuation.special 0 0 0 -1)
96
+ ; (#set! conceal "•"))
97
+ ; ([(list_marker_plus) (list_marker_star)]
98
+ ; @punctuation.special
99
+ ; (#any-of? @punctuation.special "+" "*")
100
+ ; (#set! conceal "•"))
101
+ ; ((list_marker_minus)
102
+ ; @punctuation.special
103
+ ; (#offset! @punctuation.special 0 0 0 -1)
104
+ ; (#set! conceal "—"))
105
+ ; ((list_marker_minus)
106
+ ; @punctuation.special
107
+ ; (#eq? @punctuation.special "-")
108
+ ; (#set! conceal "—"))
109
+ (thematic_break) @punctuation.special
110
+
111
+ (task_list_marker_unchecked) @markup.list.unchecked
112
+
113
+ (task_list_marker_checked) @markup.list.checked
114
+
115
+ ((block_quote) @markup.quote
116
+ (#set! priority 90))
117
+
118
+ ([
119
+ (plus_metadata)
120
+ (minus_metadata)
121
+ ] @keyword.directive
122
+ (#set! priority 90))
123
+
124
+ [
125
+ (block_continuation)
126
+ (block_quote_marker)
127
+ ] @punctuation.special
128
+
129
+ (backslash_escape) @string.escape
130
+
131
+ (inline) @spell
132
+
133
+ """#
134
+ public let injections: String = #"""
135
+ (fenced_code_block
136
+ (info_string
137
+ (language) @injection.language)
138
+ (code_fence_content) @injection.content)
139
+
140
+ ((html_block) @injection.content
141
+ (#set! injection.language "html")
142
+ (#set! injection.combined)
143
+ (#set! injection.include-children))
144
+
145
+ ((minus_metadata) @injection.content
146
+ (#set! injection.language "yaml")
147
+ (#offset! @injection.content 1 0 -1 0)
148
+ (#set! injection.include-children))
149
+
150
+ ((plus_metadata) @injection.content
151
+ (#set! injection.language "toml")
152
+ (#offset! @injection.content 1 0 -1 0)
153
+ (#set! injection.include-children))
154
+
155
+ ([
156
+ (inline)
157
+ (pipe_table_cell)
158
+ ] @injection.content
159
+ (#set! injection.language "markdown_inline"))
160
+
161
+ """#
162
+ }
@@ -0,0 +1,11 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ #ifdef __cplusplus
4
+ extern "C" {
5
+ #endif
6
+
7
+ const void *tree_sitter_markdown_inline(void);
8
+
9
+ #ifdef __cplusplus
10
+ }
11
+ #endif
@@ -0,0 +1,149 @@
1
+ import Foundation
2
+ import Codepad
3
+
4
+ @objc(CPLangMarkdownInline)
5
+ public final class CPLangMarkdownInline: NSObject, CPLanguageProvider {
6
+ public let id: String = "markdown_inline"
7
+ public var languagePointer: UnsafeRawPointer { UnsafeRawPointer(tree_sitter_markdown_inline()) }
8
+ public let highlights: String = #"""
9
+ ; From MDeiml/tree-sitter-markdown
10
+ (code_span) @markup.raw @nospell
11
+
12
+ (emphasis) @markup.italic
13
+
14
+ (strong_emphasis) @markup.strong
15
+
16
+ (strikethrough) @markup.strikethrough
17
+
18
+ (shortcut_link
19
+ (link_text) @nospell)
20
+
21
+ ; Conceal backslash in backslash escapes
22
+ ((backslash_escape) @conceal
23
+ (#offset! @conceal 0 0 0 -1)
24
+ (#set! conceal ""))
25
+
26
+ ; Conceal backslash in hard line breaks
27
+ ((hard_line_break
28
+ "\\" @conceal)
29
+ (#set! conceal ""))
30
+
31
+ ; Conceal codeblock and text style markers
32
+ ([
33
+ (code_span_delimiter)
34
+ (emphasis_delimiter)
35
+ ] @conceal
36
+ (#set! conceal ""))
37
+
38
+ ; Conceal inline links
39
+ (inline_link
40
+ [
41
+ "["
42
+ "]"
43
+ "("
44
+ (link_destination)
45
+ ")"
46
+ ] @markup.link
47
+ (#set! conceal ""))
48
+
49
+ [
50
+ (link_label)
51
+ (link_text)
52
+ (link_title)
53
+ (image_description)
54
+ ] @markup.link.label
55
+
56
+ ((inline_link
57
+ (link_destination) @_url) @_label
58
+ (#set! @_label url @_url))
59
+
60
+ ((image
61
+ (link_destination) @_url) @_label
62
+ (#set! @_label url @_url))
63
+
64
+ ; Conceal image links
65
+ (image
66
+ [
67
+ "!"
68
+ "["
69
+ "]"
70
+ "("
71
+ (link_destination)
72
+ ")"
73
+ ] @markup.link
74
+ (#set! conceal ""))
75
+
76
+ ; Conceal full reference links
77
+ (full_reference_link
78
+ [
79
+ "["
80
+ "]"
81
+ (link_label)
82
+ ] @markup.link
83
+ (#set! conceal ""))
84
+
85
+ ; Conceal collapsed reference links
86
+ (collapsed_reference_link
87
+ [
88
+ "["
89
+ "]"
90
+ ] @markup.link
91
+ (#set! conceal ""))
92
+
93
+ ; Conceal shortcut links
94
+ (shortcut_link
95
+ [
96
+ "["
97
+ "]"
98
+ ] @markup.link
99
+ (#set! conceal ""))
100
+
101
+ [
102
+ (link_destination)
103
+ (uri_autolink)
104
+ (email_autolink)
105
+ ] @markup.link.url @nospell
106
+
107
+ ((uri_autolink) @_url
108
+ (#offset! @_url 0 1 0 -1)
109
+ (#set! @_url url @_url))
110
+
111
+ (entity_reference) @nospell
112
+
113
+ ; Replace common HTML entities.
114
+ ((entity_reference) @character.special
115
+ (#eq? @character.special "&nbsp;")
116
+ (#set! conceal " "))
117
+
118
+ ((entity_reference) @character.special
119
+ (#eq? @character.special "&lt;")
120
+ (#set! conceal "<"))
121
+
122
+ ((entity_reference) @character.special
123
+ (#eq? @character.special "&gt;")
124
+ (#set! conceal ">"))
125
+
126
+ ((entity_reference) @character.special
127
+ (#eq? @character.special "&amp;")
128
+ (#set! conceal "&"))
129
+
130
+ ((entity_reference) @character.special
131
+ (#eq? @character.special "&quot;")
132
+ (#set! conceal "\""))
133
+
134
+ ((entity_reference) @character.special
135
+ (#any-of? @character.special "&ensp;" "&emsp;")
136
+ (#set! conceal " "))
137
+
138
+ """#
139
+ public let injections: String = #"""
140
+ ((html_tag) @injection.content
141
+ (#set! injection.language "html")
142
+ (#set! injection.combined))
143
+
144
+ ((latex_block) @injection.content
145
+ (#set! injection.language "latex")
146
+ (#set! injection.include-children))
147
+
148
+ """#
149
+ }
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "react-native-codepad-lang-markdown",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "tree-sitter Markdown grammar and highlight queries for react-native-codepad",
5
+ "main": "./src/index.ts",
6
+ "types": "./src/index.ts",
7
+ "files": [
8
+ "src",
9
+ "android",
10
+ "ios",
11
+ "grammar",
12
+ "queries",
13
+ "*.podspec",
14
+ "!android/build",
15
+ "!android/.cxx"
16
+ ],
17
+ "keywords": [
18
+ "react-native",
19
+ "codepad",
20
+ "tree-sitter",
21
+ "markdown"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/SectionTN/react-native-codepad.git",
26
+ "directory": "languages/markdown"
27
+ },
28
+ "author": "Rayen Sbai <rayensbai2@gmail.com> (https://github.com/SectionTN)",
29
+ "license": "MIT",
30
+ "homepage": "https://github.com/SectionTN/react-native-codepad#readme",
31
+ "peerDependencies": {
32
+ "react-native-codepad": "0.1.1"
33
+ },
34
+ "publishConfig": {
35
+ "registry": "https://registry.npmjs.org/"
36
+ },
37
+ "codepad": {
38
+ "generated": true,
39
+ "grammar": "tree-sitter-grammars/tree-sitter-markdown@a0a00f817d02412bd92c54d316f164d827b57b5c",
40
+ "queries": "nvim-treesitter/nvim-treesitter@e289100ff98969e118c702199d88b764ce9e7fdf"
41
+ }
42
+ }
@@ -0,0 +1,123 @@
1
+ ;From MDeiml/tree-sitter-markdown & Helix
2
+ (setext_heading
3
+ (paragraph) @markup.heading.1
4
+ (setext_h1_underline) @markup.heading.1)
5
+
6
+ (setext_heading
7
+ (paragraph) @markup.heading.2
8
+ (setext_h2_underline) @markup.heading.2)
9
+
10
+ (atx_heading
11
+ (atx_h1_marker)) @markup.heading.1
12
+
13
+ (atx_heading
14
+ (atx_h2_marker)) @markup.heading.2
15
+
16
+ (atx_heading
17
+ (atx_h3_marker)) @markup.heading.3
18
+
19
+ (atx_heading
20
+ (atx_h4_marker)) @markup.heading.4
21
+
22
+ (atx_heading
23
+ (atx_h5_marker)) @markup.heading.5
24
+
25
+ (atx_heading
26
+ (atx_h6_marker)) @markup.heading.6
27
+
28
+ (info_string) @label
29
+
30
+ (pipe_table_header
31
+ (pipe_table_cell) @markup.heading)
32
+
33
+ (pipe_table_header
34
+ "|" @punctuation.special)
35
+
36
+ (pipe_table_row
37
+ "|" @punctuation.special)
38
+
39
+ (pipe_table_delimiter_row
40
+ "|" @punctuation.special)
41
+
42
+ (pipe_table_delimiter_cell) @punctuation.special
43
+
44
+ ; Code blocks (conceal backticks and language annotation)
45
+ (indented_code_block) @markup.raw.block
46
+
47
+ ((fenced_code_block) @markup.raw.block
48
+ (#set! priority 90))
49
+
50
+ (fenced_code_block
51
+ (fenced_code_block_delimiter) @markup.raw.block
52
+ (#set! conceal "")
53
+ (#set! conceal_lines ""))
54
+
55
+ (fenced_code_block
56
+ (info_string
57
+ (language) @label
58
+ (#set! conceal "")
59
+ (#set! conceal_lines "")))
60
+
61
+ (link_destination) @markup.link.url
62
+
63
+ [
64
+ (link_title)
65
+ (link_label)
66
+ ] @markup.link.label
67
+
68
+ ((link_label)
69
+ .
70
+ ":" @punctuation.delimiter)
71
+
72
+ [
73
+ (list_marker_plus)
74
+ (list_marker_minus)
75
+ (list_marker_star)
76
+ (list_marker_dot)
77
+ (list_marker_parenthesis)
78
+ ] @markup.list
79
+
80
+ ; NOTE: The following has been commented out due to issues with spaces in the
81
+ ; list marker nodes generated by the parser. If those spaces ever get captured
82
+ ; by a different node (e.g. block_continuation) we can safely re-add these
83
+ ; conceals.
84
+ ; ;; Conceal bullet points
85
+ ; ([(list_marker_plus) (list_marker_star)]
86
+ ; @punctuation.special
87
+ ; (#offset! @punctuation.special 0 0 0 -1)
88
+ ; (#set! conceal "•"))
89
+ ; ([(list_marker_plus) (list_marker_star)]
90
+ ; @punctuation.special
91
+ ; (#any-of? @punctuation.special "+" "*")
92
+ ; (#set! conceal "•"))
93
+ ; ((list_marker_minus)
94
+ ; @punctuation.special
95
+ ; (#offset! @punctuation.special 0 0 0 -1)
96
+ ; (#set! conceal "—"))
97
+ ; ((list_marker_minus)
98
+ ; @punctuation.special
99
+ ; (#eq? @punctuation.special "-")
100
+ ; (#set! conceal "—"))
101
+ (thematic_break) @punctuation.special
102
+
103
+ (task_list_marker_unchecked) @markup.list.unchecked
104
+
105
+ (task_list_marker_checked) @markup.list.checked
106
+
107
+ ((block_quote) @markup.quote
108
+ (#set! priority 90))
109
+
110
+ ([
111
+ (plus_metadata)
112
+ (minus_metadata)
113
+ ] @keyword.directive
114
+ (#set! priority 90))
115
+
116
+ [
117
+ (block_continuation)
118
+ (block_quote_marker)
119
+ ] @punctuation.special
120
+
121
+ (backslash_escape) @string.escape
122
+
123
+ (inline) @spell
@@ -0,0 +1 @@
1
+ (list_item) @indent.auto
@@ -0,0 +1,25 @@
1
+ (fenced_code_block
2
+ (info_string
3
+ (language) @injection.language)
4
+ (code_fence_content) @injection.content)
5
+
6
+ ((html_block) @injection.content
7
+ (#set! injection.language "html")
8
+ (#set! injection.combined)
9
+ (#set! injection.include-children))
10
+
11
+ ((minus_metadata) @injection.content
12
+ (#set! injection.language "yaml")
13
+ (#offset! @injection.content 1 0 -1 0)
14
+ (#set! injection.include-children))
15
+
16
+ ((plus_metadata) @injection.content
17
+ (#set! injection.language "toml")
18
+ (#offset! @injection.content 1 0 -1 0)
19
+ (#set! injection.include-children))
20
+
21
+ ([
22
+ (inline)
23
+ (pipe_table_cell)
24
+ ] @injection.content
25
+ (#set! injection.language "markdown_inline"))
@@ -0,0 +1,128 @@
1
+ ; From MDeiml/tree-sitter-markdown
2
+ (code_span) @markup.raw @nospell
3
+
4
+ (emphasis) @markup.italic
5
+
6
+ (strong_emphasis) @markup.strong
7
+
8
+ (strikethrough) @markup.strikethrough
9
+
10
+ (shortcut_link
11
+ (link_text) @nospell)
12
+
13
+ ; Conceal backslash in backslash escapes
14
+ ((backslash_escape) @conceal
15
+ (#offset! @conceal 0 0 0 -1)
16
+ (#set! conceal ""))
17
+
18
+ ; Conceal backslash in hard line breaks
19
+ ((hard_line_break
20
+ "\\" @conceal)
21
+ (#set! conceal ""))
22
+
23
+ ; Conceal codeblock and text style markers
24
+ ([
25
+ (code_span_delimiter)
26
+ (emphasis_delimiter)
27
+ ] @conceal
28
+ (#set! conceal ""))
29
+
30
+ ; Conceal inline links
31
+ (inline_link
32
+ [
33
+ "["
34
+ "]"
35
+ "("
36
+ (link_destination)
37
+ ")"
38
+ ] @markup.link
39
+ (#set! conceal ""))
40
+
41
+ [
42
+ (link_label)
43
+ (link_text)
44
+ (link_title)
45
+ (image_description)
46
+ ] @markup.link.label
47
+
48
+ ((inline_link
49
+ (link_destination) @_url) @_label
50
+ (#set! @_label url @_url))
51
+
52
+ ((image
53
+ (link_destination) @_url) @_label
54
+ (#set! @_label url @_url))
55
+
56
+ ; Conceal image links
57
+ (image
58
+ [
59
+ "!"
60
+ "["
61
+ "]"
62
+ "("
63
+ (link_destination)
64
+ ")"
65
+ ] @markup.link
66
+ (#set! conceal ""))
67
+
68
+ ; Conceal full reference links
69
+ (full_reference_link
70
+ [
71
+ "["
72
+ "]"
73
+ (link_label)
74
+ ] @markup.link
75
+ (#set! conceal ""))
76
+
77
+ ; Conceal collapsed reference links
78
+ (collapsed_reference_link
79
+ [
80
+ "["
81
+ "]"
82
+ ] @markup.link
83
+ (#set! conceal ""))
84
+
85
+ ; Conceal shortcut links
86
+ (shortcut_link
87
+ [
88
+ "["
89
+ "]"
90
+ ] @markup.link
91
+ (#set! conceal ""))
92
+
93
+ [
94
+ (link_destination)
95
+ (uri_autolink)
96
+ (email_autolink)
97
+ ] @markup.link.url @nospell
98
+
99
+ ((uri_autolink) @_url
100
+ (#offset! @_url 0 1 0 -1)
101
+ (#set! @_url url @_url))
102
+
103
+ (entity_reference) @nospell
104
+
105
+ ; Replace common HTML entities.
106
+ ((entity_reference) @character.special
107
+ (#eq? @character.special "&nbsp;")
108
+ (#set! conceal " "))
109
+
110
+ ((entity_reference) @character.special
111
+ (#eq? @character.special "&lt;")
112
+ (#set! conceal "<"))
113
+
114
+ ((entity_reference) @character.special
115
+ (#eq? @character.special "&gt;")
116
+ (#set! conceal ">"))
117
+
118
+ ((entity_reference) @character.special
119
+ (#eq? @character.special "&amp;")
120
+ (#set! conceal "&"))
121
+
122
+ ((entity_reference) @character.special
123
+ (#eq? @character.special "&quot;")
124
+ (#set! conceal "\""))
125
+
126
+ ((entity_reference) @character.special
127
+ (#any-of? @character.special "&ensp;" "&emsp;")
128
+ (#set! conceal " "))
@@ -0,0 +1,7 @@
1
+ ((html_tag) @injection.content
2
+ (#set! injection.language "html")
3
+ (#set! injection.combined))
4
+
5
+ ((latex_block) @injection.content
6
+ (#set! injection.language "latex")
7
+ (#set! injection.include-children))
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const markdown = 'markdown' as const;
2
+ export const markdown_inline = 'markdown_inline' as const;