@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.
@@ -491,20 +491,59 @@ var MarkdownRenderer = class {
491
491
  format: this.config.format
492
492
  }
493
493
  }));
494
- const htmlParts = tokensWithFormat.map((token) => this.renderToken(token));
494
+ const groupedTokens = this.groupListItems(tokensWithFormat);
495
+ const htmlParts = groupedTokens.map((token) => this.renderToken(token));
495
496
  const combinedHtml = htmlParts.join("");
496
497
  if (this.config.sanitize && !this.config.allowUnsafeHtml) {
497
498
  return sanitizeHtml(combinedHtml);
498
499
  }
499
500
  return combinedHtml;
500
501
  }
502
+ groupListItems(tokens) {
503
+ const result = [];
504
+ let i = 0;
505
+ while (i < tokens.length) {
506
+ const token = tokens[i];
507
+ const isListItem = token?.type === "list-item" || token?.type === "ordered-list-item" || token?.type === "task-item";
508
+ if (isListItem) {
509
+ const listItems = [];
510
+ const firstItemType = token.type;
511
+ const isOrdered = firstItemType === "ordered-list-item";
512
+ while (i < tokens.length) {
513
+ const item = tokens[i];
514
+ if (!item) break;
515
+ const itemType = item.type;
516
+ const isSameListType = isOrdered && itemType === "ordered-list-item" || !isOrdered && (itemType === "list-item" || itemType === "task-item");
517
+ if (isSameListType) {
518
+ listItems.push(item);
519
+ i++;
520
+ } else {
521
+ break;
522
+ }
523
+ }
524
+ const wrappedList = {
525
+ type: isOrdered ? "ol" : "ul",
526
+ content: "",
527
+ raw: "",
528
+ children: listItems,
529
+ attributes: { format: this.config.format }
530
+ };
531
+ wrappedList._isWrapped = true;
532
+ result.push(wrappedList);
533
+ } else {
534
+ result.push(token);
535
+ i++;
536
+ }
537
+ }
538
+ return result;
539
+ }
501
540
  renderToken(token) {
502
541
  const rule = this.rules.get(token.type);
503
542
  if (rule) {
504
543
  try {
505
544
  let tokenToRender = token;
506
545
  if (token.children && token.children.length > 0) {
507
- const renderedChildren = this.render(token.children);
546
+ const renderedChildren = token.type === "ul" || token.type === "ol" ? token.children.map((child) => this.renderToken(child)).join("") : this.render(token.children);
508
547
  tokenToRender = {
509
548
  ...token,
510
549
  attributes: {
@@ -1115,6 +1154,28 @@ var ListExtension = {
1115
1154
  }
1116
1155
  ],
1117
1156
  renderRules: [
1157
+ {
1158
+ type: "ul",
1159
+ render: (token) => {
1160
+ const format = token.attributes?.format || "tailwind";
1161
+ const content = token.attributes?.renderedChildren || "";
1162
+ if (format === "html") {
1163
+ return `<ul style="margin: 8px 0; padding-left: 24px; list-style: disc;">${content}</ul>`;
1164
+ }
1165
+ return `<ul class="my-2 pl-6 list-disc">${content}</ul>`;
1166
+ }
1167
+ },
1168
+ {
1169
+ type: "ol",
1170
+ render: (token) => {
1171
+ const format = token.attributes?.format || "tailwind";
1172
+ const content = token.attributes?.renderedChildren || "";
1173
+ if (format === "html") {
1174
+ return `<ol style="margin: 8px 0; padding-left: 24px; list-style: decimal;">${content}</ol>`;
1175
+ }
1176
+ return `<ol class="my-2 pl-6 list-decimal">${content}</ol>`;
1177
+ }
1178
+ },
1118
1179
  {
1119
1180
  type: "list-item",
1120
1181
  render: (token) => {
@@ -1163,15 +1224,20 @@ var TaskListExtension = {
1163
1224
  const isChecked = token.attributes?.checked === "true";
1164
1225
  const content = token.attributes?.renderedChildren || escapeHtml(token.content);
1165
1226
  const format = token.attributes?.format || "html";
1227
+ 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>`;
1228
+ 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>`;
1166
1229
  if (format === "html") {
1167
- return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
1168
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
1230
+ return `<div style="display: flex; align-items: flex-start; gap: 8px; margin: 8px 0;">
1231
+ <div style="color: ${isChecked ? "#10b981" : "#9ca3af"}; margin-top: 2px;">
1232
+ ${isChecked ? checkmark : checkbox}
1233
+ </div>
1169
1234
  <span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
1170
1235
  </div>`;
1171
1236
  }
1172
- return `<div class="flex items-center gap-2 my-2 task-list-item">
1173
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled
1174
- class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
1237
+ return `<div class="flex items-start gap-2 my-2 task-list-item">
1238
+ <div class="${isChecked ? "text-green-600" : "text-gray-400"} flex-shrink-0 mt-0.5">
1239
+ ${isChecked ? checkmark : checkbox}
1240
+ </div>
1175
1241
  <span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
1176
1242
  </div>`;
1177
1243
  }