@changerawr/markdown 1.1.6 → 1.1.8

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.
@@ -1,5 +1,5 @@
1
1
  // src/parser.ts
2
- var MarkdownParser = class {
2
+ var MarkdownParser = class _MarkdownParser {
3
3
  // Cache compiled regexes
4
4
  constructor(config) {
5
5
  this.rules = [];
@@ -212,7 +212,18 @@ var MarkdownParser = class {
212
212
  recursivelyParseBlockContent(token) {
213
213
  const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
214
214
  if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
215
- const children = this.parse(token.content);
215
+ let children;
216
+ if ((token.type === "list-item" || token.type === "task-item") && this.rules.some((r) => r.name === "list-item")) {
217
+ const parserWithoutListRule = new _MarkdownParser(this.config);
218
+ this.rules.forEach((rule) => {
219
+ if (rule.name !== "list-item" && rule.name !== "task-item") {
220
+ parserWithoutListRule.addRule(rule);
221
+ }
222
+ });
223
+ children = parserWithoutListRule.parse(token.content);
224
+ } else {
225
+ children = this.parse(token.content);
226
+ }
216
227
  return {
217
228
  ...token,
218
229
  children
@@ -988,7 +999,8 @@ var ImageExtension = {
988
999
  attributes: {
989
1000
  alt: match[1] || "",
990
1001
  src: match[2] || "",
991
- title: match[3] || ""
1002
+ caption: match[3] || ""
1003
+ // Renamed from 'title' to 'caption' for clarity
992
1004
  }
993
1005
  })
994
1006
  }
@@ -999,13 +1011,24 @@ var ImageExtension = {
999
1011
  render: (token) => {
1000
1012
  const src = token.attributes?.src || "";
1001
1013
  const alt = token.attributes?.alt || "";
1002
- const title = token.attributes?.title || "";
1003
- const titleAttr = title ? ` title="${escapeHtml(title)}"` : "";
1014
+ const caption = token.attributes?.caption || "";
1004
1015
  const format = token.attributes?.format || "html";
1016
+ if (caption) {
1017
+ if (format === "html") {
1018
+ return `<figure style="margin: 16px 0; text-align: center;">
1019
+ <img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" style="max-width: 100%; height: auto; border-radius: 8px;" loading="lazy" />
1020
+ <figcaption style="margin-top: 8px; font-size: 14px; color: #6b7280; font-style: italic;">${escapeHtml(caption)}</figcaption>
1021
+ </figure>`;
1022
+ }
1023
+ return `<figure class="my-4 text-center">
1024
+ <img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" class="max-w-full h-auto rounded-lg" loading="lazy" />
1025
+ <figcaption class="mt-2 text-sm text-gray-500 italic">${escapeHtml(caption)}</figcaption>
1026
+ </figure>`;
1027
+ }
1005
1028
  if (format === "html") {
1006
- return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}"${titleAttr} style="max-width: 100%; height: auto; border-radius: 8px; margin: 16px 0;" loading="lazy" />`;
1029
+ return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" style="max-width: 100%; height: auto; border-radius: 8px; margin: 16px 0;" loading="lazy" />`;
1007
1030
  }
1008
- return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}"${titleAttr} class="max-w-full h-auto rounded-lg my-4" loading="lazy" />`;
1031
+ return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" class="max-w-full h-auto rounded-lg my-4" loading="lazy" />`;
1009
1032
  }
1010
1033
  }
1011
1034
  ]
@@ -1057,12 +1080,31 @@ var ListExtension = {
1057
1080
  name: "list",
1058
1081
  parseRules: [
1059
1082
  {
1060
- name: "list-item",
1083
+ name: "unordered-list-item",
1061
1084
  pattern: /^(\s*)[-*+]\s+(.+)$/m,
1062
1085
  render: (match) => ({
1063
1086
  type: "list-item",
1064
1087
  content: match[2] || "",
1065
- raw: match[0] || ""
1088
+ raw: match[0] || "",
1089
+ attributes: {
1090
+ indent: match[1]?.length || 0,
1091
+ ordered: false,
1092
+ marker: match[1] ? match[0].match(/[-*+]/)?.[0] : "-"
1093
+ }
1094
+ })
1095
+ },
1096
+ {
1097
+ name: "ordered-list-item",
1098
+ pattern: /^(\s*)(\d+)\.\s+(.+)$/m,
1099
+ render: (match) => ({
1100
+ type: "ordered-list-item",
1101
+ content: match[3] || "",
1102
+ raw: match[0] || "",
1103
+ attributes: {
1104
+ indent: match[1]?.length || 0,
1105
+ ordered: true,
1106
+ number: parseInt(match[2] || "1")
1107
+ }
1066
1108
  })
1067
1109
  }
1068
1110
  ],
@@ -1077,6 +1119,17 @@ var ListExtension = {
1077
1119
  }
1078
1120
  return `<li>${content}</li>`;
1079
1121
  }
1122
+ },
1123
+ {
1124
+ type: "ordered-list-item",
1125
+ render: (token) => {
1126
+ const format = token.attributes?.format || "tailwind";
1127
+ const content = token.attributes?.renderedChildren || escapeHtml(token.content);
1128
+ if (format === "html") {
1129
+ return `<li>${content}</li>`;
1130
+ }
1131
+ return `<li>${content}</li>`;
1132
+ }
1080
1133
  }
1081
1134
  ]
1082
1135
  };
@@ -1091,6 +1144,7 @@ var TaskListExtension = {
1091
1144
  content: match[3] || "",
1092
1145
  raw: match[0] || "",
1093
1146
  attributes: {
1147
+ indent: match[1]?.length || 0,
1094
1148
  checked: String((match[2] || "").toLowerCase() === "x")
1095
1149
  }
1096
1150
  })
@@ -1156,6 +1210,35 @@ var TextExtension = {
1156
1210
  ]
1157
1211
  };
1158
1212
 
1213
+ // src/extensions/core/strikethrough.ts
1214
+ var StrikethroughExtension = {
1215
+ name: "strikethrough",
1216
+ parseRules: [
1217
+ {
1218
+ name: "strikethrough",
1219
+ pattern: /~~((?:(?!~~).)+)~~/,
1220
+ render: (match) => ({
1221
+ type: "strikethrough",
1222
+ content: match[1] || "",
1223
+ raw: match[0] || ""
1224
+ })
1225
+ }
1226
+ ],
1227
+ renderRules: [
1228
+ {
1229
+ type: "strikethrough",
1230
+ render: (token) => {
1231
+ const content = escapeHtml(token.content);
1232
+ const format = token.attributes?.format;
1233
+ if (format === "html") {
1234
+ return `<del style="text-decoration: line-through; color: #6b7280;">${content}</del>`;
1235
+ }
1236
+ return `<del class="line-through text-gray-500">${content}</del>`;
1237
+ }
1238
+ }
1239
+ ]
1240
+ };
1241
+
1159
1242
  // src/extensions/core/index.ts
1160
1243
  var CoreExtensions = [
1161
1244
  TextExtension,
@@ -1170,6 +1253,7 @@ var CoreExtensions = [
1170
1253
  TaskListExtension,
1171
1254
  BlockquoteExtension,
1172
1255
  HorizontalRuleExtension,
1256
+ StrikethroughExtension,
1173
1257
  ParagraphExtension,
1174
1258
  LineBreakExtension
1175
1259
  ];