Skip to content

Commit

Permalink
Allow - in snippet body
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Jul 21, 2024
1 parent a5911e4 commit 16bf320
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "andreas-talon",
"displayName": "Andreas Talon",
"description": "VSCode extension used by Talon Voice",
"version": "3.50.0",
"version": "3.51.0",
"publisher": "AndreasArvidsson",
"license": "MIT",
"main": "./out/extension.js",
Expand Down
10 changes: 4 additions & 6 deletions src/language/SnippetParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ export function parseSnippetFile(content: string): SnippetDocument[] {

function parseDocument(text: string): SnippetDocument | undefined {
const parts = text.split(/^-$/m);
if (parts.length > 2) {
throw Error(`Found multiple '-' in snippet document '${text}'`);
}
let document = parseContext(parts[0]);
if (parts.length === 2) {
const body = parseBody(parts[1]);
if (parts.length > 1) {
const bodyText = parts.slice(1).join("-");
const body = parseBody(bodyText);
if (body != null) {
if (document == null) {
document = { variables: [] };
}
document.body = parseBody(parts[1]);
document.body = body;
}
}
return document;
Expand Down
18 changes: 18 additions & 0 deletions src/test/snippetFormatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ phrase: test
-
test
---
`
},
{
title: "- in body",
pre: `\
name: test
-
a
-
b
`,
post: `\
name: test
-
a
-
b
---
`
},
{
Expand Down

0 comments on commit 16bf320

Please sign in to comment.