@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.
package/dist/index.d.mts CHANGED
@@ -564,7 +564,7 @@ declare const ParagraphExtension: Extension;
564
564
 
565
565
  declare const TextExtension: Extension;
566
566
 
567
- declare const CoreExtensions: readonly [Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension];
567
+ declare const CoreExtensions: readonly [Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension];
568
568
 
569
569
  /**
570
570
  * @changerawr/markdown - Main package exports
@@ -623,7 +623,7 @@ declare const markdown: {
623
623
  readonly parseCum: typeof parseCum;
624
624
  readonly ChangerawrMarkdown: typeof ChangerawrMarkdown;
625
625
  readonly extensions: {
626
- readonly core: readonly [Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension];
626
+ readonly core: readonly [Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension];
627
627
  readonly Text: Extension;
628
628
  readonly Heading: Extension;
629
629
  readonly Bold: Extension;
package/dist/index.d.ts CHANGED
@@ -564,7 +564,7 @@ declare const ParagraphExtension: Extension;
564
564
 
565
565
  declare const TextExtension: Extension;
566
566
 
567
- declare const CoreExtensions: readonly [Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension];
567
+ declare const CoreExtensions: readonly [Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension];
568
568
 
569
569
  /**
570
570
  * @changerawr/markdown - Main package exports
@@ -623,7 +623,7 @@ declare const markdown: {
623
623
  readonly parseCum: typeof parseCum;
624
624
  readonly ChangerawrMarkdown: typeof ChangerawrMarkdown;
625
625
  readonly extensions: {
626
- readonly core: readonly [Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension];
626
+ readonly core: readonly [Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension, Extension];
627
627
  readonly Text: Extension;
628
628
  readonly Heading: Extension;
629
629
  readonly Bold: Extension;
package/dist/index.js CHANGED
@@ -110,7 +110,7 @@ __export(index_exports, {
110
110
  module.exports = __toCommonJS(index_exports);
111
111
 
112
112
  // src/parser.ts
113
- var MarkdownParser = class {
113
+ var MarkdownParser = class _MarkdownParser {
114
114
  // Cache compiled regexes
115
115
  constructor(config) {
116
116
  this.rules = [];
@@ -323,7 +323,18 @@ var MarkdownParser = class {
323
323
  recursivelyParseBlockContent(token) {
324
324
  const blockTypes = ["alert", "blockquote", "list-item", "task-item"];
325
325
  if (blockTypes.includes(token.type) && token.content && token.content.trim()) {
326
- const children = this.parse(token.content);
326
+ let children;
327
+ if ((token.type === "list-item" || token.type === "task-item") && this.rules.some((r) => r.name === "list-item")) {
328
+ const parserWithoutListRule = new _MarkdownParser(this.config);
329
+ this.rules.forEach((rule) => {
330
+ if (rule.name !== "list-item" && rule.name !== "task-item") {
331
+ parserWithoutListRule.addRule(rule);
332
+ }
333
+ });
334
+ children = parserWithoutListRule.parse(token.content);
335
+ } else {
336
+ children = this.parse(token.content);
337
+ }
327
338
  return {
328
339
  ...token,
329
340
  children
@@ -1196,7 +1207,8 @@ var ImageExtension = {
1196
1207
  attributes: {
1197
1208
  alt: match[1] || "",
1198
1209
  src: match[2] || "",
1199
- title: match[3] || ""
1210
+ caption: match[3] || ""
1211
+ // Renamed from 'title' to 'caption' for clarity
1200
1212
  }
1201
1213
  })
1202
1214
  }
@@ -1207,13 +1219,24 @@ var ImageExtension = {
1207
1219
  render: (token) => {
1208
1220
  const src = token.attributes?.src || "";
1209
1221
  const alt = token.attributes?.alt || "";
1210
- const title = token.attributes?.title || "";
1211
- const titleAttr = title ? ` title="${escapeHtml(title)}"` : "";
1222
+ const caption = token.attributes?.caption || "";
1212
1223
  const format = token.attributes?.format || "html";
1224
+ if (caption) {
1225
+ if (format === "html") {
1226
+ return `<figure style="margin: 16px 0; text-align: center;">
1227
+ <img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" style="max-width: 100%; height: auto; border-radius: 8px;" loading="lazy" />
1228
+ <figcaption style="margin-top: 8px; font-size: 14px; color: #6b7280; font-style: italic;">${escapeHtml(caption)}</figcaption>
1229
+ </figure>`;
1230
+ }
1231
+ return `<figure class="my-4 text-center">
1232
+ <img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" class="max-w-full h-auto rounded-lg" loading="lazy" />
1233
+ <figcaption class="mt-2 text-sm text-gray-500 italic">${escapeHtml(caption)}</figcaption>
1234
+ </figure>`;
1235
+ }
1213
1236
  if (format === "html") {
1214
- return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}"${titleAttr} style="max-width: 100%; height: auto; border-radius: 8px; margin: 16px 0;" loading="lazy" />`;
1237
+ return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" style="max-width: 100%; height: auto; border-radius: 8px; margin: 16px 0;" loading="lazy" />`;
1215
1238
  }
1216
- return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}"${titleAttr} class="max-w-full h-auto rounded-lg my-4" loading="lazy" />`;
1239
+ return `<img src="${escapeHtml(src)}" alt="${escapeHtml(alt)}" class="max-w-full h-auto rounded-lg my-4" loading="lazy" />`;
1217
1240
  }
1218
1241
  }
1219
1242
  ]
@@ -1265,12 +1288,31 @@ var ListExtension = {
1265
1288
  name: "list",
1266
1289
  parseRules: [
1267
1290
  {
1268
- name: "list-item",
1291
+ name: "unordered-list-item",
1269
1292
  pattern: /^(\s*)[-*+]\s+(.+)$/m,
1270
1293
  render: (match) => ({
1271
1294
  type: "list-item",
1272
1295
  content: match[2] || "",
1273
- raw: match[0] || ""
1296
+ raw: match[0] || "",
1297
+ attributes: {
1298
+ indent: match[1]?.length || 0,
1299
+ ordered: false,
1300
+ marker: match[1] ? match[0].match(/[-*+]/)?.[0] : "-"
1301
+ }
1302
+ })
1303
+ },
1304
+ {
1305
+ name: "ordered-list-item",
1306
+ pattern: /^(\s*)(\d+)\.\s+(.+)$/m,
1307
+ render: (match) => ({
1308
+ type: "ordered-list-item",
1309
+ content: match[3] || "",
1310
+ raw: match[0] || "",
1311
+ attributes: {
1312
+ indent: match[1]?.length || 0,
1313
+ ordered: true,
1314
+ number: parseInt(match[2] || "1")
1315
+ }
1274
1316
  })
1275
1317
  }
1276
1318
  ],
@@ -1285,6 +1327,17 @@ var ListExtension = {
1285
1327
  }
1286
1328
  return `<li>${content}</li>`;
1287
1329
  }
1330
+ },
1331
+ {
1332
+ type: "ordered-list-item",
1333
+ render: (token) => {
1334
+ const format = token.attributes?.format || "tailwind";
1335
+ const content = token.attributes?.renderedChildren || escapeHtml(token.content);
1336
+ if (format === "html") {
1337
+ return `<li>${content}</li>`;
1338
+ }
1339
+ return `<li>${content}</li>`;
1340
+ }
1288
1341
  }
1289
1342
  ]
1290
1343
  };
@@ -1299,6 +1352,7 @@ var TaskListExtension = {
1299
1352
  content: match[3] || "",
1300
1353
  raw: match[0] || "",
1301
1354
  attributes: {
1355
+ indent: match[1]?.length || 0,
1302
1356
  checked: String((match[2] || "").toLowerCase() === "x")
1303
1357
  }
1304
1358
  })
@@ -1364,6 +1418,35 @@ var TextExtension = {
1364
1418
  ]
1365
1419
  };
1366
1420
 
1421
+ // src/extensions/core/strikethrough.ts
1422
+ var StrikethroughExtension = {
1423
+ name: "strikethrough",
1424
+ parseRules: [
1425
+ {
1426
+ name: "strikethrough",
1427
+ pattern: /~~((?:(?!~~).)+)~~/,
1428
+ render: (match) => ({
1429
+ type: "strikethrough",
1430
+ content: match[1] || "",
1431
+ raw: match[0] || ""
1432
+ })
1433
+ }
1434
+ ],
1435
+ renderRules: [
1436
+ {
1437
+ type: "strikethrough",
1438
+ render: (token) => {
1439
+ const content = escapeHtml(token.content);
1440
+ const format = token.attributes?.format;
1441
+ if (format === "html") {
1442
+ return `<del style="text-decoration: line-through; color: #6b7280;">${content}</del>`;
1443
+ }
1444
+ return `<del class="line-through text-gray-500">${content}</del>`;
1445
+ }
1446
+ }
1447
+ ]
1448
+ };
1449
+
1367
1450
  // src/extensions/core/index.ts
1368
1451
  var CoreExtensions = [
1369
1452
  TextExtension,
@@ -1378,6 +1461,7 @@ var CoreExtensions = [
1378
1461
  TaskListExtension,
1379
1462
  BlockquoteExtension,
1380
1463
  HorizontalRuleExtension,
1464
+ StrikethroughExtension,
1381
1465
  ParagraphExtension,
1382
1466
  LineBreakExtension
1383
1467
  ];