Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/services/jsonHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ function toMarkdown(plain: string | undefined): string | undefined {
return plain
.trim()
.replace(/[\\`*_{}[\]()<>#+\-.!]/g, '\\$&') // escape markdown syntax tokens: http://daringfireball.net/projects/markdown/syntax#backslash
.replace(/([ \t]+)/g, (_match, g1) => '&nbsp;'.repeat(g1.length)) // escape spaces tabs
.replace(/(^ +)/mg, (_match, g1) => '&nbsp;'.repeat(g1.length)) // escape leading spaces on each line
.replace(/( {2,})/g, (_match, g1) => ' ' + '&nbsp;'.repeat(g1.length - 1)) // escape consecutive spaces
.replace(/(\t+)/g, (_match, g1) => '&nbsp;'.repeat(g1.length * 4)) // escape tabs
.replace(/\n/g, '\\\n'); // escape new lines
}
return undefined;
Expand Down
8 changes: 4 additions & 4 deletions src/test/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ suite('JSON Hover', () => {
}
};
await testComputeInfo(content, schema, { line: 0, character: 0 }).then((result) => {
assert.deepEqual(result.contents, ['a&nbsp;very&nbsp;special&nbsp;object']);
assert.deepEqual(result.contents, ['a very special object']);
});
await testComputeInfo(content, schema, { line: 0, character: 1 }).then((result) => {
assert.deepEqual(result.contents, ['A']);
Expand All @@ -66,7 +66,7 @@ suite('JSON Hover', () => {
assert.deepEqual(result.contents, ['C']);
});
await testComputeInfo(content, schema, { line: 0, character: 37 }).then((result) => {
assert.deepEqual(result.contents, ['For&nbsp;example:\\\n\\\n\\<script\\>\\\n&nbsp;&nbsp;alert\\(1\\)\\\n\\</script\\>\\\n\\\n&nbsp;&nbsp;&nbsp;&nbsp;Test&nbsp;\\[1\\]']);
assert.deepEqual(result.contents, ['For example:\\\n\\\n\\<script\\>\\\n&nbsp;&nbsp;alert\\(1\\)\\\n\\</script\\>\\\n\\\n&nbsp;&nbsp;&nbsp;&nbsp;Test \\[1\\]']);
});
await testComputeInfo(content, schema, { line: 0, character: 7 }).then((result) => {
assert.deepEqual(result.contents, ['A']);
Expand Down Expand Up @@ -96,13 +96,13 @@ suite('JSON Hover', () => {
}]
};
await testComputeInfo(content, schema, { line: 0, character: 0 }).then((result) => {
assert.deepEqual(result.contents, ['a&nbsp;very&nbsp;special&nbsp;object']);
assert.deepEqual(result.contents, ['a very special object']);
});
await testComputeInfo(content, schema, { line: 0, character: 1 }).then((result) => {
assert.deepEqual(result.contents, ['A']);
});
await testComputeInfo(content, schema, { line: 0, character: 10 }).then((result) => {
assert.deepEqual(result.contents, ['B\n\nIt\'s&nbsp;B']);
assert.deepEqual(result.contents, ['B\n\nIt\'s B']);
});
});

Expand Down