mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 22:43:42 +00:00
When quoting a message with fenced code blocks without a language, we used to have ambiguity in which '```' fence terminates the quote. This commit adds explicitly non-interfering fences, which fixes the above issue as well as makes the raw message easier to quickly read. Fixes #12446.
21 lines
963 B
JavaScript
21 lines
963 B
JavaScript
zrequire('fenced_code');
|
|
|
|
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));
|
|
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));
|
|
let large_testcase = '';
|
|
// ```
|
|
// ````
|
|
// `````
|
|
// ... upto N chars
|
|
// We insert a N + 1 character fence.
|
|
for (let i = 3; i <= 20; i += 1) {
|
|
large_testcase += '`'.repeat(i) + '\n';
|
|
}
|
|
assert.equal(fenced_code.get_unused_fence(large_testcase), '`'.repeat(21));
|
|
});
|