spec-up-t 1.0.59 → 1.0.60
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/package.json +1 -1
- package/src/fix-markdown-files.js +30 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spec-up-t",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.60",
|
|
4
4
|
"description": "Technical specification drafting tool that generates rich specification documents from markdown. Forked from https://github.com/decentralized-identity/spec-up by Daniel Buchner (https://github.com/csuwildcat)",
|
|
5
5
|
"main": "./index",
|
|
6
6
|
"repository": {
|
|
@@ -24,47 +24,54 @@ function processMarkdownFiles(directory) {
|
|
|
24
24
|
let lines = data.split('\n');
|
|
25
25
|
let modified = false;
|
|
26
26
|
|
|
27
|
-
//
|
|
27
|
+
// Handle specific functionality for `[[def:` lines
|
|
28
28
|
for (let i = 0; i < lines.length; i++) {
|
|
29
|
-
// Check if the line starts with [[def:
|
|
30
29
|
if (lines[i].startsWith('[[def:')) {
|
|
31
|
-
//
|
|
30
|
+
// Ensure a blank line immediately follows `[[def:` lines
|
|
32
31
|
if (i + 1 < lines.length && lines[i + 1].trim() !== '') {
|
|
33
|
-
// Insert
|
|
34
|
-
lines.splice(i + 1, 0, '');
|
|
32
|
+
lines.splice(i + 1, 0, ''); // Insert blank line
|
|
35
33
|
modified = true;
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
// Ensure there is
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
lines.splice(i + 1, 0, '');
|
|
44
|
-
modified = true;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
38
|
+
// Ensure there is exactly one blank line between paragraphs
|
|
39
|
+
let newLines = [];
|
|
40
|
+
let previousLineWasEmpty = false;
|
|
47
41
|
|
|
48
|
-
// Prepend `~ ` to lines that do not start with `[[def:` and are not blank lines, and do not already start with `~ `
|
|
49
42
|
for (let i = 0; i < lines.length; i++) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
43
|
+
const isCurrentLineEmpty = lines[i].trim() === '';
|
|
44
|
+
|
|
45
|
+
if (!isCurrentLineEmpty) {
|
|
46
|
+
newLines.push(lines[i]); // Add non-empty lines
|
|
47
|
+
previousLineWasEmpty = false;
|
|
48
|
+
} else if (!previousLineWasEmpty) {
|
|
49
|
+
newLines.push(''); // Add exactly one blank line
|
|
50
|
+
previousLineWasEmpty = true;
|
|
51
|
+
} else {
|
|
52
|
+
modified = true; // Skip additional blank lines
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
// Prepend `~ ` to lines that do not start with `[[def:` and are not blank, and do not already start with `~ `
|
|
57
|
+
for (let i = 0; i < newLines.length; i++) {
|
|
58
|
+
if (!newLines[i].startsWith('[[def:') && newLines[i].trim() !== '' && !newLines[i].startsWith('~ ')) {
|
|
59
|
+
newLines[i] = `~ ${newLines[i]}`;
|
|
60
|
+
modified = true;
|
|
61
|
+
}
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
// Ensure there is exactly one blank line at the end of the file
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
data = trimmedData;
|
|
65
|
+
if (newLines[newLines.length - 1] !== '') {
|
|
66
|
+
newLines.push('');
|
|
65
67
|
modified = true;
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
// Join the lines back into a single string
|
|
71
|
+
if (modified) {
|
|
72
|
+
data = newLines.join('\n');
|
|
73
|
+
}
|
|
74
|
+
|
|
68
75
|
// Write the modified content back to the file synchronously if there were any changes
|
|
69
76
|
if (modified) {
|
|
70
77
|
fs.writeFileSync(itemPath, data, 'utf8');
|
|
@@ -86,4 +93,4 @@ function processMarkdownFiles(directory) {
|
|
|
86
93
|
|
|
87
94
|
module.exports = {
|
|
88
95
|
processMarkdownFiles
|
|
89
|
-
};
|
|
96
|
+
};
|