Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/common/htmlContent.test.ts
13397 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import assert from 'assert';
6
import { appendEscapedMarkdownInlineCode, escapeMarkdownLinkLabel } from '../../common/htmlContent.js';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from './utils.js';
8
9
suite('htmlContent', () => {
10
ensureNoDisposablesAreLeakedInTestSuite();
11
12
suite('appendEscapedMarkdownInlineCode', () => {
13
test('wraps plain text in single backticks', () => {
14
assert.strictEqual(appendEscapedMarkdownInlineCode('hello'), '`hello`');
15
assert.strictEqual(appendEscapedMarkdownInlineCode(''), '``');
16
assert.strictEqual(appendEscapedMarkdownInlineCode('foo bar'), '`foo bar`');
17
});
18
19
test('chooses a fence longer than any backtick run in the content', () => {
20
assert.strictEqual(appendEscapedMarkdownInlineCode('a`b'), '``a`b``');
21
assert.strictEqual(appendEscapedMarkdownInlineCode('a``b'), '```a``b```');
22
assert.strictEqual(appendEscapedMarkdownInlineCode('a```b```c'), '````a```b```c````');
23
});
24
25
test('pads with spaces when the content begins or ends with a backtick', () => {
26
assert.strictEqual(appendEscapedMarkdownInlineCode('`'), '`` ` ``');
27
assert.strictEqual(appendEscapedMarkdownInlineCode('`hello'), '`` `hello ``');
28
assert.strictEqual(appendEscapedMarkdownInlineCode('hello`'), '`` hello` ``');
29
assert.strictEqual(appendEscapedMarkdownInlineCode('`a`b`'), '`` `a`b` ``');
30
});
31
32
test('does not pad when backticks are only in the interior', () => {
33
assert.strictEqual(appendEscapedMarkdownInlineCode('a`b'), '``a`b``');
34
});
35
36
test('handles content composed entirely of backticks', () => {
37
assert.strictEqual(appendEscapedMarkdownInlineCode('``'), '``` `` ```');
38
});
39
});
40
41
suite('escapeMarkdownLinkLabel', () => {
42
test('passes plain text through unchanged', () => {
43
assert.strictEqual(escapeMarkdownLinkLabel('hello'), 'hello');
44
assert.strictEqual(escapeMarkdownLinkLabel(''), '');
45
assert.strictEqual(escapeMarkdownLinkLabel('heap-snapshot-analysis'), 'heap-snapshot-analysis');
46
assert.strictEqual(escapeMarkdownLinkLabel('foo.bar_baz'), 'foo.bar_baz');
47
});
48
49
test('escapes only `\\` and `]`', () => {
50
assert.strictEqual(escapeMarkdownLinkLabel('a]b'), 'a\\]b');
51
assert.strictEqual(escapeMarkdownLinkLabel('a\\b'), 'a\\\\b');
52
assert.strictEqual(escapeMarkdownLinkLabel(']]'), '\\]\\]');
53
});
54
55
test('does not escape characters that are safe in link text', () => {
56
// these would be escaped by escapeMarkdownSyntaxTokens but must
57
// pass through here since they render literally inside `[...]`.
58
assert.strictEqual(escapeMarkdownLinkLabel('a*b_c#d-e.f!g~h+i(j)k{l}m'), 'a*b_c#d-e.f!g~h+i(j)k{l}m');
59
});
60
});
61
});
62
63