2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-10-09 00:25:41 +02:00
|
|
|
const assert = require("node:assert/strict");
|
2020-11-30 23:46:45 +01:00
|
|
|
|
2024-11-13 07:05:32 +01:00
|
|
|
const {zrequire} = require("./lib/namespace.cjs");
|
|
|
|
const {run_test} = require("./lib/test.cjs");
|
2020-12-01 00:02:16 +01:00
|
|
|
|
2023-02-22 23:03:47 +01:00
|
|
|
const fenced_code = zrequire("../shared/src/fenced_code");
|
2019-08-26 09:04:34 +02:00
|
|
|
|
2021-03-12 15:01:54 +01:00
|
|
|
// Check the default behavior of fenced code blocks
|
|
|
|
// works properly before Markdown is initialized.
|
|
|
|
run_test("fenced_block_defaults", () => {
|
|
|
|
const input = "\n```\nfenced code\n```\n\nand then after\n";
|
|
|
|
const expected =
|
|
|
|
'\n\n<div class="codehilite"><pre><span></span><code>fenced code\n</code></pre></div>\n\n\nand then after\n\n';
|
|
|
|
const output = fenced_code.process_fenced_code(input);
|
|
|
|
assert.equal(output, expected);
|
|
|
|
});
|
|
|
|
|
2020-07-15 01:29:15 +02:00
|
|
|
run_test("get_unused_fence", () => {
|
|
|
|
assert.equal(fenced_code.get_unused_fence("```js\nsomething\n```"), "`".repeat(4));
|
|
|
|
assert.equal(fenced_code.get_unused_fence("````\nsomething\n````"), "`".repeat(5));
|
|
|
|
assert.equal(fenced_code.get_unused_fence("```\n````\n``````"), "`".repeat(7));
|
|
|
|
assert.equal(fenced_code.get_unused_fence("~~~\nsomething\n~~~"), "`".repeat(3));
|
2020-07-15 00:34:28 +02:00
|
|
|
assert.equal(
|
|
|
|
fenced_code.get_unused_fence("```code\nterminating fence is indented and longer\n ````"),
|
|
|
|
"`".repeat(5),
|
|
|
|
);
|
|
|
|
assert.equal(
|
|
|
|
fenced_code.get_unused_fence("```code\nterminating fence is extra indented\n ````"),
|
|
|
|
"`".repeat(4),
|
|
|
|
);
|
2020-07-15 01:29:15 +02:00
|
|
|
let large_testcase = "";
|
2019-08-26 09:04:34 +02:00
|
|
|
// ```
|
|
|
|
// ````
|
|
|
|
// `````
|
2020-03-28 01:25:56 +01:00
|
|
|
// ... up to N chars
|
2019-08-26 09:04:34 +02:00
|
|
|
// We insert a N + 1 character fence.
|
|
|
|
for (let i = 3; i <= 20; i += 1) {
|
2020-07-15 01:29:15 +02:00
|
|
|
large_testcase += "`".repeat(i) + "\n";
|
2019-08-26 09:04:34 +02:00
|
|
|
}
|
2020-07-15 01:29:15 +02:00
|
|
|
assert.equal(fenced_code.get_unused_fence(large_testcase), "`".repeat(21));
|
2019-08-26 09:04:34 +02:00
|
|
|
});
|