Skip to content

Commit

Permalink
fix: correct parsing of inline code surrounded by triple backticks
Browse files Browse the repository at this point in the history
  • Loading branch information
3w36zj6 committed Oct 13, 2024
1 parent 784f677 commit 9ae4c8a
Show file tree
Hide file tree
Showing 3 changed files with 469 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/typstToTextlintAst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,13 @@ export const convertRawTypstAstObjectToTextlintAstObject = (
if (node.loc.start.line === node.loc.end.line) {
// If Code
node.type = ASTNodeTypes.Code;
node.value = node.raw.replace(/`([\s\S]*?)`/, "$1");
if (/^```([\s\S]*?)```$/.test(node.raw)) {
const codeBlockPattern = /^```(\w+)?\s([\s\S]*?)\s*```$/;
const match = node.raw.match(codeBlockPattern);
node.value = match ? match[2].trim() : "";
} else {
node.value = node.raw.replace(/`([\s\S]*?)`/, "$1");
}
} else {
// If CodeBlock
node.type = ASTNodeTypes.CodeBlock;
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/Code/input.typ
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
`inline code`

aaa `inline code` bbb

What is ```rust fn main()``` in Rust
would be ```c int main()``` in C.

This has ``` `backticks` ``` in it
(but the spaces are trimmed). And
``` here``` the leading space is
also trimmed.
Loading

0 comments on commit 9ae4c8a

Please sign in to comment.