@changerawr/markdown 1.1.3 → 1.1.5

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.
@@ -5,7 +5,8 @@ interface MarkdownToken {
5
5
  type: string;
6
6
  content: string;
7
7
  raw: string;
8
- attributes?: Record<string, string>;
8
+ attributes?: Record<string, string | number | boolean | Function | any>;
9
+ children?: MarkdownToken[];
9
10
  }
10
11
  interface ParseRule {
11
12
  name: string;
@@ -5,7 +5,8 @@ interface MarkdownToken {
5
5
  type: string;
6
6
  content: string;
7
7
  raw: string;
8
- attributes?: Record<string, string>;
8
+ attributes?: Record<string, string | number | boolean | Function | any>;
9
+ children?: MarkdownToken[];
9
10
  }
10
11
  interface ParseRule {
11
12
  name: string;
@@ -232,7 +232,8 @@ var MarkdownParser = class {
232
232
  }
233
233
  i = j;
234
234
  } else if (token) {
235
- processed.push(token);
235
+ const processedToken = this.recursivelyParseBlockContent(token);
236
+ processed.push(processedToken);
236
237
  i++;
237
238
  } else {
238
239
  i++;
@@ -240,6 +241,17 @@ var MarkdownParser = class {
240
241
  }
241
242
  return processed;
242
243
  }
244
+ recursivelyParseBlockContent(token) {
245
+ const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
246
+ if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
247
+ const children = this.parse(token.content);
248
+ return {
249
+ ...token,
250
+ children
251
+ };
252
+ }
253
+ return token;
254
+ }
243
255
  };
244
256
 
245
257
  // src/utils.ts
@@ -505,7 +517,19 @@ var MarkdownRenderer = class {
505
517
  const rule = this.rules.get(token.type);
506
518
  if (rule) {
507
519
  try {
508
- return rule.render(token);
520
+ let tokenToRender = token;
521
+ if (token.children && token.children.length > 0) {
522
+ const renderedChildren = this.render(token.children);
523
+ tokenToRender = {
524
+ ...token,
525
+ attributes: {
526
+ ...token.attributes,
527
+ renderedChildren
528
+ // Extensions can use this instead of re-parsing
529
+ }
530
+ };
531
+ }
532
+ return rule.render(tokenToRender);
509
533
  } catch (error) {
510
534
  const errorMessage = error instanceof Error ? error.message : String(error);
511
535
  this.warnings.push(`Render error for ${token.type}: ${errorMessage}`);
@@ -574,8 +598,10 @@ var BlockquoteExtension = {
574
598
  {
575
599
  type: "blockquote",
576
600
  render: (token) => {
577
- const content = escapeHtml(token.content);
578
601
  const format = token.attributes?.format || "html";
602
+ const renderedChildren = token.attributes?.renderedChildren;
603
+ const renderMarkdown = token.attributes?.renderMarkdown;
604
+ const content = renderedChildren || (renderMarkdown ? renderMarkdown(token.content) : escapeHtml(token.content));
579
605
  if (format === "html") {
580
606
  return `<blockquote style="border-left: 2px solid #d1d5db; padding: 8px 0 8px 16px; margin: 16px 0; font-style: italic; color: #6b7280;">${content}</blockquote>`;
581
607
  }
@@ -927,7 +953,14 @@ var ListExtension = {
927
953
  renderRules: [
928
954
  {
929
955
  type: "list-item",
930
- render: (token) => `<li>${escapeHtml(token.content)}</li>`
956
+ render: (token) => {
957
+ const format = token.attributes?.format || "tailwind";
958
+ const content = token.attributes?.renderedChildren || escapeHtml(token.content);
959
+ if (format === "html") {
960
+ return `<li>${content}</li>`;
961
+ }
962
+ return `<li>${content}</li>`;
963
+ }
931
964
  }
932
965
  ]
933
966
  };
@@ -952,18 +985,18 @@ var TaskListExtension = {
952
985
  type: "task-item",
953
986
  render: (token) => {
954
987
  const isChecked = token.attributes?.checked === "true";
955
- const escapedContent = escapeHtml(token.content);
988
+ const content = token.attributes?.renderedChildren || escapeHtml(token.content);
956
989
  const format = token.attributes?.format || "html";
957
990
  if (format === "html") {
958
991
  return `<div style="display: flex; align-items: center; gap: 8px; margin: 8px 0;">
959
992
  <input type="checkbox" ${isChecked ? "checked" : ""} disabled style="margin: 0;" />
960
- <span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${escapedContent}</span>
993
+ <span${isChecked ? ' style="text-decoration: line-through; color: #6b7280;"' : ""}>${content}</span>
961
994
  </div>`;
962
995
  }
963
996
  return `<div class="flex items-center gap-2 my-2 task-list-item">
964
- <input type="checkbox" ${isChecked ? "checked" : ""} disabled
997
+ <input type="checkbox" ${isChecked ? "checked" : ""} disabled
965
998
  class="form-checkbox h-4 w-4 rounded border-gray-300 text-primary focus:ring-primary" />
966
- <span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${escapedContent}</span>
999
+ <span${isChecked ? ' class="line-through text-muted-foreground"' : ""}>${content}</span>
967
1000
  </div>`;
968
1001
  }
969
1002
  }
@@ -1031,7 +1064,7 @@ var AlertExtension = {
1031
1064
  parseRules: [
1032
1065
  {
1033
1066
  name: "alert",
1034
- pattern: /:::(\w+)(?:\s+(.*?))?\s*\n([\s\S]*?)\n:::/,
1067
+ pattern: /:::(\w+)(?: ([^\n]+))?\n([\s\S]*?)\n:::/,
1035
1068
  render: (match) => {
1036
1069
  return {
1037
1070
  type: "alert",
@@ -1039,7 +1072,7 @@ var AlertExtension = {
1039
1072
  raw: match[0] || "",
1040
1073
  attributes: {
1041
1074
  type: match[1] || "info",
1042
- title: match[2] || ""
1075
+ title: match[2]?.trim() || ""
1043
1076
  }
1044
1077
  };
1045
1078
  }
@@ -1080,6 +1113,9 @@ var AlertExtension = {
1080
1113
  const config = typeConfig[type] || typeConfig.info;
1081
1114
  const baseClasses = "border-l-4 p-4 mb-4 rounded-md transition-colors duration-200";
1082
1115
  const classes = `${baseClasses} ${config?.classes}`;
1116
+ const renderedChildren = token.attributes?.renderedChildren;
1117
+ const renderMarkdown = token.attributes?.renderMarkdown;
1118
+ const renderedContent = renderedChildren || (renderMarkdown ? renderMarkdown(token.content) : token.content);
1083
1119
  const titleHtml = title ? `<div class="font-medium mb-2 flex items-center gap-2">
1084
1120
  <span class="text-lg" role="img" aria-label="${type}">${config?.icon}</span>
1085
1121
  <span>${title}</span>
@@ -1089,7 +1125,7 @@ var AlertExtension = {
1089
1125
  </div>`;
1090
1126
  return `<div class="${classes}" role="alert" aria-live="polite">
1091
1127
  ${titleHtml}
1092
- <div class="leading-relaxed">${token.content}</div>
1128
+ <div class="leading-relaxed">${renderedContent}</div>
1093
1129
  </div>`;
1094
1130
  }
1095
1131
  }