@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.
@@ -44,7 +44,7 @@ var import_react2 = __toESM(require("react"));
44
44
  var import_react = require("react");
45
45
 
46
46
  // src/parser.ts
47
- var MarkdownParser = class {
47
+ var MarkdownParser = class _MarkdownParser {
48
48
  // Cache compiled regexes
49
49
  constructor(config) {
50
50
  this.rules = [];
@@ -257,7 +257,18 @@ var MarkdownParser = class {
257
257
  recursivelyParseBlockContent(token) {
258
258
  const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
259
259
  if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
260
- const children = this.parse(token.content);
260
+ let children;
261
+ if ((token.type === "list-item" || token.type === "task-item") && this.rules.some((r) => r.name === "list-item")) {
262
+ const parserWithoutListRule = new _MarkdownParser(this.config);
263
+ this.rules.forEach((rule) => {
264
+ if (rule.name !== "list-item" && rule.name !== "task-item") {
265
+ parserWithoutListRule.addRule(rule);
266
+ }
267
+ });
268
+ children = parserWithoutListRule.parse(token.content);
269
+ } else {
270
+ children = this.parse(token.content);
271
+ }
261
272
  return {
262
273
  ...token,
263
274
  children
@@ -1033,7 +1044,8 @@ var ImageExtension = {
1033
1044
  attributes: {
1034
1045
  alt: match[1] || "",
1035
1046
  src: match[2] || "",
1036
- title: match[3] || ""
1047
+ caption: match[3] || ""
1048
+ // Renamed from 'title' to 'caption' for clarity
1037
1049
  }
1038
1050
  })
1039
1051
  }
@@ -1044,13 +1056,24 @@ var ImageExtension = {
1044
1056
  render: (token) => {
1045
1057
  const src = token.attributes?.src || "";
1046
1058
  const alt = token.attributes?.alt || "";
1047
- const title = token.attributes?.title || "";
1048
- const titleAttr = title ? ` title="${escapeHtml(title)}"` : "";
1059
+ const caption = token.attributes?.caption || "";
1049
1060
  const format = token.attributes?.format || "html";
1061
+ if (caption) {
1062
+ if (format === "html") {
1063
+ return `<figure style="margin: 16px 0; text-align: center;">
1064
+ <img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" style="max-width: 100%; height: auto; border-radius: 8px;" loading="lazy" />
1065
+ <figcaption style="margin-top: 8px; font-size: 14px; color: #6b7280; font-style: italic;">${escapeHtml(caption)}</figcaption>
1066
+ </figure>`;
1067
+ }
1068
+ return `<figure class="my-4 text-center">
1069
+ <img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" class="max-w-full h-auto rounded-lg" loading="lazy" />
1070
+ <figcaption class="mt-2 text-sm text-gray-500 italic">${escapeHtml(caption)}</figcaption>
1071
+ </figure>`;
1072
+ }
1050
1073
  if (format === "html") {
1051
- return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}"${titleAttr} style="max-width: 100%; height: auto; border-radius: 8px; margin: 16px 0;" loading="lazy" />`;
1074
+ return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" style="max-width: 100%; height: auto; border-radius: 8px; margin: 16px 0;" loading="lazy" />`;
1052
1075
  }
1053
- return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}"${titleAttr} class="max-w-full h-auto rounded-lg my-4" loading="lazy" />`;
1076
+ return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" class="max-w-full h-auto rounded-lg my-4" loading="lazy" />`;
1054
1077
  }
1055
1078
  }
1056
1079
  ]
@@ -1102,12 +1125,31 @@ var ListExtension = {
1102
1125
  name: "list",
1103
1126
  parseRules: [
1104
1127
  {
1105
- name: "list-item",
1128
+ name: "unordered-list-item",
1106
1129
  pattern: /^(\s*)[-*+]\s+(.+)$/m,
1107
1130
  render: (match) => ({
1108
1131
  type: "list-item",
1109
1132
  content: match[2] || "",
1110
- raw: match[0] || ""
1133
+ raw: match[0] || "",
1134
+ attributes: {
1135
+ indent: match[1]?.length || 0,
1136
+ ordered: false,
1137
+ marker: match[1] ? match[0].match(/[-*+]/)?.[0] : "-"
1138
+ }
1139
+ })
1140
+ },
1141
+ {
1142
+ name: "ordered-list-item",
1143
+ pattern: /^(\s*)(\d+)\.\s+(.+)$/m,
1144
+ render: (match) => ({
1145
+ type: "ordered-list-item",
1146
+ content: match[3] || "",
1147
+ raw: match[0] || "",
1148
+ attributes: {
1149
+ indent: match[1]?.length || 0,
1150
+ ordered: true,
1151
+ number: parseInt(match[2] || "1")
1152
+ }
1111
1153
  })
1112
1154
  }
1113
1155
  ],
@@ -1122,6 +1164,17 @@ var ListExtension = {
1122
1164
  }
1123
1165
  return `<li>${content}</li>`;
1124
1166
  }
1167
+ },
1168
+ {
1169
+ type: "ordered-list-item",
1170
+ render: (token) => {
1171
+ const format = token.attributes?.format || "tailwind";
1172
+ const content = token.attributes?.renderedChildren || escapeHtml(token.content);
1173
+ if (format === "html") {
1174
+ return `<li>${content}</li>`;
1175
+ }
1176
+ return `<li>${content}</li>`;
1177
+ }
1125
1178
  }
1126
1179
  ]
1127
1180
  };
@@ -1136,6 +1189,7 @@ var TaskListExtension = {
1136
1189
  content: match[3] || "",
1137
1190
  raw: match[0] || "",
1138
1191
  attributes: {
1192
+ indent: match[1]?.length || 0,
1139
1193
  checked: String((match[2] || "").toLowerCase() === "x")
1140
1194
  }
1141
1195
  })
@@ -1201,6 +1255,35 @@ var TextExtension = {
1201
1255
  ]
1202
1256
  };
1203
1257
 
1258
+ // src/extensions/core/strikethrough.ts
1259
+ var StrikethroughExtension = {
1260
+ name: "strikethrough",
1261
+ parseRules: [
1262
+ {
1263
+ name: "strikethrough",
1264
+ pattern: /~~((?:(?!~~).)+)~~/,
1265
+ render: (match) => ({
1266
+ type: "strikethrough",
1267
+ content: match[1] || "",
1268
+ raw: match[0] || ""
1269
+ })
1270
+ }
1271
+ ],
1272
+ renderRules: [
1273
+ {
1274
+ type: "strikethrough",
1275
+ render: (token) => {
1276
+ const content = escapeHtml(token.content);
1277
+ const format = token.attributes?.format;
1278
+ if (format === "html") {
1279
+ return `<del style="text-decoration: line-through; color: #6b7280;">${content}</del>`;
1280
+ }
1281
+ return `<del class="line-through text-gray-500">${content}</del>`;
1282
+ }
1283
+ }
1284
+ ]
1285
+ };
1286
+
1204
1287
  // src/extensions/core/index.ts
1205
1288
  var CoreExtensions = [
1206
1289
  TextExtension,
@@ -1215,6 +1298,7 @@ var CoreExtensions = [
1215
1298
  TaskListExtension,
1216
1299
  BlockquoteExtension,
1217
1300
  HorizontalRuleExtension,
1301
+ StrikethroughExtension,
1218
1302
  ParagraphExtension,
1219
1303
  LineBreakExtension
1220
1304
  ];