Skip to content

Commit 9ae4c8a

Browse files
committed
fix: correct parsing of inline code surrounded by triple backticks
1 parent 784f677 commit 9ae4c8a

File tree

3 files changed

+469
-5
lines changed

3 files changed

+469
-5
lines changed

src/typstToTextlintAst.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,13 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
307307
if (node.loc.start.line === node.loc.end.line) {
308308
// If Code
309309
node.type = ASTNodeTypes.Code;
310-
node.value = node.raw.replace(/`([\s\S]*?)`/, "$1");
310+
if (/^```([\s\S]*?)```$/.test(node.raw)) {
311+
const codeBlockPattern = /^```(\w+)?\s([\s\S]*?)\s*```$/;
312+
const match = node.raw.match(codeBlockPattern);
313+
node.value = match ? match[2].trim() : "";
314+
} else {
315+
node.value = node.raw.replace(/`([\s\S]*?)`/, "$1");
316+
}
311317
} else {
312318
// If CodeBlock
313319
node.type = ASTNodeTypes.CodeBlock;

test/fixtures/Code/input.typ

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
`inline code`
22

33
aaa `inline code` bbb
4+
5+
What is ```rust fn main()``` in Rust
6+
would be ```c int main()``` in C.
7+
8+
This has ``` `backticks` ``` in it
9+
(but the spaces are trimmed). And
10+
``` here``` the leading space is
11+
also trimmed.

0 commit comments

Comments
 (0)