@changerawr/markdown 1.1.3 → 1.1.5
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/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +47 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -11
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/react/index.js +47 -11
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +47 -11
- package/dist/react/index.mjs.map +1 -1
- package/dist/standalone.browser.js +50 -16
- package/dist/standalone.d.mts +2 -1
- package/dist/standalone.d.ts +2 -1
- package/dist/standalone.js +47 -11
- package/dist/standalone.js.map +1 -1
- package/dist/standalone.mjs +47 -11
- package/dist/standalone.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,8 @@ interface MarkdownToken {
|
|
|
2
2
|
type: string;
|
|
3
3
|
content: string;
|
|
4
4
|
raw: string;
|
|
5
|
-
attributes?: Record<string, string>;
|
|
5
|
+
attributes?: Record<string, string | number | boolean | Function | any>;
|
|
6
|
+
children?: MarkdownToken[];
|
|
6
7
|
}
|
|
7
8
|
interface ParseRule {
|
|
8
9
|
name: string;
|
|
@@ -384,6 +385,7 @@ declare class MarkdownParser {
|
|
|
384
385
|
private preprocessMarkdown;
|
|
385
386
|
private validateMarkdown;
|
|
386
387
|
private postProcessTokens;
|
|
388
|
+
private recursivelyParseBlockContent;
|
|
387
389
|
}
|
|
388
390
|
|
|
389
391
|
declare class MarkdownRenderer {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ interface MarkdownToken {
|
|
|
2
2
|
type: string;
|
|
3
3
|
content: string;
|
|
4
4
|
raw: string;
|
|
5
|
-
attributes?: Record<string, string>;
|
|
5
|
+
attributes?: Record<string, string | number | boolean | Function | any>;
|
|
6
|
+
children?: MarkdownToken[];
|
|
6
7
|
}
|
|
7
8
|
interface ParseRule {
|
|
8
9
|
name: string;
|
|
@@ -384,6 +385,7 @@ declare class MarkdownParser {
|
|
|
384
385
|
private preprocessMarkdown;
|
|
385
386
|
private validateMarkdown;
|
|
386
387
|
private postProcessTokens;
|
|
388
|
+
private recursivelyParseBlockContent;
|
|
387
389
|
}
|
|
388
390
|
|
|
389
391
|
declare class MarkdownRenderer {
|
package/dist/index.js
CHANGED
|
@@ -295,7 +295,8 @@ var MarkdownParser = class {
|
|
|
295
295
|
}
|
|
296
296
|
i = j;
|
|
297
297
|
} else if (token) {
|
|
298
|
-
|
|
298
|
+
const processedToken = this.recursivelyParseBlockContent(token);
|
|
299
|
+
processed.push(processedToken);
|
|
299
300
|
i++;
|
|
300
301
|
} else {
|
|
301
302
|
i++;
|
|
@@ -303,6 +304,17 @@ var MarkdownParser = class {
|
|
|
303
304
|
}
|
|
304
305
|
return processed;
|
|
305
306
|
}
|
|
307
|
+
recursivelyParseBlockContent(token) {
|
|
308
|
+
const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
|
|
309
|
+
if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
|
|
310
|
+
const children = this.parse(token.content);
|
|
311
|
+
return {
|
|
312
|
+
...token,
|
|
313
|
+
children
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return token;
|
|
317
|
+
}
|
|
306
318
|
};
|
|
307
319
|
|
|
308
320
|
// src/utils.ts
|
|
@@ -648,7 +660,19 @@ var MarkdownRenderer = class {
|
|
|
648
660
|
const rule = this.rules.get(token.type);
|
|
649
661
|
if (rule) {
|
|
650
662
|
try {
|
|
651
|
-
|
|
663
|
+
let tokenToRender = token;
|
|
664
|
+
if (token.children && token.children.length > 0) {
|
|
665
|
+
const renderedChildren = this.render(token.children);
|
|
666
|
+
tokenToRender = {
|
|
667
|
+
...token,
|
|
668
|
+
attributes: {
|
|
669
|
+
...token.attributes,
|
|
670
|
+
renderedChildren
|
|
671
|
+
// Extensions can use this instead of re-parsing
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
return rule.render(tokenToRender);
|
|
652
676
|
} catch (error) {
|
|
653
677
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
654
678
|
this.warnings.push(`Render error for ${token.type}: ${errorMessage}`);
|
|
@@ -717,8 +741,10 @@ var BlockquoteExtension = {
|
|
|
717
741
|
{
|
|
718
742
|
type: "blockquote",
|
|
719
743
|
render: (token) => {
|
|
720
|
-
const content = escapeHtml(token.content);
|
|
721
744
|
const format = token.attributes?.format || "html";
|
|
745
|
+
const renderedChildren = token.attributes?.renderedChildren;
|
|
746
|
+
const renderMarkdown2 = token.attributes?.renderMarkdown;
|
|
747
|
+
const content = renderedChildren || (renderMarkdown2 ? renderMarkdown2(token.content) : escapeHtml(token.content));
|
|
722
748
|
if (format === "html") {
|
|
723
749
|
return `<blockquote style="border-left: 2px solid #d1d5db; padding: 8px 0 8px 16px; margin: 16px 0; font-style: italic; color: #6b7280;">${content}</blockquote>`;
|
|
724
750
|
}
|
|
@@ -1070,7 +1096,14 @@ var ListExtension = {
|
|
|
1070
1096
|
renderRules: [
|
|
1071
1097
|
{
|
|
1072
1098
|
type: "list-item",
|
|
1073
|
-
render: (token) =>
|
|
1099
|
+
render: (token) => {
|
|
1100
|
+
const format = token.attributes?.format || "tailwind";
|
|
1101
|
+
const content = token.attributes?.renderedChildren || escapeHtml(token.content);
|
|
1102
|
+
if (format === "html") {
|
|
1103
|
+
return `<li>${content}</li>`;
|
|
1104
|
+
}
|
|
1105
|
+
return `<li>${content}</li>`;
|
|
1106
|
+
}
|
|
1074
1107
|
}
|
|
1075
1108
|
]
|
|
1076
1109
|
};
|
|
@@ -1095,18 +1128,18 @@ var TaskListExtension = {
|
|
|
1095
1128
|
type: "task-item",
|
|
1096
1129
|
render: (token) => {
|
|
1097
1130
|
const isChecked = token.attributes?.checked === "true";
|
|
1098
|
-
const
|
|
1131
|
+
const content = token.attributes?.renderedChildren || escapeHtml(token.content);
|
|
1099
1132
|
const format = token.attributes?.format || "html";
|
|
1100
1133
|
if (format === "html") {
|
|
1101
1134
|
return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
|
|
1102
1135
|
<input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
|
|
1103
|
-
<span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${
|
|
1136
|
+
<span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
|
|
1104
1137
|
</div>`;
|
|
1105
1138
|
}
|
|
1106
1139
|
return `<div class="flex items-center gap-2 my-2 task-list-item">
|
|
1107
|
-
<input type="checkbox" ${isChecked ? "checked" : ""} disabled
|
|
1140
|
+
<input type="checkbox" ${isChecked ? "checked" : ""} disabled
|
|
1108
1141
|
class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
|
|
1109
|
-
<span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${
|
|
1142
|
+
<span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
|
|
1110
1143
|
</div>`;
|
|
1111
1144
|
}
|
|
1112
1145
|
}
|
|
@@ -1174,7 +1207,7 @@ var AlertExtension = {
|
|
|
1174
1207
|
parseRules: [
|
|
1175
1208
|
{
|
|
1176
1209
|
name: "alert",
|
|
1177
|
-
pattern: /:::(\w+)(
|
|
1210
|
+
pattern: /:::(\w+)(?: ([^\n]+))?\n([\s\S]*?)\n:::/,
|
|
1178
1211
|
render: (match) => {
|
|
1179
1212
|
return {
|
|
1180
1213
|
type: "alert",
|
|
@@ -1182,7 +1215,7 @@ var AlertExtension = {
|
|
|
1182
1215
|
raw: match[0] || "",
|
|
1183
1216
|
attributes: {
|
|
1184
1217
|
type: match[1] || "info",
|
|
1185
|
-
title: match[2] || ""
|
|
1218
|
+
title: match[2]?.trim() || ""
|
|
1186
1219
|
}
|
|
1187
1220
|
};
|
|
1188
1221
|
}
|
|
@@ -1223,6 +1256,9 @@ var AlertExtension = {
|
|
|
1223
1256
|
const config = typeConfig[type] || typeConfig.info;
|
|
1224
1257
|
const baseClasses = "border-l-4 p-4 mb-4 rounded-md transition-colors duration-200";
|
|
1225
1258
|
const classes = `${baseClasses} ${config?.classes}`;
|
|
1259
|
+
const renderedChildren = token.attributes?.renderedChildren;
|
|
1260
|
+
const renderMarkdown2 = token.attributes?.renderMarkdown;
|
|
1261
|
+
const renderedContent = renderedChildren || (renderMarkdown2 ? renderMarkdown2(token.content) : token.content);
|
|
1226
1262
|
const titleHtml = title ? `<div class="font-medium mb-2 flex items-center gap-2">
|
|
1227
1263
|
<span class="text-lg" role="img" aria-label="${type}">${config?.icon}</span>
|
|
1228
1264
|
<span>${title}</span>
|
|
@@ -1232,7 +1268,7 @@ var AlertExtension = {
|
|
|
1232
1268
|
</div>`;
|
|
1233
1269
|
return `<div class="${classes}" role="alert" aria-live="polite">
|
|
1234
1270
|
${titleHtml}
|
|
1235
|
-
<div class="leading-relaxed">${
|
|
1271
|
+
<div class="leading-relaxed">${renderedContent}</div>
|
|
1236
1272
|
</div>`;
|
|
1237
1273
|
}
|
|
1238
1274
|
}
|