@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
|
@@ -1229,7 +1229,8 @@ var ChangerawrMarkdown = (() => {
|
|
|
1229
1229
|
}
|
|
1230
1230
|
i = j;
|
|
1231
1231
|
} else if (token) {
|
|
1232
|
-
|
|
1232
|
+
const processedToken = this.recursivelyParseBlockContent(token);
|
|
1233
|
+
processed.push(processedToken);
|
|
1233
1234
|
i++;
|
|
1234
1235
|
} else {
|
|
1235
1236
|
i++;
|
|
@@ -1237,6 +1238,16 @@ var ChangerawrMarkdown = (() => {
|
|
|
1237
1238
|
}
|
|
1238
1239
|
return processed;
|
|
1239
1240
|
}
|
|
1241
|
+
recursivelyParseBlockContent(token) {
|
|
1242
|
+
const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
|
|
1243
|
+
if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
|
|
1244
|
+
const children = this.parse(token.content);
|
|
1245
|
+
return __spreadProps(__spreadValues({}, token), {
|
|
1246
|
+
children
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
return token;
|
|
1250
|
+
}
|
|
1240
1251
|
};
|
|
1241
1252
|
|
|
1242
1253
|
// src/utils.ts
|
|
@@ -1499,7 +1510,17 @@ var ChangerawrMarkdown = (() => {
|
|
|
1499
1510
|
const rule = this.rules.get(token.type);
|
|
1500
1511
|
if (rule) {
|
|
1501
1512
|
try {
|
|
1502
|
-
|
|
1513
|
+
let tokenToRender = token;
|
|
1514
|
+
if (token.children && token.children.length > 0) {
|
|
1515
|
+
const renderedChildren = this.render(token.children);
|
|
1516
|
+
tokenToRender = __spreadProps(__spreadValues({}, token), {
|
|
1517
|
+
attributes: __spreadProps(__spreadValues({}, token.attributes), {
|
|
1518
|
+
renderedChildren
|
|
1519
|
+
// Extensions can use this instead of re-parsing
|
|
1520
|
+
})
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
return rule.render(tokenToRender);
|
|
1503
1524
|
} catch (error) {
|
|
1504
1525
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1505
1526
|
this.warnings.push(`Render error for ${token.type}: ${errorMessage}`);
|
|
@@ -1568,9 +1589,11 @@ var ChangerawrMarkdown = (() => {
|
|
|
1568
1589
|
{
|
|
1569
1590
|
type: "blockquote",
|
|
1570
1591
|
render: (token) => {
|
|
1571
|
-
var _a;
|
|
1572
|
-
const content = escapeHtml(token.content);
|
|
1592
|
+
var _a, _b, _c;
|
|
1573
1593
|
const format = ((_a = token.attributes) == null ? void 0 : _a.format) || "html";
|
|
1594
|
+
const renderedChildren = (_b = token.attributes) == null ? void 0 : _b.renderedChildren;
|
|
1595
|
+
const renderMarkdown = (_c = token.attributes) == null ? void 0 : _c.renderMarkdown;
|
|
1596
|
+
const content = renderedChildren || (renderMarkdown ? renderMarkdown(token.content) : escapeHtml(token.content));
|
|
1574
1597
|
if (format === "html") {
|
|
1575
1598
|
return `<blockquote style="border-left: 2px solid #d1d5db; padding: 8px 0 8px 16px; margin: 16px 0; font-style: italic; color: #6b7280;">${content}</blockquote>`;
|
|
1576
1599
|
}
|
|
@@ -1933,7 +1956,15 @@ var ChangerawrMarkdown = (() => {
|
|
|
1933
1956
|
renderRules: [
|
|
1934
1957
|
{
|
|
1935
1958
|
type: "list-item",
|
|
1936
|
-
render: (token) =>
|
|
1959
|
+
render: (token) => {
|
|
1960
|
+
var _a, _b;
|
|
1961
|
+
const format = ((_a = token.attributes) == null ? void 0 : _a.format) || "tailwind";
|
|
1962
|
+
const content = ((_b = token.attributes) == null ? void 0 : _b.renderedChildren) || escapeHtml(token.content);
|
|
1963
|
+
if (format === "html") {
|
|
1964
|
+
return `<li>${content}</li>`;
|
|
1965
|
+
}
|
|
1966
|
+
return `<li>${content}</li>`;
|
|
1967
|
+
}
|
|
1937
1968
|
}
|
|
1938
1969
|
]
|
|
1939
1970
|
};
|
|
@@ -1957,20 +1988,20 @@ var ChangerawrMarkdown = (() => {
|
|
|
1957
1988
|
{
|
|
1958
1989
|
type: "task-item",
|
|
1959
1990
|
render: (token) => {
|
|
1960
|
-
var _a, _b;
|
|
1991
|
+
var _a, _b, _c;
|
|
1961
1992
|
const isChecked = ((_a = token.attributes) == null ? void 0 : _a.checked) === "true";
|
|
1962
|
-
const
|
|
1963
|
-
const format = ((
|
|
1993
|
+
const content = ((_b = token.attributes) == null ? void 0 : _b.renderedChildren) || escapeHtml(token.content);
|
|
1994
|
+
const format = ((_c = token.attributes) == null ? void 0 : _c.format) || "html";
|
|
1964
1995
|
if (format === "html") {
|
|
1965
1996
|
return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
|
|
1966
1997
|
<input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
|
|
1967
|
-
<span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${
|
|
1998
|
+
<span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
|
|
1968
1999
|
</div>`;
|
|
1969
2000
|
}
|
|
1970
2001
|
return `<div class="flex items-center gap-2 my-2 task-list-item">
|
|
1971
|
-
<input type="checkbox" ${isChecked ? "checked" : ""} disabled
|
|
2002
|
+
<input type="checkbox" ${isChecked ? "checked" : ""} disabled
|
|
1972
2003
|
class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
|
|
1973
|
-
<span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${
|
|
2004
|
+
<span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
|
|
1974
2005
|
</div>`;
|
|
1975
2006
|
}
|
|
1976
2007
|
}
|
|
@@ -2039,16 +2070,16 @@ var ChangerawrMarkdown = (() => {
|
|
|
2039
2070
|
parseRules: [
|
|
2040
2071
|
{
|
|
2041
2072
|
name: "alert",
|
|
2042
|
-
pattern: /:::(\w+)(
|
|
2073
|
+
pattern: /:::(\w+)(?: ([^\n]+))?\n([\s\S]*?)\n:::/,
|
|
2043
2074
|
render: (match) => {
|
|
2044
|
-
var _a;
|
|
2075
|
+
var _a, _b;
|
|
2045
2076
|
return {
|
|
2046
2077
|
type: "alert",
|
|
2047
2078
|
content: ((_a = match[3]) == null ? void 0 : _a.trim()) || "",
|
|
2048
2079
|
raw: match[0] || "",
|
|
2049
2080
|
attributes: {
|
|
2050
2081
|
type: match[1] || "info",
|
|
2051
|
-
title: match[2] || ""
|
|
2082
|
+
title: ((_b = match[2]) == null ? void 0 : _b.trim()) || ""
|
|
2052
2083
|
}
|
|
2053
2084
|
};
|
|
2054
2085
|
}
|
|
@@ -2058,7 +2089,7 @@ var ChangerawrMarkdown = (() => {
|
|
|
2058
2089
|
{
|
|
2059
2090
|
type: "alert",
|
|
2060
2091
|
render: (token) => {
|
|
2061
|
-
var _a, _b;
|
|
2092
|
+
var _a, _b, _c, _d;
|
|
2062
2093
|
const type = ((_a = token.attributes) == null ? void 0 : _a.type) || "info";
|
|
2063
2094
|
const title = ((_b = token.attributes) == null ? void 0 : _b.title) || "";
|
|
2064
2095
|
const typeConfig = {
|
|
@@ -2090,6 +2121,9 @@ var ChangerawrMarkdown = (() => {
|
|
|
2090
2121
|
const config = typeConfig[type] || typeConfig.info;
|
|
2091
2122
|
const baseClasses = "border-l-4 p-4 mb-4 rounded-md transition-colors duration-200";
|
|
2092
2123
|
const classes = `${baseClasses} ${config == null ? void 0 : config.classes}`;
|
|
2124
|
+
const renderedChildren = (_c = token.attributes) == null ? void 0 : _c.renderedChildren;
|
|
2125
|
+
const renderMarkdown = (_d = token.attributes) == null ? void 0 : _d.renderMarkdown;
|
|
2126
|
+
const renderedContent = renderedChildren || (renderMarkdown ? renderMarkdown(token.content) : token.content);
|
|
2093
2127
|
const titleHtml = title ? `<div class="font-medium mb-2 flex items-center gap-2">
|
|
2094
2128
|
<span class="text-lg" role="img" aria-label="${type}">${config == null ? void 0 : config.icon}</span>
|
|
2095
2129
|
<span>${title}</span>
|
|
@@ -2099,7 +2133,7 @@ var ChangerawrMarkdown = (() => {
|
|
|
2099
2133
|
</div>`;
|
|
2100
2134
|
return `<div class="${classes}" role="alert" aria-live="polite">
|
|
2101
2135
|
${titleHtml}
|
|
2102
|
-
<div class="leading-relaxed">${
|
|
2136
|
+
<div class="leading-relaxed">${renderedContent}</div>
|
|
2103
2137
|
</div>`;
|
|
2104
2138
|
}
|
|
2105
2139
|
}
|
package/dist/standalone.d.mts
CHANGED
package/dist/standalone.d.ts
CHANGED
package/dist/standalone.js
CHANGED
|
@@ -230,7 +230,8 @@ var MarkdownParser = class {
|
|
|
230
230
|
}
|
|
231
231
|
i = j;
|
|
232
232
|
} else if (token) {
|
|
233
|
-
|
|
233
|
+
const processedToken = this.recursivelyParseBlockContent(token);
|
|
234
|
+
processed.push(processedToken);
|
|
234
235
|
i++;
|
|
235
236
|
} else {
|
|
236
237
|
i++;
|
|
@@ -238,6 +239,17 @@ var MarkdownParser = class {
|
|
|
238
239
|
}
|
|
239
240
|
return processed;
|
|
240
241
|
}
|
|
242
|
+
recursivelyParseBlockContent(token) {
|
|
243
|
+
const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
|
|
244
|
+
if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
|
|
245
|
+
const children = this.parse(token.content);
|
|
246
|
+
return {
|
|
247
|
+
...token,
|
|
248
|
+
children
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return token;
|
|
252
|
+
}
|
|
241
253
|
};
|
|
242
254
|
|
|
243
255
|
// src/utils.ts
|
|
@@ -503,7 +515,19 @@ var MarkdownRenderer = class {
|
|
|
503
515
|
const rule = this.rules.get(token.type);
|
|
504
516
|
if (rule) {
|
|
505
517
|
try {
|
|
506
|
-
|
|
518
|
+
let tokenToRender = token;
|
|
519
|
+
if (token.children && token.children.length > 0) {
|
|
520
|
+
const renderedChildren = this.render(token.children);
|
|
521
|
+
tokenToRender = {
|
|
522
|
+
...token,
|
|
523
|
+
attributes: {
|
|
524
|
+
...token.attributes,
|
|
525
|
+
renderedChildren
|
|
526
|
+
// Extensions can use this instead of re-parsing
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
return rule.render(tokenToRender);
|
|
507
531
|
} catch (error) {
|
|
508
532
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
509
533
|
this.warnings.push(`Render error for ${token.type}: ${errorMessage}`);
|
|
@@ -572,8 +596,10 @@ var BlockquoteExtension = {
|
|
|
572
596
|
{
|
|
573
597
|
type: "blockquote",
|
|
574
598
|
render: (token) => {
|
|
575
|
-
const content = escapeHtml(token.content);
|
|
576
599
|
const format = token.attributes?.format || "html";
|
|
600
|
+
const renderedChildren = token.attributes?.renderedChildren;
|
|
601
|
+
const renderMarkdown = token.attributes?.renderMarkdown;
|
|
602
|
+
const content = renderedChildren || (renderMarkdown ? renderMarkdown(token.content) : escapeHtml(token.content));
|
|
577
603
|
if (format === "html") {
|
|
578
604
|
return `<blockquote style="border-left: 2px solid #d1d5db; padding: 8px 0 8px 16px; margin: 16px 0; font-style: italic; color: #6b7280;">${content}</blockquote>`;
|
|
579
605
|
}
|
|
@@ -925,7 +951,14 @@ var ListExtension = {
|
|
|
925
951
|
renderRules: [
|
|
926
952
|
{
|
|
927
953
|
type: "list-item",
|
|
928
|
-
render: (token) =>
|
|
954
|
+
render: (token) => {
|
|
955
|
+
const format = token.attributes?.format || "tailwind";
|
|
956
|
+
const content = token.attributes?.renderedChildren || escapeHtml(token.content);
|
|
957
|
+
if (format === "html") {
|
|
958
|
+
return `<li>${content}</li>`;
|
|
959
|
+
}
|
|
960
|
+
return `<li>${content}</li>`;
|
|
961
|
+
}
|
|
929
962
|
}
|
|
930
963
|
]
|
|
931
964
|
};
|
|
@@ -950,18 +983,18 @@ var TaskListExtension = {
|
|
|
950
983
|
type: "task-item",
|
|
951
984
|
render: (token) => {
|
|
952
985
|
const isChecked = token.attributes?.checked === "true";
|
|
953
|
-
const
|
|
986
|
+
const content = token.attributes?.renderedChildren || escapeHtml(token.content);
|
|
954
987
|
const format = token.attributes?.format || "html";
|
|
955
988
|
if (format === "html") {
|
|
956
989
|
return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
|
|
957
990
|
<input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
|
|
958
|
-
<span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${
|
|
991
|
+
<span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
|
|
959
992
|
</div>`;
|
|
960
993
|
}
|
|
961
994
|
return `<div class="flex items-center gap-2 my-2 task-list-item">
|
|
962
|
-
<input type="checkbox" ${isChecked ? "checked" : ""} disabled
|
|
995
|
+
<input type="checkbox" ${isChecked ? "checked" : ""} disabled
|
|
963
996
|
class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
|
|
964
|
-
<span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${
|
|
997
|
+
<span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
|
|
965
998
|
</div>`;
|
|
966
999
|
}
|
|
967
1000
|
}
|
|
@@ -1029,7 +1062,7 @@ var AlertExtension = {
|
|
|
1029
1062
|
parseRules: [
|
|
1030
1063
|
{
|
|
1031
1064
|
name: "alert",
|
|
1032
|
-
pattern: /:::(\w+)(
|
|
1065
|
+
pattern: /:::(\w+)(?: ([^\n]+))?\n([\s\S]*?)\n:::/,
|
|
1033
1066
|
render: (match) => {
|
|
1034
1067
|
return {
|
|
1035
1068
|
type: "alert",
|
|
@@ -1037,7 +1070,7 @@ var AlertExtension = {
|
|
|
1037
1070
|
raw: match[0] || "",
|
|
1038
1071
|
attributes: {
|
|
1039
1072
|
type: match[1] || "info",
|
|
1040
|
-
title: match[2] || ""
|
|
1073
|
+
title: match[2]?.trim() || ""
|
|
1041
1074
|
}
|
|
1042
1075
|
};
|
|
1043
1076
|
}
|
|
@@ -1078,6 +1111,9 @@ var AlertExtension = {
|
|
|
1078
1111
|
const config = typeConfig[type] || typeConfig.info;
|
|
1079
1112
|
const baseClasses = "border-l-4 p-4 mb-4 rounded-md transition-colors duration-200";
|
|
1080
1113
|
const classes = `${baseClasses} ${config?.classes}`;
|
|
1114
|
+
const renderedChildren = token.attributes?.renderedChildren;
|
|
1115
|
+
const renderMarkdown = token.attributes?.renderMarkdown;
|
|
1116
|
+
const renderedContent = renderedChildren || (renderMarkdown ? renderMarkdown(token.content) : token.content);
|
|
1081
1117
|
const titleHtml = title ? `<div class="font-medium mb-2 flex items-center gap-2">
|
|
1082
1118
|
<span class="text-lg" role="img" aria-label="${type}">${config?.icon}</span>
|
|
1083
1119
|
<span>${title}</span>
|
|
@@ -1087,7 +1123,7 @@ var AlertExtension = {
|
|
|
1087
1123
|
</div>`;
|
|
1088
1124
|
return `<div class="${classes}" role="alert" aria-live="polite">
|
|
1089
1125
|
${titleHtml}
|
|
1090
|
-
<div class="leading-relaxed">${
|
|
1126
|
+
<div class="leading-relaxed">${renderedContent}</div>
|
|
1091
1127
|
</div>`;
|
|
1092
1128
|
}
|
|
1093
1129
|
}
|