pantsdown 2.1.4 → 2.1.6
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 +15 -15
- package/src/renderer.ts +2 -2
- package/src/tokenizer.ts +1 -3
- package/src/utils.ts +7 -7
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "pantsdown",
|
|
3
3
|
"author": "wallpants",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "2.1.
|
|
5
|
+
"version": "2.1.6",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"description": "Markdown to 'GitHub HTML' parser",
|
|
8
8
|
"repository": {
|
|
@@ -51,21 +51,21 @@
|
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"github-slugger": "^2.0.0",
|
|
54
|
-
"highlight.js": "^11.
|
|
54
|
+
"highlight.js": "^11.10.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@commitlint/config-conventional": "^19.
|
|
58
|
-
"@commitlint/cz-commitlint": "^19.
|
|
59
|
-
"@happy-dom/global-registrator": "^
|
|
60
|
-
"@types/bun": "^1.1.
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
62
|
-
"@typescript-eslint/parser": "^
|
|
63
|
-
"commitizen": "^4.3.
|
|
64
|
-
"commitlint": "^19.
|
|
65
|
-
"eslint": "^8.57.
|
|
66
|
-
"prettier": "^3.
|
|
67
|
-
"prettier-plugin-organize-imports": "^
|
|
68
|
-
"semantic-release": "^
|
|
69
|
-
"typescript": "5.
|
|
57
|
+
"@commitlint/config-conventional": "^19.5.0",
|
|
58
|
+
"@commitlint/cz-commitlint": "^19.5.0",
|
|
59
|
+
"@happy-dom/global-registrator": "^15.7.4",
|
|
60
|
+
"@types/bun": "^1.1.12",
|
|
61
|
+
"@typescript-eslint/eslint-plugin": "^8.12.2",
|
|
62
|
+
"@typescript-eslint/parser": "^8.12.2",
|
|
63
|
+
"commitizen": "^4.3.1",
|
|
64
|
+
"commitlint": "^19.5.0",
|
|
65
|
+
"eslint": "^8.57.1",
|
|
66
|
+
"prettier": "^3.3.3",
|
|
67
|
+
"prettier-plugin-organize-imports": "^4.1.0",
|
|
68
|
+
"semantic-release": "^24.2.0",
|
|
69
|
+
"typescript": "5.6.3"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/src/renderer.ts
CHANGED
|
@@ -24,7 +24,7 @@ export class Renderer {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
code(code: string, infostring: string | undefined, sourceMap: SourceMap): string {
|
|
27
|
-
const lang = (infostring ?? "")
|
|
27
|
+
const lang = /^\S*/.exec(infostring ?? "")?.[0];
|
|
28
28
|
code = code.replace(/\n$/, "") + "\n";
|
|
29
29
|
|
|
30
30
|
const attrs: HTMLAttrs = [];
|
|
@@ -52,7 +52,7 @@ export class Renderer {
|
|
|
52
52
|
return `<blockquote>\n${quote}</blockquote>\n`;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
html(html: string, _block: boolean, sourceMap?: SourceMap
|
|
55
|
+
html(html: string, _block: boolean, sourceMap?: SourceMap): string {
|
|
56
56
|
const result = fixHtmlLocalImageHref(
|
|
57
57
|
html,
|
|
58
58
|
this.pantsdown.config.renderer.relativeImageUrlPrefix,
|
package/src/tokenizer.ts
CHANGED
|
@@ -709,7 +709,7 @@ export class Tokenizer {
|
|
|
709
709
|
if (!match) return;
|
|
710
710
|
|
|
711
711
|
// _ can't be between two alphanumerics. \p{L}\p{N} includes non-english alphabet/numbers as well
|
|
712
|
-
if (match[3] &&
|
|
712
|
+
if (match[3] && /[\p{L}\p{N}]/u.exec(prevChar)) return;
|
|
713
713
|
|
|
714
714
|
// eslint-disable-next-line
|
|
715
715
|
const nextChar = match[1] || match[2] || "";
|
|
@@ -738,12 +738,10 @@ export class Tokenizer {
|
|
|
738
738
|
|
|
739
739
|
rLength = [...rDelim].length;
|
|
740
740
|
|
|
741
|
-
// eslint-disable-next-line
|
|
742
741
|
if (match[3] || match[4]) {
|
|
743
742
|
// found another Left Delim
|
|
744
743
|
delimTotal += rLength;
|
|
745
744
|
continue;
|
|
746
|
-
// eslint-disable-next-line
|
|
747
745
|
} else if (match[5] || match[6]) {
|
|
748
746
|
// either Left or Right Delim
|
|
749
747
|
if (lLength % 3 && !((lLength + rLength) % 3)) {
|
package/src/utils.ts
CHANGED
|
@@ -57,11 +57,11 @@ export function injectHtmlAttributes(html: string, attrs: HTMLAttrs, sourceMap?:
|
|
|
57
57
|
if (!attrs.length) return html;
|
|
58
58
|
|
|
59
59
|
const closingBracket = /[a-zA-Z0-9\/"]>/;
|
|
60
|
-
const match =
|
|
60
|
+
const match = closingBracket.exec(html);
|
|
61
61
|
if (match) {
|
|
62
62
|
let htmlAttrs = "";
|
|
63
63
|
attrs.forEach((atrr) => (htmlAttrs += ` ${atrr[0]}="${atrr[1]}"`));
|
|
64
|
-
const sliceIdx = match.index
|
|
64
|
+
const sliceIdx = match.index + (match[0] === "/>" ? -1 : 1);
|
|
65
65
|
return html.slice(0, sliceIdx) + htmlAttrs + html.slice(sliceIdx);
|
|
66
66
|
}
|
|
67
67
|
return html;
|
|
@@ -73,7 +73,7 @@ export function fixHtmlLocalImageHref(
|
|
|
73
73
|
): string {
|
|
74
74
|
return relativeImageUrlPrefix
|
|
75
75
|
? html.replace(
|
|
76
|
-
/<img\s+([^>]*?)src\s*=\s*(["'])([
|
|
76
|
+
/<img\s+([^>]*?)src\s*=\s*(["'])([^>'"]+?)\2([^>]*)>/gm,
|
|
77
77
|
(_m, g1, _g2, g3: string, g4) => {
|
|
78
78
|
const href = fixLocalImageHref(g3, relativeImageUrlPrefix);
|
|
79
79
|
return `<img ${g1}src="${href}"${g4}>`;
|
|
@@ -106,7 +106,7 @@ export function fixLocalImageHref(
|
|
|
106
106
|
try {
|
|
107
107
|
const temp = new URL(href, dummyBaseUrl).href;
|
|
108
108
|
return temp.slice(dummyUrlLength);
|
|
109
|
-
} catch (
|
|
109
|
+
} catch (_) {
|
|
110
110
|
return href;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
@@ -114,7 +114,7 @@ export function fixLocalImageHref(
|
|
|
114
114
|
export function cleanUrl(href: string) {
|
|
115
115
|
try {
|
|
116
116
|
href = encodeURI(href).replace(/%25/g, "%");
|
|
117
|
-
} catch (
|
|
117
|
+
} catch (_) {
|
|
118
118
|
return null;
|
|
119
119
|
}
|
|
120
120
|
return href;
|
|
@@ -249,7 +249,7 @@ export function outputLink(
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
export function indentCodeCompensation(raw: string, text: string) {
|
|
252
|
-
const matchIndentToCode =
|
|
252
|
+
const matchIndentToCode = /^(\s+)(?:```)/.exec(raw);
|
|
253
253
|
|
|
254
254
|
if (matchIndentToCode === null) {
|
|
255
255
|
return text;
|
|
@@ -260,7 +260,7 @@ export function indentCodeCompensation(raw: string, text: string) {
|
|
|
260
260
|
return text
|
|
261
261
|
.split("\n")
|
|
262
262
|
.map((node) => {
|
|
263
|
-
const matchIndentInNode =
|
|
263
|
+
const matchIndentInNode = /^\s+/.exec(node);
|
|
264
264
|
if (matchIndentInNode === null) {
|
|
265
265
|
return node;
|
|
266
266
|
}
|