pantsdown 2.0.1 → 2.0.2
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/renderer.ts +1 -1
- package/src/tokenizer.ts +14 -15
package/package.json
CHANGED
package/src/renderer.ts
CHANGED
|
@@ -42,7 +42,7 @@ export class Renderer {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
alert(body: string, token: Tokens["Alert"]): string {
|
|
45
|
-
const result = `<div
|
|
45
|
+
const result = `<div><span>${token.icon + token.variant}</span>${body}</div>\n`;
|
|
46
46
|
return injectHtmlAttributes(result, [
|
|
47
47
|
["class", `markdown-alert markdown-alert-${token.variant.toLowerCase()}`],
|
|
48
48
|
]);
|
package/src/tokenizer.ts
CHANGED
|
@@ -105,7 +105,7 @@ export class Tokenizer {
|
|
|
105
105
|
const cap = block.blockquote.exec(src);
|
|
106
106
|
if (!cap) return undefined;
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
let text = rtrim(cap[0].replace(/^ *>[ \t]?/gm, ""), "\n");
|
|
109
109
|
const top = this.lexer.state.top;
|
|
110
110
|
this.lexer.state.top = true;
|
|
111
111
|
const tokens = this.lexer.blockTokens(text, []);
|
|
@@ -119,20 +119,21 @@ export class Tokenizer {
|
|
|
119
119
|
text,
|
|
120
120
|
};
|
|
121
121
|
|
|
122
|
-
const
|
|
122
|
+
const matchedAlertVariant = ALERTS.find(({ regex }) => regex.test(blockquoteToken.text));
|
|
123
123
|
|
|
124
|
-
if (
|
|
125
|
-
const { variant, icon, regex } =
|
|
124
|
+
if (matchedAlertVariant) {
|
|
125
|
+
const { variant, icon, regex } = matchedAlertVariant;
|
|
126
126
|
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
127
|
+
const firstToken = blockquoteToken.tokens[0] as Tokens["Paragraph"];
|
|
128
|
+
|
|
129
|
+
text = firstToken.raw.replace(regex, "");
|
|
130
|
+
|
|
131
|
+
// since we're modifying firstToken.raw by removing the first line,
|
|
132
|
+
// resulting tokens also change and thus also the sourceMap that
|
|
133
|
+
// was generated for the blockquote
|
|
134
|
+
if (firstToken.sourceMap?.[0]) firstToken.sourceMap[0]++;
|
|
135
|
+
|
|
136
|
+
firstToken.tokens = this.lexer.inlineTokens(text, []);
|
|
136
137
|
|
|
137
138
|
const alertToken: Tokens["Alert"] = {
|
|
138
139
|
...blockquoteToken,
|
|
@@ -141,8 +142,6 @@ export class Tokenizer {
|
|
|
141
142
|
icon,
|
|
142
143
|
};
|
|
143
144
|
|
|
144
|
-
alertToken.tokens.splice(0, 1, firstLine);
|
|
145
|
-
|
|
146
145
|
return alertToken;
|
|
147
146
|
}
|
|
148
147
|
|