@changerawr/markdown 1.1.2 → 1.1.4

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.
@@ -6,6 +6,7 @@ interface MarkdownToken {
6
6
  content: string;
7
7
  raw: string;
8
8
  attributes?: Record<string, string>;
9
+ children?: MarkdownToken[];
9
10
  }
10
11
  interface ParseRule {
11
12
  name: string;
@@ -6,6 +6,7 @@ interface MarkdownToken {
6
6
  content: string;
7
7
  raw: string;
8
8
  attributes?: Record<string, string>;
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"];
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
  }
@@ -1080,6 +1106,9 @@ var AlertExtension = {
1080
1106
  const config = typeConfig[type] || typeConfig.info;
1081
1107
  const baseClasses = "border-l-4 p-4 mb-4 rounded-md transition-colors duration-200";
1082
1108
  const classes = `${baseClasses} ${config?.classes}`;
1109
+ const renderedChildren = token.attributes?.renderedChildren;
1110
+ const renderMarkdown = token.attributes?.renderMarkdown;
1111
+ const renderedContent = renderedChildren || (renderMarkdown ? renderMarkdown(token.content) : token.content);
1083
1112
  const titleHtml = title ? `<div class="font-medium mb-2 flex items-center gap-2">
1084
1113
  <span class="text-lg" role="img" aria-label="${type}">${config?.icon}</span>
1085
1114
  <span>${title}</span>
@@ -1089,7 +1118,7 @@ var AlertExtension = {
1089
1118
  </div>`;
1090
1119
  return `<div class="${classes}" role="alert" aria-live="polite">
1091
1120
  ${titleHtml}
1092
- <div class="leading-relaxed">${token.content}</div>
1121
+ <div class="leading-relaxed">${renderedContent}</div>
1093
1122
  </div>`;
1094
1123
  }
1095
1124
  }