Skip to content

Commit 3e6567d

Browse files
committed
Ignore code blocks and raw text in Typst
See #74
1 parent d58b083 commit 3e6567d

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

changelog.xml

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<action type="fix" issue="#72">
3030
Fix false positives in Typst
3131
</action>
32+
<action type="fix" issue="#74">
33+
Ignore code blocks and raw text in Typst
34+
</action>
3235
</release>
3336
<release version="18.4.0" date="2024-12-23">
3437
<action type="add" issue="valentjn/ltex-ls#268" due-to="Benoît Pasquier">

src/main/kotlin/org/bsplines/ltexls/parsing/typst/TypstAnnotatedTextBuilder.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class TypstAnnotatedTextBuilder(
3737
addMarkupInternal(LET_CURLY_BRACKETS_REGEX)
3838
addMarkupInternal(LET_CODE_REGEX, "", false, true)
3939
addMarkupInternal(LET_REGEX)
40+
addMarkupInternal(RAW_CODE_REGEX_1, "", true)
41+
addMarkupInternal(RAW_CODE_REGEX_2, "", true)
42+
addMarkupInternal(RAW_CODE_REGEX_3, "", true)
4043
addMarkupInternal(CITE_REGEX)
4144
addMarkupInternal(CODE_REGEX, "", false, true)
4245
addMarkupInternal(CODE_SQUARE_BRACKETS_REGEX, "", true)
@@ -149,7 +152,7 @@ class TypstAnnotatedTextBuilder(
149152
// String within code mode to be spell checked
150153
addText(this.curString)
151154
} else {
152-
addMarkupInternal(SPELLCHECK_EXCLUDED_PROPERTY_REGEX)
155+
addMarkupInternal(PROPERTY_REGEX)
153156
addMarkup(this.curString)
154157
}
155158
}
@@ -184,6 +187,9 @@ class TypstAnnotatedTextBuilder(
184187
private val LET_CURLY_BRACKETS_REGEX = Regex("^#let.*=\\s*\\{(.|\r?\n)*?\\}")
185188
private val LET_CODE_REGEX = Regex("^#let.*?=\\s*?\\w*?\\(")
186189
private val LET_REGEX = Regex("^#let.*=\\s*")
190+
private val RAW_CODE_REGEX_1 = Regex("^`{3,}(.|\r?\n)*?`{3,}")
191+
private val RAW_CODE_REGEX_2 = Regex("^`(.|\r?\n)*?`")
192+
private val RAW_CODE_REGEX_3 = Regex("^#raw\\((.|\r?\n)*?[^\\\\]\"\\)")
187193
private val CITE_REGEX = Regex("^#cite\\(\\S+\\)")
188194
private val CODE_REGEX = Regex("^#.*?\\(")
189195
private val CODE_SQUARE_BRACKETS_REGEX = Regex("^#.*\\[(.|\r?\n)*?\\]")
@@ -196,7 +202,7 @@ class TypstAnnotatedTextBuilder(
196202
private val LABEL_REF_REGEX = Regex("^<[^\\s]*>")
197203
private val VARIABLE_REGEX = Regex("^#\\S+")
198204
private val FILENAME_REGEX = Regex("^.+\\.\\w{1,4}")
199-
private val SPELLCHECK_EXCLUDED_PROPERTY_REGEX =
205+
private val PROPERTY_REGEX =
200206
Regex(
201207
"^(font|style|weight|top-edge|bottom-edge|lang|region|script|number-type|number-width)\\s?:\\s?\".*?\"",
202208
)

src/test/kotlin/org/bsplines/ltexls/parsing/typst/TypstAnnotatedTextBuilderTest.kt

+26
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,32 @@ class TypstAnnotatedTextBuilderTest : CodeAnnotatedTextBuilderTest("typst") {
8080
)
8181
}
8282

83+
@Test
84+
fun testRawCode() {
85+
assertPlainText(
86+
"""
87+
Raw code should not be `spell checked`.
88+
```php
89+
function main() {
90+
echo("Hello World!");
91+
}
92+
```
93+
You can do the same with the raw element.
94+
#raw("function main() {echo(\"Hello World!\");}", lang: "php")
95+
Single `backticks` work, too.
96+
More text after the code block.
97+
""".trimIndent(),
98+
"""
99+
Raw code should not be Dummy0.
100+
Dummy1
101+
You can do the same with the raw element.
102+
Dummy2
103+
Single Dummy3 work, too.
104+
More text after the code block.
105+
""".trimIndent(),
106+
)
107+
}
108+
83109
@Test
84110
fun testMarkup() {
85111
assertPlainText(

0 commit comments

Comments
 (0)