@changerawr/markdown 1.1.8 → 1.1.9

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.
@@ -1543,20 +1543,59 @@ var ChangerawrMarkdown = (() => {
1543
1543
  format: this.config.format
1544
1544
  })
1545
1545
  }));
1546
- const htmlParts = tokensWithFormat.map((token) => this.renderToken(token));
1546
+ const groupedTokens = this.groupListItems(tokensWithFormat);
1547
+ const htmlParts = groupedTokens.map((token) => this.renderToken(token));
1547
1548
  const combinedHtml = htmlParts.join("");
1548
1549
  if (this.config.sanitize && !this.config.allowUnsafeHtml) {
1549
1550
  return sanitizeHtml(combinedHtml);
1550
1551
  }
1551
1552
  return combinedHtml;
1552
1553
  }
1554
+ groupListItems(tokens) {
1555
+ const result = [];
1556
+ let i = 0;
1557
+ while (i < tokens.length) {
1558
+ const token = tokens[i];
1559
+ const isListItem = (token == null ? void 0 : token.type) === "list-item" || (token == null ? void 0 : token.type) === "ordered-list-item" || (token == null ? void 0 : token.type) === "task-item";
1560
+ if (isListItem) {
1561
+ const listItems = [];
1562
+ const firstItemType = token.type;
1563
+ const isOrdered = firstItemType === "ordered-list-item";
1564
+ while (i < tokens.length) {
1565
+ const item = tokens[i];
1566
+ if (!item) break;
1567
+ const itemType = item.type;
1568
+ const isSameListType = isOrdered && itemType === "ordered-list-item" || !isOrdered && (itemType === "list-item" || itemType === "task-item");
1569
+ if (isSameListType) {
1570
+ listItems.push(item);
1571
+ i++;
1572
+ } else {
1573
+ break;
1574
+ }
1575
+ }
1576
+ const wrappedList = {
1577
+ type: isOrdered ? "ol" : "ul",
1578
+ content: "",
1579
+ raw: "",
1580
+ children: listItems,
1581
+ attributes: { format: this.config.format }
1582
+ };
1583
+ wrappedList._isWrapped = true;
1584
+ result.push(wrappedList);
1585
+ } else {
1586
+ result.push(token);
1587
+ i++;
1588
+ }
1589
+ }
1590
+ return result;
1591
+ }
1553
1592
  renderToken(token) {
1554
1593
  const rule = this.rules.get(token.type);
1555
1594
  if (rule) {
1556
1595
  try {
1557
1596
  let tokenToRender = token;
1558
1597
  if (token.children && token.children.length > 0) {
1559
- const renderedChildren = this.render(token.children);
1598
+ const renderedChildren = token.type === "ul" || token.type === "ol" ? token.children.map((child) => this.renderToken(child)).join("") : this.render(token.children);
1560
1599
  tokenToRender = __spreadProps(__spreadValues({}, token), {
1561
1600
  attributes: __spreadProps(__spreadValues({}, token.attributes), {
1562
1601
  renderedChildren
@@ -2183,6 +2222,30 @@ var ChangerawrMarkdown = (() => {
2183
2222
  }
2184
2223
  ],
2185
2224
  renderRules: [
2225
+ {
2226
+ type: "ul",
2227
+ render: (token) => {
2228
+ var _a, _b;
2229
+ const format = ((_a = token.attributes) == null ? void 0 : _a.format) || "tailwind";
2230
+ const content = ((_b = token.attributes) == null ? void 0 : _b.renderedChildren) || "";
2231
+ if (format === "html") {
2232
+ return `<ul style="margin: 8px 0; padding-left: 24px; list-style: disc;">${content}</ul>`;
2233
+ }
2234
+ return `<ul class="my-2 pl-6 list-disc">${content}</ul>`;
2235
+ }
2236
+ },
2237
+ {
2238
+ type: "ol",
2239
+ render: (token) => {
2240
+ var _a, _b;
2241
+ const format = ((_a = token.attributes) == null ? void 0 : _a.format) || "tailwind";
2242
+ const content = ((_b = token.attributes) == null ? void 0 : _b.renderedChildren) || "";
2243
+ if (format === "html") {
2244
+ return `<ol style="margin: 8px 0; padding-left: 24px; list-style: decimal;">${content}</ol>`;
2245
+ }
2246
+ return `<ol class="my-2 pl-6 list-decimal">${content}</ol>`;
2247
+ }
2248
+ },
2186
2249
  {
2187
2250
  type: "list-item",
2188
2251
  render: (token) => {
@@ -2237,15 +2300,20 @@ var ChangerawrMarkdown = (() => {
2237
2300
  const isChecked = ((_a = token.attributes) == null ? void 0 : _a.checked) === "true";
2238
2301
  const content = ((_b = token.attributes) == null ? void 0 : _b.renderedChildren) || escapeHtml(token.content);
2239
2302
  const format = ((_c = token.attributes) == null ? void 0 : _c.format) || "html";
2303
+ const checkmark = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="flex-shrink: 0; margin-top: 2px;"><polyline points="20 6 9 17 4 12"></polyline></svg>`;
2304
+ const checkbox = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="flex-shrink: 0; margin-top: 2px;"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect></svg>`;
2240
2305
  if (format === "html") {
2241
- return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
2242
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
2306
+ return `<div style="display: flex; align-items: flex-start; gap: 8px; margin: 8px 0;">
2307
+ <div style="color: ${isChecked ? "#10b981" : "#9ca3af"}; margin-top: 2px;">
2308
+ ${isChecked ? checkmark : checkbox}
2309
+ </div>
2243
2310
  <span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
2244
2311
  </div>`;
2245
2312
  }
2246
- return `<div class="flex items-center gap-2 my-2 task-list-item">
2247
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled
2248
- class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
2313
+ return `<div class="flex items-start gap-2 my-2 task-list-item">
2314
+ <div class="${isChecked ? "text-green-600" : "text-gray-400"} flex-shrink-0 mt-0.5">
2315
+ ${isChecked ? checkmark : checkbox}
2316
+ </div>
2249
2317
  <span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
2250
2318
  </div>`;
2251
2319
  }
@@ -528,20 +528,59 @@ var MarkdownRenderer = class {
528
528
  format: this.config.format
529
529
  }
530
530
  }));
531
- const htmlParts = tokensWithFormat.map((token) => this.renderToken(token));
531
+ const groupedTokens = this.groupListItems(tokensWithFormat);
532
+ const htmlParts = groupedTokens.map((token) => this.renderToken(token));
532
533
  const combinedHtml = htmlParts.join("");
533
534
  if (this.config.sanitize && !this.config.allowUnsafeHtml) {
534
535
  return sanitizeHtml(combinedHtml);
535
536
  }
536
537
  return combinedHtml;
537
538
  }
539
+ groupListItems(tokens) {
540
+ const result = [];
541
+ let i = 0;
542
+ while (i < tokens.length) {
543
+ const token = tokens[i];
544
+ const isListItem = token?.type === "list-item" || token?.type === "ordered-list-item" || token?.type === "task-item";
545
+ if (isListItem) {
546
+ const listItems = [];
547
+ const firstItemType = token.type;
548
+ const isOrdered = firstItemType === "ordered-list-item";
549
+ while (i < tokens.length) {
550
+ const item = tokens[i];
551
+ if (!item) break;
552
+ const itemType = item.type;
553
+ const isSameListType = isOrdered && itemType === "ordered-list-item" || !isOrdered && (itemType === "list-item" || itemType === "task-item");
554
+ if (isSameListType) {
555
+ listItems.push(item);
556
+ i++;
557
+ } else {
558
+ break;
559
+ }
560
+ }
561
+ const wrappedList = {
562
+ type: isOrdered ? "ol" : "ul",
563
+ content: "",
564
+ raw: "",
565
+ children: listItems,
566
+ attributes: { format: this.config.format }
567
+ };
568
+ wrappedList._isWrapped = true;
569
+ result.push(wrappedList);
570
+ } else {
571
+ result.push(token);
572
+ i++;
573
+ }
574
+ }
575
+ return result;
576
+ }
538
577
  renderToken(token) {
539
578
  const rule = this.rules.get(token.type);
540
579
  if (rule) {
541
580
  try {
542
581
  let tokenToRender = token;
543
582
  if (token.children && token.children.length > 0) {
544
- const renderedChildren = this.render(token.children);
583
+ const renderedChildren = token.type === "ul" || token.type === "ol" ? token.children.map((child) => this.renderToken(child)).join("") : this.render(token.children);
545
584
  tokenToRender = {
546
585
  ...token,
547
586
  attributes: {
@@ -1152,6 +1191,28 @@ var ListExtension = {
1152
1191
  }
1153
1192
  ],
1154
1193
  renderRules: [
1194
+ {
1195
+ type: "ul",
1196
+ render: (token) => {
1197
+ const format = token.attributes?.format || "tailwind";
1198
+ const content = token.attributes?.renderedChildren || "";
1199
+ if (format === "html") {
1200
+ return `<ul style="margin: 8px 0; padding-left: 24px; list-style: disc;">${content}</ul>`;
1201
+ }
1202
+ return `<ul class="my-2 pl-6 list-disc">${content}</ul>`;
1203
+ }
1204
+ },
1205
+ {
1206
+ type: "ol",
1207
+ render: (token) => {
1208
+ const format = token.attributes?.format || "tailwind";
1209
+ const content = token.attributes?.renderedChildren || "";
1210
+ if (format === "html") {
1211
+ return `<ol style="margin: 8px 0; padding-left: 24px; list-style: decimal;">${content}</ol>`;
1212
+ }
1213
+ return `<ol class="my-2 pl-6 list-decimal">${content}</ol>`;
1214
+ }
1215
+ },
1155
1216
  {
1156
1217
  type: "list-item",
1157
1218
  render: (token) => {
@@ -1200,15 +1261,20 @@ var TaskListExtension = {
1200
1261
  const isChecked = token.attributes?.checked === "true";
1201
1262
  const content = token.attributes?.renderedChildren || escapeHtml(token.content);
1202
1263
  const format = token.attributes?.format || "html";
1264
+ const checkmark = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="flex-shrink: 0; margin-top: 2px;"><polyline points="20 6 9 17 4 12"></polyline></svg>`;
1265
+ const checkbox = `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="flex-shrink: 0; margin-top: 2px;"><rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect></svg>`;
1203
1266
  if (format === "html") {
1204
- return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
1205
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
1267
+ return `<div style="display: flex; align-items: flex-start; gap: 8px; margin: 8px 0;">
1268
+ <div style="color: ${isChecked ? "#10b981" : "#9ca3af"}; margin-top: 2px;">
1269
+ ${isChecked ? checkmark : checkbox}
1270
+ </div>
1206
1271
  <span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
1207
1272
  </div>`;
1208
1273
  }
1209
- return `<div class="flex items-center gap-2 my-2 task-list-item">
1210
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled
1211
- class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
1274
+ return `<div class="flex items-start gap-2 my-2 task-list-item">
1275
+ <div class="${isChecked ? "text-green-600" : "text-gray-400"} flex-shrink-0 mt-0.5">
1276
+ ${isChecked ? checkmark : checkbox}
1277
+ </div>
1212
1278
  <span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
1213
1279
  </div>`;
1214
1280
  }