@changerawr/markdown 1.1.8 → 1.1.10

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.
@@ -210,13 +210,13 @@ var MarkdownParser = class _MarkdownParser {
210
210
  return processed;
211
211
  }
212
212
  recursivelyParseBlockContent(token) {
213
- const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
213
+ const blockTypes = ["alert", "blockquote", "list-item", "ordered-list-item", "task-item"];
214
214
  if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
215
215
  let children;
216
- if ((token.type === "list-item" || token.type === "task-item") && this.rules.some((r) => r.name === "list-item")) {
216
+ if ((token.type === "list-item" || token.type === "ordered-list-item" || token.type === "task-item") && this.rules.some((r) => r.name === "unordered-list-item" || r.name === "ordered-list-item" || r.name === "task-item")) {
217
217
  const parserWithoutListRule = new _MarkdownParser(this.config);
218
218
  this.rules.forEach((rule) => {
219
- if (rule.name !== "list-item" && rule.name !== "task-item") {
219
+ if (rule.name !== "unordered-list-item" && rule.name !== "ordered-list-item" && rule.name !== "task-item") {
220
220
  parserWithoutListRule.addRule(rule);
221
221
  }
222
222
  });
@@ -485,20 +485,59 @@ var MarkdownRenderer = class {
485
485
  format: this.config.format
486
486
  }
487
487
  }));
488
- const htmlParts = tokensWithFormat.map((token) => this.renderToken(token));
488
+ const groupedTokens = this.groupListItems(tokensWithFormat);
489
+ const htmlParts = groupedTokens.map((token) => this.renderToken(token));
489
490
  const combinedHtml = htmlParts.join("");
490
491
  if (this.config.sanitize && !this.config.allowUnsafeHtml) {
491
492
  return sanitizeHtml(combinedHtml);
492
493
  }
493
494
  return combinedHtml;
494
495
  }
496
+ groupListItems(tokens) {
497
+ const result = [];
498
+ let i = 0;
499
+ while (i < tokens.length) {
500
+ const token = tokens[i];
501
+ const isListItem = token?.type === "list-item" || token?.type === "ordered-list-item" || token?.type === "task-item";
502
+ if (isListItem) {
503
+ const listItems = [];
504
+ const firstItemType = token.type;
505
+ const isOrdered = firstItemType === "ordered-list-item";
506
+ while (i < tokens.length) {
507
+ const item = tokens[i];
508
+ if (!item) break;
509
+ const itemType = item.type;
510
+ const isSameListType = isOrdered && itemType === "ordered-list-item" || !isOrdered && (itemType === "list-item" || itemType === "task-item");
511
+ if (isSameListType) {
512
+ listItems.push(item);
513
+ i++;
514
+ } else {
515
+ break;
516
+ }
517
+ }
518
+ const wrappedList = {
519
+ type: isOrdered ? "ol" : "ul",
520
+ content: "",
521
+ raw: "",
522
+ children: listItems,
523
+ attributes: { format: this.config.format }
524
+ };
525
+ wrappedList._isWrapped = true;
526
+ result.push(wrappedList);
527
+ } else {
528
+ result.push(token);
529
+ i++;
530
+ }
531
+ }
532
+ return result;
533
+ }
495
534
  renderToken(token) {
496
535
  const rule = this.rules.get(token.type);
497
536
  if (rule) {
498
537
  try {
499
538
  let tokenToRender = token;
500
539
  if (token.children && token.children.length > 0) {
501
- const renderedChildren = this.render(token.children);
540
+ const renderedChildren = token.type === "ul" || token.type === "ol" ? token.children.map((child) => this.renderToken(child)).join("") : this.render(token.children);
502
541
  tokenToRender = {
503
542
  ...token,
504
543
  attributes: {
@@ -1109,6 +1148,28 @@ var ListExtension = {
1109
1148
  }
1110
1149
  ],
1111
1150
  renderRules: [
1151
+ {
1152
+ type: "ul",
1153
+ render: (token) => {
1154
+ const format = token.attributes?.format || "tailwind";
1155
+ const content = token.attributes?.renderedChildren || "";
1156
+ if (format === "html") {
1157
+ return `<ul style="margin: 8px 0; padding-left: 24px; list-style: disc;">${content}</ul>`;
1158
+ }
1159
+ return `<ul class="my-2 pl-6 list-disc">${content}</ul>`;
1160
+ }
1161
+ },
1162
+ {
1163
+ type: "ol",
1164
+ render: (token) => {
1165
+ const format = token.attributes?.format || "tailwind";
1166
+ const content = token.attributes?.renderedChildren || "";
1167
+ if (format === "html") {
1168
+ return `<ol style="margin: 8px 0; padding-left: 24px; list-style: decimal;">${content}</ol>`;
1169
+ }
1170
+ return `<ol class="my-2 pl-6 list-decimal">${content}</ol>`;
1171
+ }
1172
+ },
1112
1173
  {
1113
1174
  type: "list-item",
1114
1175
  render: (token) => {
@@ -1157,15 +1218,20 @@ var TaskListExtension = {
1157
1218
  const isChecked = token.attributes?.checked === "true";
1158
1219
  const content = token.attributes?.renderedChildren || escapeHtml(token.content);
1159
1220
  const format = token.attributes?.format || "html";
1221
+ 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>`;
1222
+ 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>`;
1160
1223
  if (format === "html") {
1161
- return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
1162
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
1224
+ return `<div style="display: flex; align-items: flex-start; gap: 8px; margin: 8px 0;">
1225
+ <div style="color: ${isChecked ? "#10b981" : "#9ca3af"}; margin-top: 2px;">
1226
+ ${isChecked ? checkmark : checkbox}
1227
+ </div>
1163
1228
  <span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
1164
1229
  </div>`;
1165
1230
  }
1166
- return `<div class="flex items-center gap-2 my-2 task-list-item">
1167
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled
1168
- class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
1231
+ return `<div class="flex items-start gap-2 my-2 task-list-item">
1232
+ <div class="${isChecked ? "text-green-600" : "text-gray-400"} flex-shrink-0 mt-0.5">
1233
+ ${isChecked ? checkmark : checkbox}
1234
+ </div>
1169
1235
  <span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
1170
1236
  </div>`;
1171
1237
  }