10% nicer way of wrapping code lines 😄

+ update test data to contain a single-line example
This commit is contained in:
shati-patel
2022-04-25 11:17:52 +01:00
committed by Shati Patel
parent aed4c9fc58
commit 2b8b621298
3 changed files with 12 additions and 19 deletions

View File

@@ -115,16 +115,14 @@ function generateMarkdownForCodeSnippet(
);
// Make sure there are no extra newlines before or after the <code> block:
if (codeLines.length === 1) {
lines.push(`<pre><code class="${language}">${codeLines[0]}</code></pre>`);
} else {
lines.push(
`<pre><code class="${language}">${codeLines[0]}`,
...codeLines.slice(1, -1),
`${codeLines[codeLines.length - 1]}</code></pre>`,
);
}
lines.push('');
const codeLinesWrapped = [...codeLines];
codeLinesWrapped[0] = `<pre><code class="${language}">${codeLinesWrapped[0]}`;
codeLinesWrapped[codeLinesWrapped.length - 1] = `${codeLinesWrapped[codeLinesWrapped.length - 1]}</code></pre>`;
lines.push(
...codeLinesWrapped,
'',
);
return lines;
}

View File

@@ -137,9 +137,9 @@
},
"severity": "Warning",
"codeSnippet": {
"startLine": 7,
"endLine": 11,
"text": "// ## Parser utilities\n\nconst literal = /^(?:'((?:\\\\.|[^'])*?)'|\"((?:\\\\.|[^\"])*?)\")/\npp.strictDirective = function(start) {\n for (;;) {\n"
"startLine": 9,
"endLine": 9,
"text": "const literal = /^(?:'((?:\\\\.|[^'])*?)'|\"((?:\\\\.|[^\"])*?)\")/"
},
"highlightedRegion": {
"startLine": 9,

View File

@@ -41,12 +41,7 @@ pp.strictDirective = function(start) {
[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)
<pre><code class="javascript">// ## Parser utilities
const literal = /^(?:'((?:\\.|[^'])*?)'|"(<strong>(?:\\.|[^"])*?</strong>)")/
pp.strictDirective = function(start) {
for (;;) {
</code></pre>
<pre><code class="javascript">const literal = /^(?:'((?:\\.|[^'])*?)'|"(<strong>(?:\\.|[^"])*?</strong>)")/</code></pre>
*This part of the regular expression may cause exponential backtracking on strings starting with '"' and containing many repetitions of '\!'.*