Skip to content

Commit

Permalink
add filename map to body transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
Chuanqi Sun committed Sep 2, 2023
1 parent 5fcbb75 commit 1a30b44
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/tools/markdown-converter/haiku-to-md.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async function main(inputDir) {
// convert headerLines to yaml
const { frontmatter, timeId } = handleHeaderLines(haikuFile, headerLines);

const body = handleBodyLines(haikuFile, bodyLines);
const body = handleBodyLines(haikuFile, bodyLines, filenameMap);

// TODO pass through markdown and yaml parser

Expand Down
4 changes: 3 additions & 1 deletion packages/tools/markdown-converter/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ export function handleHeaderLines(haikuFile, headerLines) {
}

/**
* @param {string} haikuFile
* @param {string[]} bodyLines
* @param {Map<string, string>} filenameMap
*/
export function handleBodyLines(haikuFile, bodyLines) {
export function handleBodyLines(haikuFile, bodyLines, filenameMap) {
// trim bodyLines
while (bodyLines[0]?.trim() === "") {
bodyLines.shift();
Expand Down
29 changes: 16 additions & 13 deletions packages/tools/markdown-converter/lib.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,39 +111,42 @@ describe("header", () => {

describe("body", () => {
it("handles basic list", () => {
assert.strictEqual(handleBodyLines("", fileToLines(`- item\n- item\n- item`).bodyLines), `- item\n- item\n- item`);
assert.strictEqual(
handleBodyLines("", fileToLines(`- item\n- item\n- item`).bodyLines, new Map()),
`- item\n- item\n- item`
);
});
it("handles nested list", () => {
assert.strictEqual(
handleBodyLines("", fileToLines(`- item\n-- item\n--- item`).bodyLines),
handleBodyLines("", fileToLines(`- item\n-- item\n--- item`).bodyLines, new Map()),
`- item\n - item\n - item`
);
});
it("handles ordered list", () => {
assert.strictEqual(
handleBodyLines("", fileToLines(`1. item\n2. item\n3. item`).bodyLines),
handleBodyLines("", fileToLines(`1. item\n2. item\n3. item`).bodyLines, new Map()),
`- 1. item\n- 2. item\n- 3. item`
);
});
it("handles nested ordered list", () => {
assert.strictEqual(
handleBodyLines("", fileToLines(`1. item\n-1. item\n--1. item`).bodyLines),
handleBodyLines("", fileToLines(`1. item\n-1. item\n--1. item`).bodyLines, new Map()),
`- 1. item\n - 1. item\n - 1. item`
);
});
it("invalid lists", () => {
assert.throws(() => handleBodyLines("", fileToLines(`+ item`).bodyLines));
assert.throws(() => handleBodyLines("", fileToLines(`* item`).bodyLines));
assert.throws(() => handleBodyLines("", fileToLines(`+ item`).bodyLines, new Map()));
assert.throws(() => handleBodyLines("", fileToLines(`* item`).bodyLines, new Map()));
});
it("handles quotes", () => {
assert.strictEqual(handleBodyLines("", fileToLines(`> quote`).bodyLines), `> quote`);
assert.strictEqual(handleBodyLines("", fileToLines(`> quote`).bodyLines, new Map()), `> quote`);
});
it("handles heading", () => {
assert.strictEqual(handleBodyLines("", fileToLines(`# heading`).bodyLines), `# heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`## heading`).bodyLines), `## heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`### heading`).bodyLines), `### heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`#### heading`).bodyLines), `#### heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`##### heading`).bodyLines), `##### heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`###### heading`).bodyLines), `###### heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`# heading`).bodyLines, new Map()), `# heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`## heading`).bodyLines, new Map()), `## heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`### heading`).bodyLines, new Map()), `### heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`#### heading`).bodyLines, new Map()), `#### heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`##### heading`).bodyLines, new Map()), `##### heading`);
assert.strictEqual(handleBodyLines("", fileToLines(`###### heading`).bodyLines, new Map()), `###### heading`);
});
});

0 comments on commit 1a30b44

Please sign in to comment.