next-issue 12.5.9 → 12.5.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/issue-format.mjs +34 -6
- package/package.json +1 -1
package/dist/issue-format.mjs
CHANGED
|
@@ -9,17 +9,45 @@ const OPEN_QUESTIONS = /^(#{1,6})[^\S\r\n]+Open questions[^\S\r\n]*$/im;
|
|
|
9
9
|
export function numbered(items) {
|
|
10
10
|
return items.map((item, index) => `${index + 1}. ${item}`).join('\n');
|
|
11
11
|
}
|
|
12
|
+
const FENCE = /^ {0,3}(`{3,}|~{3,})(.*)$/;
|
|
13
|
+
const HEADING = /^(#{1,6})[^\S\r\n]/;
|
|
14
|
+
function headings(body) {
|
|
15
|
+
const found = [];
|
|
16
|
+
let fence = '';
|
|
17
|
+
let index = 0;
|
|
18
|
+
for (const text of body.split('\n')) {
|
|
19
|
+
const marker = FENCE.exec(text.replace(/\r$/, ''));
|
|
20
|
+
if (fence === '') {
|
|
21
|
+
if (marker !== null && !(marker[1][0] === '`' && marker[2].includes('`'))) {
|
|
22
|
+
fence = marker[1];
|
|
23
|
+
}
|
|
24
|
+
else if (HEADING.test(text)) {
|
|
25
|
+
found.push({ index, length: text.length, text });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else if (marker !== null &&
|
|
29
|
+
marker[1][0] === fence[0] &&
|
|
30
|
+
marker[1].length >= fence.length &&
|
|
31
|
+
marker[2].trim() === '') {
|
|
32
|
+
fence = '';
|
|
33
|
+
}
|
|
34
|
+
index += text.length + 1;
|
|
35
|
+
}
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
12
38
|
export function withOpenQuestions(body, questions) {
|
|
13
39
|
const list = numbered(questions);
|
|
14
|
-
const
|
|
15
|
-
|
|
40
|
+
const all = headings(body);
|
|
41
|
+
const position = all.findIndex((line) => OPEN_QUESTIONS.test(line.text));
|
|
42
|
+
if (position === -1) {
|
|
16
43
|
const kept = body.trimEnd();
|
|
17
44
|
return `${kept === '' ? '' : `${kept}\n\n`}## Open questions\n\n${list}`;
|
|
18
45
|
}
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
46
|
+
const heading = all[position];
|
|
47
|
+
const start = heading.index + heading.length;
|
|
48
|
+
const level = HEADING.exec(heading.text)[1].length;
|
|
49
|
+
const next = all.slice(position + 1).find((line) => HEADING.exec(line.text)[1].length <= level);
|
|
50
|
+
const end = next === undefined ? body.length : next.index;
|
|
23
51
|
const section = body.slice(start, end).trimEnd();
|
|
24
52
|
const rest = body.slice(end);
|
|
25
53
|
return `${body.slice(0, start)}${section}\n\n${list}${rest === '' ? '' : `\n\n${rest}`}`;
|