markshell 1.6.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 +15 -6
- package/package.json +15 -8
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
|
|
|
@@ -232,7 +241,7 @@ const _highlightedCodeBlock = (content) => {
|
|
|
232
241
|
|
|
233
242
|
newContent.forEach((element) => {
|
|
234
243
|
|
|
235
|
-
let langRegex = new RegExp(/(\`\`\`)(.*?)(\n)/igs);
|
|
244
|
+
let langRegex = new RegExp(/(\`\`\`)(.*?)(\r?\n)/igs);
|
|
236
245
|
let langIdentifiere = element.match(langRegex);
|
|
237
246
|
|
|
238
247
|
if (langIdentifiere.length === 1) {
|
|
@@ -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
|
|
|
@@ -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
|
}
|
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,15 +42,18 @@
|
|
|
38
42
|
"author": "Stefan Bauer",
|
|
39
43
|
"license": "MIT",
|
|
40
44
|
"dependencies": {
|
|
41
|
-
"@types/prismjs": "1.
|
|
45
|
+
"@types/prismjs": "1.26",
|
|
42
46
|
"chalk": "^4.1.2",
|
|
43
|
-
"jsdom": "^
|
|
44
|
-
"prismjs": "^1.
|
|
45
|
-
"wrap-ansi": "^
|
|
47
|
+
"jsdom": "^27.3.0",
|
|
48
|
+
"prismjs": "^1.30.0",
|
|
49
|
+
"wrap-ansi": "^9.0.2"
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^10.
|
|
49
|
-
"@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"
|
|
50
57
|
},
|
|
51
58
|
"repository": {
|
|
52
59
|
"type": "git",
|