// https://github.com/rsms/markdown-wasm/issues/5 const libdir = process.argv.includes("-debug") ? "build/debug" : "dist" const md = require(`../${libdir}/markdown.node.js`) // this triggers the bug const input1 = Buffer.from( "```\n" + " |\n" + "```" , "utf8") const expected1 = Buffer.from( "
" +
" |\n" +
"\n"
, "utf8")
// this does not (indent is 1 less space)
const input2 = Buffer.from(
"```\n" +
" |\n" +
"```"
, "utf8")
const expected2 = Buffer.from(
"" +
" |\n" +
"\n"
, "utf8")
// this does not (indent is 1 more space)
const input3 = Buffer.from(
"```\n" +
" |\n" +
"```"
, "utf8")
const expected3 = Buffer.from(
"" +
" |\n" +
"\n"
, "utf8")
let fails = 0
check("test1", expected1, input1)
check("test2", expected2, input2)
check("test3", expected3, input3)
function check(name, expected, inputData) {
const actual = Buffer.from(md.parse(inputData, { asMemoryView: true }))
if (expected.compare(actual) == 0) {
console.log(`${name} OK`)
return
}
fails++
const line = "——————————————————————————————————————————————————"
const wave = "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
console.error(`${name} FAIL.`)
console.error(`\n\nExpected output:\n${line}`)
inspectBuf(expected, actual)
console.error(`${line}\n\nActual output:\n${line}`)
inspectBuf(actual, expected)
console.error(line)
function inspectBuf(buf, otherbuf) {
process.stderr.write(buf)
if (buf[buf.length-1] != 0x0a) {
process.stderr.write("