Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/promptFiles/parsePromptFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import * as YAML from "yaml";
import { getLastNPathParts } from "../util/uri";

export function parsePromptFile(path: string, content: string) {
let [preambleRaw, prompt] = content.split("\n---\n");
const normalizedContent = content.replace(/\r\n/g, "\n");
let [preambleRaw, prompt] = normalizedContent.split("\n---\n");
if (prompt === undefined) {
prompt = preambleRaw;
preambleRaw = "";
Expand Down
37 changes: 37 additions & 0 deletions core/promptFiles/parsePromptFile.vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { describe, expect, it } from "vitest";
import { parsePromptFile } from "./parsePromptFile";

describe("parsePromptFile", () => {
const path = "test.prompt";

it("should parse LF content correctly", () => {
const content = "name: test\ndescription: a test\n---\nHello world";
const result = parsePromptFile(path, content);
expect(result.name).toBe("test");
expect(result.description).toBe("a test");
expect(result.prompt).toBe("Hello world");
});

it("should parse CRLF content correctly", () => {
const content = "name: test\r\ndescription: a test\r\n---\r\nHello world";
const result = parsePromptFile(path, content);
expect(result.name).toBe("test");
expect(result.description).toBe("a test");
expect(result.prompt).toBe("Hello world");
});

it("should handle no frontmatter", () => {
const content = "Just a prompt";
const result = parsePromptFile(path, content);
expect(result.prompt).toBe("Just a prompt");
expect(result.name).toBe("test");
});

it("should parse system tag with CRLF", () => {
const content =
"name: test\r\n---\r\n<system>You are helpful</system>\r\nHello";
const result = parsePromptFile(path, content);
expect(result.systemMessage).toBe("You are helpful");
expect(result.prompt).toBe("Hello");
});
});
Loading