@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/standalone.mjs
CHANGED
|
@@ -187,7 +187,8 @@ var MarkdownParser = class {
|
|
|
187
187
|
}
|
|
188
188
|
i = j;
|
|
189
189
|
} else if (token) {
|
|
190
|
-
|
|
190
|
+
const processedToken = this.recursivelyParseBlockContent(token);
|
|
191
|
+
processed.push(processedToken);
|
|
191
192
|
i++;
|
|
192
193
|
} else {
|
|
193
194
|
i++;
|
|
@@ -195,6 +196,17 @@ var MarkdownParser = class {
|
|
|
195
196
|
}
|
|
196
197
|
return processed;
|
|
197
198
|
}
|
|
199
|
+
recursivelyParseBlockContent(token) {
|
|
200
|
+
const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
|
|
201
|
+
if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
|
|
202
|
+
const children = this.parse(token.content);
|
|
203
|
+
return {
|
|
204
|
+
...token,
|
|
205
|
+
children
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return token;
|
|
209
|
+
}
|
|
198
210
|
};
|
|
199
211
|
|
|
200
212
|
// src/utils.ts
|
|
@@ -460,7 +472,19 @@ var MarkdownRenderer = class {
|
|
|
460
472
|
const rule = this.rules.get(token.type);
|
|
461
473
|
if (rule) {
|
|
462
474
|
try {
|
|
463
|
-
|
|
475
|
+
let tokenToRender = token;
|
|
476
|
+
if (token.children && token.children.length > 0) {
|
|
477
|
+
const renderedChildren = this.render(token.children);
|
|
478
|
+
tokenToRender = {
|
|
479
|
+
...token,
|
|
480
|
+
attributes: {
|
|
481
|
+
...token.attributes,
|
|
482
|
+
renderedChildren
|
|
483
|
+
// Extensions can use this instead of re-parsing
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
return rule.render(tokenToRender);
|
|
464
488
|
} catch (error) {
|
|
465
489
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
466
490
|
this.warnings.push(`Render error for ${token.type}: ${errorMessage}`);
|
|
@@ -529,8 +553,10 @@ var BlockquoteExtension = {
|
|
|
529
553
|
{
|
|
530
554
|
type: "blockquote",
|
|
531
555
|
render: (token) => {
|
|
532
|
-
const content = escapeHtml(token.content);
|
|
533
556
|
const format = token.attributes?.format || "html";
|
|
557
|
+
const renderedChildren = token.attributes?.renderedChildren;
|
|
558
|
+
const renderMarkdown = token.attributes?.renderMarkdown;
|
|
559
|
+
const content = renderedChildren || (renderMarkdown ? renderMarkdown(token.content) : escapeHtml(token.content));
|
|
534
560
|
if (format === "html") {
|
|
535
561
|
return `<blockquote style="border-left: 2px solid #d1d5db; padding: 8px 0 8px 16px; margin: 16px 0; font-style: italic; color: #6b7280;">${content}</blockquote>`;
|
|
536
562
|
}
|
|
@@ -882,7 +908,14 @@ var ListExtension = {
|
|
|
882
908
|
renderRules: [
|
|
883
909
|
{
|
|
884
910
|
type: "list-item",
|
|
885
|
-
render: (token) =>
|
|
911
|
+
render: (token) => {
|
|
912
|
+
const format = token.attributes?.format || "tailwind";
|
|
913
|
+
const content = token.attributes?.renderedChildren || escapeHtml(token.content);
|
|
914
|
+
if (format === "html") {
|
|
915
|
+
return `<li>${content}</li>`;
|
|
916
|
+
}
|
|
917
|
+
return `<li>${content}</li>`;
|
|
918
|
+
}
|
|
886
919
|
}
|
|
887
920
|
]
|
|
888
921
|
};
|
|
@@ -907,18 +940,18 @@ var TaskListExtension = {
|
|
|
907
940
|
type: "task-item",
|
|
908
941
|
render: (token) => {
|
|
909
942
|
const isChecked = token.attributes?.checked === "true";
|
|
910
|
-
const
|
|
943
|
+
const content = token.attributes?.renderedChildren || escapeHtml(token.content);
|
|
911
944
|
const format = token.attributes?.format || "html";
|
|
912
945
|
if (format === "html") {
|
|
913
946
|
return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
|
|
914
947
|
<input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
|
|
915
|
-
<span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${
|
|
948
|
+
<span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
|
|
916
949
|
</div>`;
|
|
917
950
|
}
|
|
918
951
|
return `<div class="flex items-center gap-2 my-2 task-list-item">
|
|
919
|
-
<input type="checkbox" ${isChecked ? "checked" : ""} disabled
|
|
952
|
+
<input type="checkbox" ${isChecked ? "checked" : ""} disabled
|
|
920
953
|
class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
|
|
921
|
-
<span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${
|
|
954
|
+
<span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
|
|
922
955
|
</div>`;
|
|
923
956
|
}
|
|
924
957
|
}
|
|
@@ -986,7 +1019,7 @@ var AlertExtension = {
|
|
|
986
1019
|
parseRules: [
|
|
987
1020
|
{
|
|
988
1021
|
name: "alert",
|
|
989
|
-
pattern: /:::(\w+)(
|
|
1022
|
+
pattern: /:::(\w+)(?: ([^\n]+))?\n([\s\S]*?)\n:::/,
|
|
990
1023
|
render: (match) => {
|
|
991
1024
|
return {
|
|
992
1025
|
type: "alert",
|
|
@@ -994,7 +1027,7 @@ var AlertExtension = {
|
|
|
994
1027
|
raw: match[0] || "",
|
|
995
1028
|
attributes: {
|
|
996
1029
|
type: match[1] || "info",
|
|
997
|
-
title: match[2] || ""
|
|
1030
|
+
title: match[2]?.trim() || ""
|
|
998
1031
|
}
|
|
999
1032
|
};
|
|
1000
1033
|
}
|
|
@@ -1035,6 +1068,9 @@ var AlertExtension = {
|
|
|
1035
1068
|
const config = typeConfig[type] || typeConfig.info;
|
|
1036
1069
|
const baseClasses = "border-l-4 p-4 mb-4 rounded-md transition-colors duration-200";
|
|
1037
1070
|
const classes = `${baseClasses} ${config?.classes}`;
|
|
1071
|
+
const renderedChildren = token.attributes?.renderedChildren;
|
|
1072
|
+
const renderMarkdown = token.attributes?.renderMarkdown;
|
|
1073
|
+
const renderedContent = renderedChildren || (renderMarkdown ? renderMarkdown(token.content) : token.content);
|
|
1038
1074
|
const titleHtml = title ? `<div class="font-medium mb-2 flex items-center gap-2">
|
|
1039
1075
|
<span class="text-lg" role="img" aria-label="${type}">${config?.icon}</span>
|
|
1040
1076
|
<span>${title}</span>
|
|
@@ -1044,7 +1080,7 @@ var AlertExtension = {
|
|
|
1044
1080
|
</div>`;
|
|
1045
1081
|
return `<div class="${classes}" role="alert" aria-live="polite">
|
|
1046
1082
|
${titleHtml}
|
|
1047
|
-
<div class="leading-relaxed">${
|
|
1083
|
+
<div class="leading-relaxed">${renderedContent}</div>
|
|
1048
1084
|
</div>`;
|
|
1049
1085
|
}
|
|
1050
1086
|
}
|