markshell 1.5.0 → 1.7.0
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/lib/admonitions/index.js +18 -15
- package/lib/index.js +25 -16
- package/package.json +15 -9
package/lib/admonitions/index.js
CHANGED
|
@@ -95,21 +95,23 @@ const offset = () => {
|
|
|
95
95
|
|
|
96
96
|
let offsetLength;
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
// console.log(typeof this.styles.indent.afterIndent, this.styles.indent.afterIndent);
|
|
100
|
-
// console.log(typeof this.styles.indent.titleIndent, this.styles.indent.titleIndent);
|
|
98
|
+
const currentStyles = styles || formatBlock;
|
|
101
99
|
|
|
102
|
-
|
|
100
|
+
// console.log(typeof currentStyles.indent.beforeIndent, currentStyles.indent.beforeIndent);
|
|
101
|
+
// console.log(typeof currentStyles.indent.afterIndent, currentStyles.indent.afterIndent);
|
|
102
|
+
// console.log(typeof currentStyles.indent.titleIndent, currentStyles.indent.titleIndent);
|
|
103
|
+
|
|
104
|
+
offsetLength = (currentStyles.indent.beforeIndent) + 2 + currentStyles.indent.afterIndent + currentStyles.indent.titleIndent;
|
|
103
105
|
|
|
104
106
|
// console.log(process.stdout.columns < offsetLength, offsetLength);
|
|
105
107
|
|
|
106
108
|
if (process.stdout.columns < offsetLength) {
|
|
107
109
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
currentStyles.indent.beforeIndent = defBeforeIndent;
|
|
111
|
+
currentStyles.indent.afterIndent = defAfterIndent;
|
|
112
|
+
currentStyles.indent.titleIndent = defTitleIndent;
|
|
111
113
|
|
|
112
|
-
offsetLength =
|
|
114
|
+
offsetLength = currentStyles.indent.beforeIndent + 2 + currentStyles.indent.afterIndent + currentStyles.indent.titleIndent;
|
|
113
115
|
|
|
114
116
|
}
|
|
115
117
|
|
|
@@ -119,18 +121,19 @@ const offset = () => {
|
|
|
119
121
|
|
|
120
122
|
const formatOutput = (title, style) => {
|
|
121
123
|
|
|
124
|
+
const currentStyles = styles || formatBlock;
|
|
122
125
|
let indentOffset = offset();
|
|
123
126
|
let outTitle = " " + title + " "
|
|
124
127
|
|
|
125
|
-
if (
|
|
128
|
+
if (currentStyles.indent.beforeIndent === 0 && currentStyles.indent.titleIndent === 0) {
|
|
126
129
|
outTitle = title + " ";
|
|
127
130
|
}
|
|
128
131
|
|
|
129
|
-
return " ".repeat(
|
|
130
|
-
style(" ".repeat(
|
|
132
|
+
return " ".repeat(currentStyles.indent.beforeIndent) +
|
|
133
|
+
style(" ".repeat(currentStyles.indent.titleIndent)) +
|
|
131
134
|
chalk.bgHex('#000').white(outTitle) +
|
|
132
135
|
style(" ".repeat(process.stdout.columns - indentOffset - title.length)) +
|
|
133
|
-
chalk.bgHex('#000')(" ".repeat(
|
|
136
|
+
chalk.bgHex('#000')(" ".repeat(currentStyles.indent.afterIndent)) +
|
|
134
137
|
EOL;
|
|
135
138
|
|
|
136
139
|
}
|
|
@@ -226,13 +229,13 @@ const _getBlocks = (content, beforeIndent, afterIndent, titleIndent, useSafeStyl
|
|
|
226
229
|
*/
|
|
227
230
|
const _getStyles = () => {
|
|
228
231
|
|
|
229
|
-
if (
|
|
232
|
+
if (styles === null || styles === undefined) {
|
|
230
233
|
|
|
231
234
|
return formatBlock;
|
|
232
235
|
|
|
233
236
|
} else {
|
|
234
237
|
|
|
235
|
-
return
|
|
238
|
+
return styles;
|
|
236
239
|
|
|
237
240
|
}
|
|
238
241
|
|
|
@@ -240,7 +243,7 @@ const _getStyles = () => {
|
|
|
240
243
|
|
|
241
244
|
const _setStyles = (styleBlock) => {
|
|
242
245
|
|
|
243
|
-
|
|
246
|
+
styles = styleBlock;
|
|
244
247
|
|
|
245
248
|
}
|
|
246
249
|
|
package/lib/index.js
CHANGED
|
@@ -7,6 +7,15 @@ const syntaxHighlighter = require('./syntaxhighlighter');
|
|
|
7
7
|
const admonitions = require('./admonitions');
|
|
8
8
|
const EOL = require('os').EOL;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Escape special regex characters to prevent ReDoS attacks
|
|
12
|
+
* @param {string} str - String to escape
|
|
13
|
+
* @returns {string} - Escaped string safe for use in RegExp
|
|
14
|
+
*/
|
|
15
|
+
const escapeRegex = (str) => {
|
|
16
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
17
|
+
};
|
|
18
|
+
|
|
10
19
|
const theme = require('./syntaxhighlighter/themes/okaidia.theme');
|
|
11
20
|
let _theme;
|
|
12
21
|
|
|
@@ -96,7 +105,7 @@ const _highlightText = (content, regexMatch, colorFunction, removeChars = null)
|
|
|
96
105
|
|
|
97
106
|
if (removeChars === null) {
|
|
98
107
|
|
|
99
|
-
let findAllRegex = new RegExp(match[0], "ig");
|
|
108
|
+
let findAllRegex = new RegExp(escapeRegex(match[0]), "ig");
|
|
100
109
|
|
|
101
110
|
newContent = newContent.replace(findAllRegex, colorFunction(match[1]));
|
|
102
111
|
|
|
@@ -191,13 +200,13 @@ const _codeBlock = (content) => {
|
|
|
191
200
|
|
|
192
201
|
if (langIdentifiere.length === 1) {
|
|
193
202
|
|
|
194
|
-
let lang = langIdentifiere[0].replace(
|
|
203
|
+
let lang = langIdentifiere[0].replace(/```/, '').replace(/\n/, '');
|
|
195
204
|
|
|
196
205
|
//Replace language
|
|
197
|
-
let source = element.replace(`\`\`\`${lang}\
|
|
206
|
+
let source = element.replace(`\`\`\`${lang}\n`, '');
|
|
198
207
|
|
|
199
208
|
//Replace ```
|
|
200
|
-
source = source.replace(
|
|
209
|
+
source = source.replace('```', '');
|
|
201
210
|
|
|
202
211
|
try {
|
|
203
212
|
let hlSource = syntaxHighlighter.highlight(source, lang.trim(), this._theme.sourceCodeTheme);
|
|
@@ -237,7 +246,7 @@ const _highlightedCodeBlock = (content) => {
|
|
|
237
246
|
|
|
238
247
|
if (langIdentifiere.length === 1) {
|
|
239
248
|
|
|
240
|
-
let lang = langIdentifiere[0].replace(/\`\`\`/, '').replace(/\
|
|
249
|
+
let lang = langIdentifiere[0].replace(/\`\`\`/, '').replace(/\n/, '').trim();
|
|
241
250
|
|
|
242
251
|
//Replace language
|
|
243
252
|
let source = element.replace(`\`\`\`${lang}\n`, '');
|
|
@@ -274,7 +283,7 @@ const _highlightedCodeBlock = (content) => {
|
|
|
274
283
|
*/
|
|
275
284
|
const _addBlockQuote = (content, indentLeft = 3, indentRight = 3) => {
|
|
276
285
|
|
|
277
|
-
let newContent = content.split(
|
|
286
|
+
let newContent = content.split('\n');
|
|
278
287
|
var columns = process.stdout.columns - 4;
|
|
279
288
|
let maxWordLength = columns - indentLeft - indentRight;
|
|
280
289
|
|
|
@@ -299,7 +308,7 @@ const _addBlockQuote = (content, indentLeft = 3, indentRight = 3) => {
|
|
|
299
308
|
|
|
300
309
|
curLine = calcLine;
|
|
301
310
|
|
|
302
|
-
newLine +=
|
|
311
|
+
newLine += '\n' + element;
|
|
303
312
|
|
|
304
313
|
} else {
|
|
305
314
|
|
|
@@ -322,7 +331,7 @@ const _addBlockQuote = (content, indentLeft = 3, indentRight = 3) => {
|
|
|
322
331
|
newContent[index] += " ".repeat(indentLeft) +
|
|
323
332
|
this._theme.blockQuote(
|
|
324
333
|
line.trim() + fillUpString
|
|
325
|
-
) +
|
|
334
|
+
) + '\n';
|
|
326
335
|
|
|
327
336
|
})
|
|
328
337
|
|
|
@@ -330,7 +339,7 @@ const _addBlockQuote = (content, indentLeft = 3, indentRight = 3) => {
|
|
|
330
339
|
|
|
331
340
|
})
|
|
332
341
|
|
|
333
|
-
return newContent.join(
|
|
342
|
+
return newContent.join('\n');
|
|
334
343
|
|
|
335
344
|
}
|
|
336
345
|
|
|
@@ -379,7 +388,7 @@ const _includeExternals = (content, externalFound, baseDir, regexDelimiter) => {
|
|
|
379
388
|
|
|
380
389
|
for (let i = 0; i < keys.length; i++) {
|
|
381
390
|
|
|
382
|
-
var regExp = new RegExp(keys[i], 'ig');
|
|
391
|
+
var regExp = new RegExp(escapeRegex(keys[i]), 'ig');
|
|
383
392
|
newContent = newContent.replace(regExp, replacements[keys[i]]);
|
|
384
393
|
|
|
385
394
|
}
|
|
@@ -452,7 +461,7 @@ const _addBold = (content) => {
|
|
|
452
461
|
*/
|
|
453
462
|
const _addItalic = (content) => {
|
|
454
463
|
|
|
455
|
-
let regExp = new RegExp(
|
|
464
|
+
let regExp = new RegExp(/(?<!\w)_([^_\n]+?)_(?!\w)/g);
|
|
456
465
|
|
|
457
466
|
return _highlightText(content, regExp, this._theme.italic);
|
|
458
467
|
|
|
@@ -485,7 +494,7 @@ const _addCode = (content) => {
|
|
|
485
494
|
const _addInlineCode = (content) => {
|
|
486
495
|
|
|
487
496
|
// return _highlightText(content, /\`/ig, this._theme.inlineCode);
|
|
488
|
-
return _highlightText(content, /`(
|
|
497
|
+
return _highlightText(content, /`([^`]*)`/g, this._theme.inlineCode);
|
|
489
498
|
|
|
490
499
|
}
|
|
491
500
|
|
|
@@ -597,7 +606,7 @@ const _addDefinitionList = (content, leftIndent = 3) => {
|
|
|
597
606
|
|
|
598
607
|
});
|
|
599
608
|
|
|
600
|
-
contentBlocks[index] = formattedLines.join(
|
|
609
|
+
contentBlocks[index] = formattedLines.join('\n');
|
|
601
610
|
|
|
602
611
|
}
|
|
603
612
|
|
|
@@ -605,7 +614,7 @@ const _addDefinitionList = (content, leftIndent = 3) => {
|
|
|
605
614
|
|
|
606
615
|
// console.log(contentBlocks);
|
|
607
616
|
|
|
608
|
-
return contentBlocks.join(
|
|
617
|
+
return contentBlocks.join('\n');
|
|
609
618
|
|
|
610
619
|
}
|
|
611
620
|
|
|
@@ -651,7 +660,7 @@ const _toRawContent = (filepath) => {
|
|
|
651
660
|
}
|
|
652
661
|
|
|
653
662
|
try {
|
|
654
|
-
content = _removeImages(content,
|
|
663
|
+
content = _removeImages(content, /!\[([^\]]*)\]\(([^)"'\s]+)(?:\s+["']([^"']*)["'])?\)/g);
|
|
655
664
|
} catch (e) {
|
|
656
665
|
throw `Error in remove images: ${e}`;
|
|
657
666
|
}
|
|
@@ -739,7 +748,7 @@ const _toRawContent = (filepath) => {
|
|
|
739
748
|
|
|
740
749
|
}
|
|
741
750
|
|
|
742
|
-
return content;
|
|
751
|
+
return content.replace(/\n/ig, EOL);
|
|
743
752
|
|
|
744
753
|
}
|
|
745
754
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "markshell",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "markshell allows you to output any markdown file formatted and style to the console",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown",
|
|
@@ -22,7 +22,11 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/stfbauer/markshell#readme",
|
|
24
24
|
"scripts": {
|
|
25
|
-
"test": "
|
|
25
|
+
"test": "vitest",
|
|
26
|
+
"test:ui": "vitest --ui",
|
|
27
|
+
"test:run": "vitest run",
|
|
28
|
+
"test:coverage": "vitest --coverage",
|
|
29
|
+
"test:old": "node test/index.js",
|
|
26
30
|
"testRun": "node ./lib/index.js",
|
|
27
31
|
"update-types": "./tools/typings.sh"
|
|
28
32
|
},
|
|
@@ -38,16 +42,18 @@
|
|
|
38
42
|
"author": "Stefan Bauer",
|
|
39
43
|
"license": "MIT",
|
|
40
44
|
"dependencies": {
|
|
41
|
-
"@types/
|
|
42
|
-
"@types/prismjs": "1.16",
|
|
45
|
+
"@types/prismjs": "1.26",
|
|
43
46
|
"chalk": "^4.1.2",
|
|
44
|
-
"jsdom": "^
|
|
45
|
-
"prismjs": "^1.
|
|
46
|
-
"wrap-ansi": "^
|
|
47
|
+
"jsdom": "^27.3.0",
|
|
48
|
+
"prismjs": "^1.30.0",
|
|
49
|
+
"wrap-ansi": "^9.0.2"
|
|
47
50
|
},
|
|
48
51
|
"devDependencies": {
|
|
49
|
-
"@types/node": "^10.
|
|
50
|
-
"@types/prismjs": "^1.16.1"
|
|
52
|
+
"@types/node": "^24.10.2",
|
|
53
|
+
"@types/prismjs": "^1.16.1",
|
|
54
|
+
"@vitest/coverage-v8": "^1.6.1",
|
|
55
|
+
"@vitest/ui": "^1.0.0",
|
|
56
|
+
"vitest": "^1.0.0"
|
|
51
57
|
},
|
|
52
58
|
"repository": {
|
|
53
59
|
"type": "git",
|