diff --git a/src/md4w.zig b/src/md4w.zig index 7077a14..5e6292f 100644 --- a/src/md4w.zig +++ b/src/md4w.zig @@ -529,7 +529,7 @@ const JOSNRenderer = struct { if (code.lang.size > 0) { w.writeJSONProps(); w.write("\"lang\":\""); - w.writeJSONString(@as([*]const u8, @ptrCast(code.lang.text))[0..code.lang.size], 1); + w.writeJSONString(@as([*]const u8, @ptrCast(code.lang.text))[0..code.lang.size], 0); w.write("\"}"); } w.writeJSONChildren(); @@ -600,7 +600,7 @@ const JOSNRenderer = struct { w.writeJSONString(@as([*]const u8, @ptrCast(a.href.text))[0..a.href.size], 2); if (a.title.size > 0) { w.write("\",\"title\":"); - w.writeJSONString(@as([*]const u8, @ptrCast(a.title.text))[0..a.title.size], 1); + w.writeJSONString(@as([*]const u8, @ptrCast(a.title.text))[0..a.title.size], 0); } w.write("\"}"); w.writeJSONChildren(); @@ -647,7 +647,7 @@ const JOSNRenderer = struct { } if (img.title.size > 0) { w.write("\"title\":\""); - w.writeJSONString(@as([*]const u8, @ptrCast(img.title.text))[0..img.title.size], 1); + w.writeJSONString(@as([*]const u8, @ptrCast(img.title.text))[0..img.title.size], 0); w.write("\""); } w.write("}},"); @@ -701,9 +701,8 @@ const JOSNRenderer = struct { } }, else => { - const escape: u2 = if (typ == c.MD_TEXT_CODE) 0 else 1; w.writeByte('"'); - w.writeJSONString(@as([*]const u8, @ptrCast(ptr))[0..len], escape); + w.writeJSONString(@as([*]const u8, @ptrCast(ptr))[0..len], 0); w.write("\","); }, } diff --git a/test/test.js b/test/test.js index 19e2500..93265e1 100644 --- a/test/test.js +++ b/test/test.js @@ -15,10 +15,10 @@ await init(); Deno.test("render to string", async (t) => { await t.step("commonmark-spec", async () => { - const md = await Deno.readFile( + const specMd = await Deno.readFile( new URL("commonmark-spec.md", import.meta.url), ); - const html = mdToHtml(md); + const html = mdToHtml(specMd); assertIncludes(html, "

Introduction"); // main heading assertIncludes(html, '
    After we're done"); // last paragraph @@ -149,7 +149,7 @@ Deno.test("using code hightlighter", async () => { }); Deno.test("render to json", async () => { - const md = ` + const simpleMd = ` # Jobs Stay _foolish_, stay **hungry**! @@ -185,9 +185,11 @@ console.log('Hello, world!'); | :--- | ---: | | \`git status\` | List all *new or modified* files | | \`git diff\` | Show file differences that **haven't been** staged | + +This is hardly a "corner case," for some reason. `; - const tree = mdToJSON(md); + const tree = mdToJSON(simpleMd); assertEquals(tree, { children: [ { type: NodeType.H1, children: ["Jobs"] }, @@ -467,6 +469,18 @@ console.log('Hello, world!'); }, ], }, + { + type: NodeType.P, + children: [ + "This is hardly a \"corner case,\" for some reason.", + ], + } ], }); + + // Make sure spec can be parsed + // const specMd = await Deno.readFile( + // new URL("commonmark-spec.md", import.meta.url), + // ); + // mdToJSON(specMd); });