@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.
package/dist/index.d.mts CHANGED
@@ -523,6 +523,7 @@ declare class MarkdownRenderer {
523
523
  addRule(rule: RenderRule): void;
524
524
  hasRule(type: string): boolean;
525
525
  render(tokens: MarkdownToken[]): string;
526
+ private groupListItems;
526
527
  private renderToken;
527
528
  private createErrorBlock;
528
529
  private createDebugBlock;
package/dist/index.d.ts CHANGED
@@ -523,6 +523,7 @@ declare class MarkdownRenderer {
523
523
  addRule(rule: RenderRule): void;
524
524
  hasRule(type: string): boolean;
525
525
  render(tokens: MarkdownToken[]): string;
526
+ private groupListItems;
526
527
  private renderToken;
527
528
  private createErrorBlock;
528
529
  private createDebugBlock;
package/dist/index.js CHANGED
@@ -676,20 +676,59 @@ var MarkdownRenderer = class {
676
676
  format: this.config.format
677
677
  }
678
678
  }));
679
- const htmlParts = tokensWithFormat.map((token) => this.renderToken(token));
679
+ const groupedTokens = this.groupListItems(tokensWithFormat);
680
+ const htmlParts = groupedTokens.map((token) => this.renderToken(token));
680
681
  const combinedHtml = htmlParts.join("");
681
682
  if (this.config.sanitize && !this.config.allowUnsafeHtml) {
682
683
  return sanitizeHtml(combinedHtml);
683
684
  }
684
685
  return combinedHtml;
685
686
  }
687
+ groupListItems(tokens) {
688
+ const result = [];
689
+ let i = 0;
690
+ while (i < tokens.length) {
691
+ const token = tokens[i];
692
+ const isListItem = token?.type === "list-item" || token?.type === "ordered-list-item" || token?.type === "task-item";
693
+ if (isListItem) {
694
+ const listItems = [];
695
+ const firstItemType = token.type;
696
+ const isOrdered = firstItemType === "ordered-list-item";
697
+ while (i < tokens.length) {
698
+ const item = tokens[i];
699
+ if (!item) break;
700
+ const itemType = item.type;
701
+ const isSameListType = isOrdered && itemType === "ordered-list-item" || !isOrdered && (itemType === "list-item" || itemType === "task-item");
702
+ if (isSameListType) {
703
+ listItems.push(item);
704
+ i++;
705
+ } else {
706
+ break;
707
+ }
708
+ }
709
+ const wrappedList = {
710
+ type: isOrdered ? "ol" : "ul",
711
+ content: "",
712
+ raw: "",
713
+ children: listItems,
714
+ attributes: { format: this.config.format }
715
+ };
716
+ wrappedList._isWrapped = true;
717
+ result.push(wrappedList);
718
+ } else {
719
+ result.push(token);
720
+ i++;
721
+ }
722
+ }
723
+ return result;
724
+ }
686
725
  renderToken(token) {
687
726
  const rule = this.rules.get(token.type);
688
727
  if (rule) {
689
728
  try {
690
729
  let tokenToRender = token;
691
730
  if (token.children && token.children.length > 0) {
692
- const renderedChildren = this.render(token.children);
731
+ const renderedChildren = token.type === "ul" || token.type === "ol" ? token.children.map((child) => this.renderToken(child)).join("") : this.render(token.children);
693
732
  tokenToRender = {
694
733
  ...token,
695
734
  attributes: {
@@ -1317,6 +1356,28 @@ var ListExtension = {
1317
1356
  }
1318
1357
  ],
1319
1358
  renderRules: [
1359
+ {
1360
+ type: "ul",
1361
+ render: (token) => {
1362
+ const format = token.attributes?.format || "tailwind";
1363
+ const content = token.attributes?.renderedChildren || "";
1364
+ if (format === "html") {
1365
+ return `<ul style="margin: 8px 0; padding-left: 24px; list-style: disc;">${content}</ul>`;
1366
+ }
1367
+ return `<ul class="my-2 pl-6 list-disc">${content}</ul>`;
1368
+ }
1369
+ },
1370
+ {
1371
+ type: "ol",
1372
+ render: (token) => {
1373
+ const format = token.attributes?.format || "tailwind";
1374
+ const content = token.attributes?.renderedChildren || "";
1375
+ if (format === "html") {
1376
+ return `<ol style="margin: 8px 0; padding-left: 24px; list-style: decimal;">${content}</ol>`;
1377
+ }
1378
+ return `<ol class="my-2 pl-6 list-decimal">${content}</ol>`;
1379
+ }
1380
+ },
1320
1381
  {
1321
1382
  type: "list-item",
1322
1383
  render: (token) => {
@@ -1365,15 +1426,20 @@ var TaskListExtension = {
1365
1426
  const isChecked = token.attributes?.checked === "true";
1366
1427
  const content = token.attributes?.renderedChildren || escapeHtml(token.content);
1367
1428
  const format = token.attributes?.format || "html";
1429
+ 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>`;
1430
+ 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>`;
1368
1431
  if (format === "html") {
1369
- return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
1370
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
1432
+ return `<div style="display: flex; align-items: flex-start; gap: 8px; margin: 8px 0;">
1433
+ <div style="color: ${isChecked ? "#10b981" : "#9ca3af"}; margin-top: 2px;">
1434
+ ${isChecked ? checkmark : checkbox}
1435
+ </div>
1371
1436
  <span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
1372
1437
  </div>`;
1373
1438
  }
1374
- return `<div class="flex items-center gap-2 my-2 task-list-item">
1375
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled
1376
- class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
1439
+ return `<div class="flex items-start gap-2 my-2 task-list-item">
1440
+ <div class="${isChecked ? "text-green-600" : "text-gray-400"} flex-shrink-0 mt-0.5">
1441
+ ${isChecked ? checkmark : checkbox}
1442
+ </div>
1377
1443
  <span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
1378
1444
  </div>`;
1379
1445
  }