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,28 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "CodepadLangMarkdown"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+ s.platforms = { :ios => "17.0" }
13
+ s.source = { :git => "https://github.com/SectionTN/react-native-codepad.git", :tag => "v#{s.version}" }
14
+
15
+ s.source_files = ["ios/*.{h,swift}", "grammar/tree-sitter-markdown/src/parser.c", "grammar/tree-sitter-markdown/src/scanner.c", "grammar/tree-sitter-markdown-inline/src/parser.c", "grammar/tree-sitter-markdown-inline/src/scanner.c"]
16
+ s.public_header_files = "ios/*.h"
17
+ s.preserve_paths = "grammar/**/*"
18
+ s.compiler_flags = "-w"
19
+ s.pod_target_xcconfig = {
20
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/grammar/tree-sitter-markdown/src\" \"$(PODS_TARGET_SRCROOT)/grammar/tree-sitter-markdown-inline/src\"",
21
+ "GCC_OPTIMIZATION_LEVEL" => "1",
22
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
23
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
24
+ "DEFINES_MODULE" => "YES",
25
+ }
26
+
27
+ s.dependency "Codepad"
28
+ end
package/README.md CHANGED
@@ -1,3 +1,51 @@
1
- # Temporary Holding Version
1
+ # react-native-codepad-lang-markdown
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Generated package. Do not edit by hand; run `yarn gen:languages` in the react-native-codepad repository.
4
+
5
+ Grammar: tree-sitter-grammars/tree-sitter-markdown at a0a00f817d02412bd92c54d316f164d827b57b5c. Queries: nvim-treesitter at e289100ff98969e118c702199d88b764ce9e7fdf.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ yarn add react-native-codepad react-native-codepad-lang-markdown
11
+ ```
12
+
13
+ Then pass `language="markdown"` to `CodeEditor`. Theme token keys this package produces:
14
+
15
+ ### markdown
16
+
17
+ - `keyword.directive`
18
+ - `label`
19
+ - `markup.heading`
20
+ - `markup.heading.1`
21
+ - `markup.heading.2`
22
+ - `markup.heading.3`
23
+ - `markup.heading.4`
24
+ - `markup.heading.5`
25
+ - `markup.heading.6`
26
+ - `markup.link.label`
27
+ - `markup.link.url`
28
+ - `markup.list`
29
+ - `markup.list.checked`
30
+ - `markup.list.unchecked`
31
+ - `markup.quote`
32
+ - `markup.raw.block`
33
+ - `punctuation.delimiter`
34
+ - `punctuation.special`
35
+ - `spell`
36
+ - `string.escape`
37
+
38
+ ### markdown_inline
39
+
40
+ - `character.special`
41
+ - `conceal`
42
+ - `markup.italic`
43
+ - `markup.link`
44
+ - `markup.link.label`
45
+ - `markup.link.url`
46
+ - `markup.raw`
47
+ - `markup.strikethrough`
48
+ - `markup.strong`
49
+ - `nospell`
50
+
51
+ See the [languages guide](https://sectiontn.github.io/react-native-codepad/guides/languages/) for aliases, injections and themes.
@@ -0,0 +1,19 @@
1
+ cmake_minimum_required(VERSION 3.13)
2
+ project(codepad_lang_markdown C)
3
+ set(GRAMMAR ${CMAKE_SOURCE_DIR}/../grammar)
4
+
5
+ add_library(codepad_lang_markdown SHARED
6
+ src/main/cpp/lang.c
7
+ ${GRAMMAR}/tree-sitter-markdown/src/parser.c
8
+ ${GRAMMAR}/tree-sitter-markdown/src/scanner.c
9
+ ${GRAMMAR}/tree-sitter-markdown-inline/src/parser.c
10
+ ${GRAMMAR}/tree-sitter-markdown-inline/src/scanner.c
11
+ )
12
+
13
+ target_include_directories(codepad_lang_markdown PRIVATE ${GRAMMAR}/tree-sitter-markdown/src)
14
+ target_include_directories(codepad_lang_markdown PRIVATE ${GRAMMAR}/tree-sitter-markdown-inline/src)
15
+
16
+ # Parser tables are data. -O1 keeps large grammars from taking minutes to compile.
17
+ set_source_files_properties(${GRAMMAR}/tree-sitter-markdown/src/parser.c PROPERTIES COMPILE_OPTIONS "-O1")
18
+ set_source_files_properties(${GRAMMAR}/tree-sitter-markdown-inline/src/parser.c PROPERTIES COMPILE_OPTIONS "-O1")
19
+ target_compile_options(codepad_lang_markdown PRIVATE -std=c11 -O2 -fvisibility=hidden -w)
@@ -0,0 +1,61 @@
1
+ buildscript {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ }
6
+ dependencies {
7
+ classpath "com.android.tools.build:gradle:8.7.2"
8
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21"
9
+ }
10
+ }
11
+
12
+ apply plugin: "com.android.library"
13
+ if (project.extensions.findByName("kotlin") == null) {
14
+ apply plugin: "kotlin-android"
15
+ }
16
+ apply plugin: "com.facebook.react"
17
+
18
+ def safeExtGet(prop, fallback) {
19
+ rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
20
+ }
21
+
22
+ def reactNativeArchitectures() {
23
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
24
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
25
+ }
26
+
27
+ android {
28
+ namespace "me.sectiontn.codepad.lang.markdown"
29
+ compileSdkVersion safeExtGet("compileSdkVersion", 36)
30
+
31
+ defaultConfig {
32
+ minSdkVersion safeExtGet("minSdkVersion", 24)
33
+ consumerProguardFiles "consumer-rules.pro"
34
+ externalNativeBuild {
35
+ cmake {
36
+ arguments "-DANDROID_STL=none", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
37
+ abiFilters(*reactNativeArchitectures())
38
+ }
39
+ }
40
+ }
41
+
42
+ if (rootProject.ext.has("ndkVersion")) {
43
+ ndkVersion rootProject.ext.ndkVersion
44
+ }
45
+
46
+ externalNativeBuild {
47
+ cmake {
48
+ path "CMakeLists.txt"
49
+ }
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_17
54
+ targetCompatibility JavaVersion.VERSION_17
55
+ }
56
+ }
57
+
58
+ dependencies {
59
+ implementation "com.facebook.react:react-android"
60
+ implementation project(":react-native-codepad")
61
+ }
@@ -0,0 +1,2 @@
1
+ -keep class me.sectiontn.codepad.lang.markdown.MarkdownLanguage { *; }
2
+ -keep class me.sectiontn.codepad.lang.markdown_inline.MarkdownInlineLanguage { *; }
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,17 @@
1
+ #include <jni.h>
2
+ #include <stdint.h>
3
+
4
+ const void *tree_sitter_markdown(void);
5
+ const void *tree_sitter_markdown_inline(void);
6
+
7
+ JNIEXPORT jlong JNICALL Java_me_sectiontn_codepad_lang_markdown_MarkdownLanguage_nativeLanguage(JNIEnv *env, jobject thiz) {
8
+ (void) env;
9
+ (void) thiz;
10
+ return (jlong) (intptr_t) tree_sitter_markdown();
11
+ }
12
+
13
+ JNIEXPORT jlong JNICALL Java_me_sectiontn_codepad_lang_markdown_1inline_MarkdownInlineLanguage_nativeLanguage(JNIEnv *env, jobject thiz) {
14
+ (void) env;
15
+ (void) thiz;
16
+ return (jlong) (intptr_t) tree_sitter_markdown_inline();
17
+ }
@@ -0,0 +1,13 @@
1
+ package me.sectiontn.codepad.lang.markdown
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfoProvider
7
+
8
+ // Empty package so React Native autolinking includes this Gradle module.
9
+ class CodepadLangMarkdownPackage : BaseReactPackage() {
10
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? = null
11
+
12
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = ReactModuleInfoProvider { HashMap() }
13
+ }
@@ -0,0 +1,169 @@
1
+ package me.sectiontn.codepad.lang.markdown
2
+
3
+ import me.sectiontn.codepad.syntax.LanguageProvider
4
+
5
+ class MarkdownLanguage : LanguageProvider {
6
+ override val id: String = "markdown"
7
+ override val languagePointer: Long get() = nativeLanguage()
8
+ override val highlights: String = HIGHLIGHTS
9
+ override val injections: String = INJECTIONS
10
+
11
+ private external fun nativeLanguage(): Long
12
+
13
+ companion object {
14
+ init {
15
+ System.loadLibrary("codepad_lang_markdown")
16
+ }
17
+
18
+ private val HIGHLIGHTS: String = """;From MDeiml/tree-sitter-markdown & Helix
19
+ (setext_heading
20
+ (paragraph) @markup.heading.1
21
+ (setext_h1_underline) @markup.heading.1)
22
+
23
+ (setext_heading
24
+ (paragraph) @markup.heading.2
25
+ (setext_h2_underline) @markup.heading.2)
26
+
27
+ (atx_heading
28
+ (atx_h1_marker)) @markup.heading.1
29
+
30
+ (atx_heading
31
+ (atx_h2_marker)) @markup.heading.2
32
+
33
+ (atx_heading
34
+ (atx_h3_marker)) @markup.heading.3
35
+
36
+ (atx_heading
37
+ (atx_h4_marker)) @markup.heading.4
38
+
39
+ (atx_heading
40
+ (atx_h5_marker)) @markup.heading.5
41
+
42
+ (atx_heading
43
+ (atx_h6_marker)) @markup.heading.6
44
+
45
+ (info_string) @label
46
+
47
+ (pipe_table_header
48
+ (pipe_table_cell) @markup.heading)
49
+
50
+ (pipe_table_header
51
+ "|" @punctuation.special)
52
+
53
+ (pipe_table_row
54
+ "|" @punctuation.special)
55
+
56
+ (pipe_table_delimiter_row
57
+ "|" @punctuation.special)
58
+
59
+ (pipe_table_delimiter_cell) @punctuation.special
60
+
61
+ ; Code blocks (conceal backticks and language annotation)
62
+ (indented_code_block) @markup.raw.block
63
+
64
+ ((fenced_code_block) @markup.raw.block
65
+ (#set! priority 90))
66
+
67
+ (fenced_code_block
68
+ (fenced_code_block_delimiter) @markup.raw.block
69
+ (#set! conceal "")
70
+ (#set! conceal_lines ""))
71
+
72
+ (fenced_code_block
73
+ (info_string
74
+ (language) @label
75
+ (#set! conceal "")
76
+ (#set! conceal_lines "")))
77
+
78
+ (link_destination) @markup.link.url
79
+
80
+ [
81
+ (link_title)
82
+ (link_label)
83
+ ] @markup.link.label
84
+
85
+ ((link_label)
86
+ .
87
+ ":" @punctuation.delimiter)
88
+
89
+ [
90
+ (list_marker_plus)
91
+ (list_marker_minus)
92
+ (list_marker_star)
93
+ (list_marker_dot)
94
+ (list_marker_parenthesis)
95
+ ] @markup.list
96
+
97
+ ; NOTE: The following has been commented out due to issues with spaces in the
98
+ ; list marker nodes generated by the parser. If those spaces ever get captured
99
+ ; by a different node (e.g. block_continuation) we can safely re-add these
100
+ ; conceals.
101
+ ; ;; Conceal bullet points
102
+ ; ([(list_marker_plus) (list_marker_star)]
103
+ ; @punctuation.special
104
+ ; (#offset! @punctuation.special 0 0 0 -1)
105
+ ; (#set! conceal "•"))
106
+ ; ([(list_marker_plus) (list_marker_star)]
107
+ ; @punctuation.special
108
+ ; (#any-of? @punctuation.special "+" "*")
109
+ ; (#set! conceal "•"))
110
+ ; ((list_marker_minus)
111
+ ; @punctuation.special
112
+ ; (#offset! @punctuation.special 0 0 0 -1)
113
+ ; (#set! conceal "—"))
114
+ ; ((list_marker_minus)
115
+ ; @punctuation.special
116
+ ; (#eq? @punctuation.special "-")
117
+ ; (#set! conceal "—"))
118
+ (thematic_break) @punctuation.special
119
+
120
+ (task_list_marker_unchecked) @markup.list.unchecked
121
+
122
+ (task_list_marker_checked) @markup.list.checked
123
+
124
+ ((block_quote) @markup.quote
125
+ (#set! priority 90))
126
+
127
+ ([
128
+ (plus_metadata)
129
+ (minus_metadata)
130
+ ] @keyword.directive
131
+ (#set! priority 90))
132
+
133
+ [
134
+ (block_continuation)
135
+ (block_quote_marker)
136
+ ] @punctuation.special
137
+
138
+ (backslash_escape) @string.escape
139
+
140
+ (inline) @spell
141
+ """
142
+ private val INJECTIONS: String = """(fenced_code_block
143
+ (info_string
144
+ (language) @injection.language)
145
+ (code_fence_content) @injection.content)
146
+
147
+ ((html_block) @injection.content
148
+ (#set! injection.language "html")
149
+ (#set! injection.combined)
150
+ (#set! injection.include-children))
151
+
152
+ ((minus_metadata) @injection.content
153
+ (#set! injection.language "yaml")
154
+ (#offset! @injection.content 1 0 -1 0)
155
+ (#set! injection.include-children))
156
+
157
+ ((plus_metadata) @injection.content
158
+ (#set! injection.language "toml")
159
+ (#offset! @injection.content 1 0 -1 0)
160
+ (#set! injection.include-children))
161
+
162
+ ([
163
+ (inline)
164
+ (pipe_table_cell)
165
+ ] @injection.content
166
+ (#set! injection.language "markdown_inline"))
167
+ """
168
+ }
169
+ }
@@ -0,0 +1,156 @@
1
+ package me.sectiontn.codepad.lang.markdown_inline
2
+
3
+ import me.sectiontn.codepad.syntax.LanguageProvider
4
+
5
+ class MarkdownInlineLanguage : LanguageProvider {
6
+ override val id: String = "markdown_inline"
7
+ override val languagePointer: Long get() = nativeLanguage()
8
+ override val highlights: String = HIGHLIGHTS
9
+ override val injections: String = INJECTIONS
10
+
11
+ private external fun nativeLanguage(): Long
12
+
13
+ companion object {
14
+ init {
15
+ System.loadLibrary("codepad_lang_markdown")
16
+ }
17
+
18
+ private val HIGHLIGHTS: String = """; From MDeiml/tree-sitter-markdown
19
+ (code_span) @markup.raw @nospell
20
+
21
+ (emphasis) @markup.italic
22
+
23
+ (strong_emphasis) @markup.strong
24
+
25
+ (strikethrough) @markup.strikethrough
26
+
27
+ (shortcut_link
28
+ (link_text) @nospell)
29
+
30
+ ; Conceal backslash in backslash escapes
31
+ ((backslash_escape) @conceal
32
+ (#offset! @conceal 0 0 0 -1)
33
+ (#set! conceal ""))
34
+
35
+ ; Conceal backslash in hard line breaks
36
+ ((hard_line_break
37
+ "\\" @conceal)
38
+ (#set! conceal ""))
39
+
40
+ ; Conceal codeblock and text style markers
41
+ ([
42
+ (code_span_delimiter)
43
+ (emphasis_delimiter)
44
+ ] @conceal
45
+ (#set! conceal ""))
46
+
47
+ ; Conceal inline links
48
+ (inline_link
49
+ [
50
+ "["
51
+ "]"
52
+ "("
53
+ (link_destination)
54
+ ")"
55
+ ] @markup.link
56
+ (#set! conceal ""))
57
+
58
+ [
59
+ (link_label)
60
+ (link_text)
61
+ (link_title)
62
+ (image_description)
63
+ ] @markup.link.label
64
+
65
+ ((inline_link
66
+ (link_destination) @_url) @_label
67
+ (#set! @_label url @_url))
68
+
69
+ ((image
70
+ (link_destination) @_url) @_label
71
+ (#set! @_label url @_url))
72
+
73
+ ; Conceal image links
74
+ (image
75
+ [
76
+ "!"
77
+ "["
78
+ "]"
79
+ "("
80
+ (link_destination)
81
+ ")"
82
+ ] @markup.link
83
+ (#set! conceal ""))
84
+
85
+ ; Conceal full reference links
86
+ (full_reference_link
87
+ [
88
+ "["
89
+ "]"
90
+ (link_label)
91
+ ] @markup.link
92
+ (#set! conceal ""))
93
+
94
+ ; Conceal collapsed reference links
95
+ (collapsed_reference_link
96
+ [
97
+ "["
98
+ "]"
99
+ ] @markup.link
100
+ (#set! conceal ""))
101
+
102
+ ; Conceal shortcut links
103
+ (shortcut_link
104
+ [
105
+ "["
106
+ "]"
107
+ ] @markup.link
108
+ (#set! conceal ""))
109
+
110
+ [
111
+ (link_destination)
112
+ (uri_autolink)
113
+ (email_autolink)
114
+ ] @markup.link.url @nospell
115
+
116
+ ((uri_autolink) @_url
117
+ (#offset! @_url 0 1 0 -1)
118
+ (#set! @_url url @_url))
119
+
120
+ (entity_reference) @nospell
121
+
122
+ ; Replace common HTML entities.
123
+ ((entity_reference) @character.special
124
+ (#eq? @character.special "&nbsp;")
125
+ (#set! conceal " "))
126
+
127
+ ((entity_reference) @character.special
128
+ (#eq? @character.special "&lt;")
129
+ (#set! conceal "<"))
130
+
131
+ ((entity_reference) @character.special
132
+ (#eq? @character.special "&gt;")
133
+ (#set! conceal ">"))
134
+
135
+ ((entity_reference) @character.special
136
+ (#eq? @character.special "&amp;")
137
+ (#set! conceal "&"))
138
+
139
+ ((entity_reference) @character.special
140
+ (#eq? @character.special "&quot;")
141
+ (#set! conceal "\""))
142
+
143
+ ((entity_reference) @character.special
144
+ (#any-of? @character.special "&ensp;" "&emsp;")
145
+ (#set! conceal " "))
146
+ """
147
+ private val INJECTIONS: String = """((html_tag) @injection.content
148
+ (#set! injection.language "html")
149
+ (#set! injection.combined))
150
+
151
+ ((latex_block) @injection.content
152
+ (#set! injection.language "latex")
153
+ (#set! injection.include-children))
154
+ """
155
+ }
156
+ }
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Matthias Deiml
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.