Skip to content

Commit 2b8b621

Browse files
committed
10% nicer way of wrapping code lines 😄
+ update test data to contain a single-line example
1 parent aed4c9f commit 2b8b621

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

extensions/ql-vscode/src/remote-queries/remote-queries-markdown-generation.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,14 @@ function generateMarkdownForCodeSnippet(
115115
);
116116

117117
// Make sure there are no extra newlines before or after the <code> block:
118-
if (codeLines.length === 1) {
119-
lines.push(`<pre><code class="${language}">${codeLines[0]}</code></pre>`);
120-
} else {
121-
lines.push(
122-
`<pre><code class="${language}">${codeLines[0]}`,
123-
...codeLines.slice(1, -1),
124-
`${codeLines[codeLines.length - 1]}</code></pre>`,
125-
);
126-
}
127-
lines.push('');
118+
const codeLinesWrapped = [...codeLines];
119+
codeLinesWrapped[0] = `<pre><code class="${language}">${codeLinesWrapped[0]}`;
120+
codeLinesWrapped[codeLinesWrapped.length - 1] = `${codeLinesWrapped[codeLinesWrapped.length - 1]}</code></pre>`;
121+
122+
lines.push(
123+
...codeLinesWrapped,
124+
'',
125+
);
128126
return lines;
129127
}
130128

extensions/ql-vscode/test/pure-tests/remote-queries/markdown-generation/data/interpreted-results/problem/analyses-results.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@
137137
},
138138
"severity": "Warning",
139139
"codeSnippet": {
140-
"startLine": 7,
141-
"endLine": 11,
142-
"text": "// ## Parser utilities\n\nconst literal = /^(?:'((?:\\\\.|[^'])*?)'|\"((?:\\\\.|[^\"])*?)\")/\npp.strictDirective = function(start) {\n for (;;) {\n"
140+
"startLine": 9,
141+
"endLine": 9,
142+
"text": "const literal = /^(?:'((?:\\\\.|[^'])*?)'|\"((?:\\\\.|[^\"])*?)\")/"
143143
},
144144
"highlightedRegion": {
145145
"startLine": 9,

extensions/ql-vscode/test/pure-tests/remote-queries/markdown-generation/data/interpreted-results/problem/results-repo2.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ pp.strictDirective = function(start) {
4141

4242
[tools/tests/apps/modules/imports/links/acorn/src/parseutil.js](https://github.com/meteor/meteor/blob/53f3c4442d3542d3d2a012a854472a0d1bef9d12/tools/tests/apps/modules/imports/links/acorn/src/parseutil.js#L9-L9)
4343

44-
<pre><code class="javascript">// ## Parser utilities
45-
46-
const literal = /^(?:'((?:\\.|[^'])*?)'|"(<strong>(?:\\.|[^"])*?</strong>)")/
47-
pp.strictDirective = function(start) {
48-
for (;;) {
49-
</code></pre>
44+
<pre><code class="javascript">const literal = /^(?:'((?:\\.|[^'])*?)'|"(<strong>(?:\\.|[^"])*?</strong>)")/</code></pre>
5045

5146
*This part of the regular expression may cause exponential backtracking on strings starting with '"' and containing many repetitions of '\!'.*
5247

0 commit comments

Comments
 (0)