-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9dd6ec3
commit 123f3f0
Showing
6 changed files
with
80 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
export function parseNamedNode(content: string): { | ||
name: string | null; | ||
content: string; | ||
} { | ||
const lines = content.split('\n'); | ||
const firstLine = lines[0].trim(); | ||
|
||
// Check if the first line is a single-bracketed name | ||
if (firstLine.startsWith('[') && firstLine.endsWith(']') && !firstLine.startsWith('[[')) { | ||
// Try to parse as JSON to ensure it's not a valid JSON array | ||
try { | ||
JSON.parse(firstLine); | ||
// If it's a valid JSON array, don't treat it as a name | ||
return { name: null, content }; | ||
} catch { | ||
// Not a valid JSON array, so it's a name | ||
const name = firstLine.slice(1, -1); | ||
const remainingContent = lines.slice(1).join('\n'); | ||
return { name, content: remainingContent }; | ||
} | ||
} | ||
|
||
// If not a single-bracketed name, return null for name and the entire content | ||
return { name: null, content }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters