@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.
@@ -255,13 +255,13 @@ var MarkdownParser = class _MarkdownParser {
255
255
  return processed;
256
256
  }
257
257
  recursivelyParseBlockContent(token) {
258
- const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
258
+ const blockTypes = ["alert", "blockquote", "list-item", "ordered-list-item", "task-item"];
259
259
  if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
260
260
  let children;
261
- if ((token.type === "list-item" || token.type === "task-item") && this.rules.some((r) => r.name === "list-item")) {
261
+ 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")) {
262
262
  const parserWithoutListRule = new _MarkdownParser(this.config);
263
263
  this.rules.forEach((rule) => {
264
- if (rule.name !== "list-item" && rule.name !== "task-item") {
264
+ if (rule.name !== "unordered-list-item" && rule.name !== "ordered-list-item" && rule.name !== "task-item") {
265
265
  parserWithoutListRule.addRule(rule);
266
266
  }
267
267
  });
@@ -530,20 +530,59 @@ var MarkdownRenderer = class {
530
530
  format: this.config.format
531
531
  }
532
532
  }));
533
- const htmlParts = tokensWithFormat.map((token) => this.renderToken(token));
533
+ const groupedTokens = this.groupListItems(tokensWithFormat);
534
+ const htmlParts = groupedTokens.map((token) => this.renderToken(token));
534
535
  const combinedHtml = htmlParts.join("");
535
536
  if (this.config.sanitize && !this.config.allowUnsafeHtml) {
536
537
  return sanitizeHtml(combinedHtml);
537
538
  }
538
539
  return combinedHtml;
539
540
  }
541
+ groupListItems(tokens) {
542
+ const result = [];
543
+ let i = 0;
544
+ while (i < tokens.length) {
545
+ const token = tokens[i];
546
+ const isListItem = token?.type === "list-item" || token?.type === "ordered-list-item" || token?.type === "task-item";
547
+ if (isListItem) {
548
+ const listItems = [];
549
+ const firstItemType = token.type;
550
+ const isOrdered = firstItemType === "ordered-list-item";
551
+ while (i < tokens.length) {
552
+ const item = tokens[i];
553
+ if (!item) break;
554
+ const itemType = item.type;
555
+ const isSameListType = isOrdered && itemType === "ordered-list-item" || !isOrdered && (itemType === "list-item" || itemType === "task-item");
556
+ if (isSameListType) {
557
+ listItems.push(item);
558
+ i++;
559
+ } else {
560
+ break;
561
+ }
562
+ }
563
+ const wrappedList = {
564
+ type: isOrdered ? "ol" : "ul",
565
+ content: "",
566
+ raw: "",
567
+ children: listItems,
568
+ attributes: { format: this.config.format }
569
+ };
570
+ wrappedList._isWrapped = true;
571
+ result.push(wrappedList);
572
+ } else {
573
+ result.push(token);
574
+ i++;
575
+ }
576
+ }
577
+ return result;
578
+ }
540
579
  renderToken(token) {
541
580
  const rule = this.rules.get(token.type);
542
581
  if (rule) {
543
582
  try {
544
583
  let tokenToRender = token;
545
584
  if (token.children && token.children.length > 0) {
546
- const renderedChildren = this.render(token.children);
585
+ const renderedChildren = token.type === "ul" || token.type === "ol" ? token.children.map((child) => this.renderToken(child)).join("") : this.render(token.children);
547
586
  tokenToRender = {
548
587
  ...token,
549
588
  attributes: {
@@ -1154,6 +1193,28 @@ var ListExtension = {
1154
1193
  }
1155
1194
  ],
1156
1195
  renderRules: [
1196
+ {
1197
+ type: "ul",
1198
+ render: (token) => {
1199
+ const format = token.attributes?.format || "tailwind";
1200
+ const content = token.attributes?.renderedChildren || "";
1201
+ if (format === "html") {
1202
+ return `<ul style="margin: 8px 0; padding-left: 24px; list-style: disc;">${content}</ul>`;
1203
+ }
1204
+ return `<ul class="my-2 pl-6 list-disc">${content}</ul>`;
1205
+ }
1206
+ },
1207
+ {
1208
+ type: "ol",
1209
+ render: (token) => {
1210
+ const format = token.attributes?.format || "tailwind";
1211
+ const content = token.attributes?.renderedChildren || "";
1212
+ if (format === "html") {
1213
+ return `<ol style="margin: 8px 0; padding-left: 24px; list-style: decimal;">${content}</ol>`;
1214
+ }
1215
+ return `<ol class="my-2 pl-6 list-decimal">${content}</ol>`;
1216
+ }
1217
+ },
1157
1218
  {
1158
1219
  type: "list-item",
1159
1220
  render: (token) => {
@@ -1202,15 +1263,20 @@ var TaskListExtension = {
1202
1263
  const isChecked = token.attributes?.checked === "true";
1203
1264
  const content = token.attributes?.renderedChildren || escapeHtml(token.content);
1204
1265
  const format = token.attributes?.format || "html";
1266
+ 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>`;
1267
+ 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>`;
1205
1268
  if (format === "html") {
1206
- return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
1207
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
1269
+ return `<div style="display: flex; align-items: flex-start; gap: 8px; margin: 8px 0;">
1270
+ <div style="color: ${isChecked ? "#10b981" : "#9ca3af"}; margin-top: 2px;">
1271
+ ${isChecked ? checkmark : checkbox}
1272
+ </div>
1208
1273
  <span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
1209
1274
  </div>`;
1210
1275
  }
1211
- return `<div class="flex items-center gap-2 my-2 task-list-item">
1212
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled
1213
- class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
1276
+ return `<div class="flex items-start gap-2 my-2 task-list-item">
1277
+ <div class="${isChecked ? "text-green-600" : "text-gray-400"} flex-shrink-0 mt-0.5">
1278
+ ${isChecked ? checkmark : checkbox}
1279
+ </div>
1214
1280
  <span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
1215
1281
  </div>`;
1216
1282
  }