@affanhamid/markdown-renderer 2.3.5 → 2.3.6

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.cjs CHANGED
@@ -227,6 +227,7 @@ function hasMatchingDelimiter(text, startIndex, delimiter) {
227
227
  return false;
228
228
  }
229
229
  var IMG_PLACEHOLDER = "IMG";
230
+ var LINK_PLACEHOLDER = "LNK";
230
231
  var format = (text) => {
231
232
  const images = [];
232
233
  text = text.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_, alt, url) => {
@@ -236,6 +237,14 @@ var format = (text) => {
236
237
  );
237
238
  return `${IMG_PLACEHOLDER}${idx}`;
238
239
  });
240
+ const links = [];
241
+ text = text.replace(/(?<!!)\[([^\]]*)\]\(([^)]+)\)/g, (_, linkText, url) => {
242
+ const idx = links.length;
243
+ links.push(
244
+ `<a href="${escapeHtml(url)}">${format(linkText)}</a>`
245
+ );
246
+ return `${LINK_PLACEHOLDER}${idx}`;
247
+ });
239
248
  let inLatex = false;
240
249
  let inBoldItalics = false;
241
250
  let inBold = false;
@@ -545,6 +554,12 @@ var format = (text) => {
545
554
  images[idx]
546
555
  );
547
556
  }
557
+ for (let idx = 0; idx < links.length; idx++) {
558
+ result = result.replace(
559
+ escapeHtml(`${LINK_PLACEHOLDER}${idx}`),
560
+ links[idx]
561
+ );
562
+ }
548
563
  return result;
549
564
  };
550
565
  var getIndentLevel = (line) => {
package/dist/index.js CHANGED
@@ -188,6 +188,7 @@ function hasMatchingDelimiter(text, startIndex, delimiter) {
188
188
  return false;
189
189
  }
190
190
  var IMG_PLACEHOLDER = "IMG";
191
+ var LINK_PLACEHOLDER = "LNK";
191
192
  var format = (text) => {
192
193
  const images = [];
193
194
  text = text.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_, alt, url) => {
@@ -197,6 +198,14 @@ var format = (text) => {
197
198
  );
198
199
  return `${IMG_PLACEHOLDER}${idx}`;
199
200
  });
201
+ const links = [];
202
+ text = text.replace(/(?<!!)\[([^\]]*)\]\(([^)]+)\)/g, (_, linkText, url) => {
203
+ const idx = links.length;
204
+ links.push(
205
+ `<a href="${escapeHtml(url)}">${format(linkText)}</a>`
206
+ );
207
+ return `${LINK_PLACEHOLDER}${idx}`;
208
+ });
200
209
  let inLatex = false;
201
210
  let inBoldItalics = false;
202
211
  let inBold = false;
@@ -506,6 +515,12 @@ var format = (text) => {
506
515
  images[idx]
507
516
  );
508
517
  }
518
+ for (let idx = 0; idx < links.length; idx++) {
519
+ result = result.replace(
520
+ escapeHtml(`${LINK_PLACEHOLDER}${idx}`),
521
+ links[idx]
522
+ );
523
+ }
509
524
  return result;
510
525
  };
511
526
  var getIndentLevel = (line) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affanhamid/markdown-renderer",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "description": "Custom markdown renderer with KaTeX support",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",