marked-katex-extension 4.0.0 → 4.0.2

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/lib/index.cjs CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  var katex = require('katex');
4
4
 
5
- const inlineStartRule = /(\s|^)\${1,2}(?!\$)/;
6
5
  const inlineRule = /^(\${1,2})(?!\$)((?:\\.|[^\\\n])*?(?:\\.|[^\\\n\$]))\1(?=[\s?!\.,:]|$)/;
7
6
  const blockRule = /^(\${1,2})\n((?:\\[^]|[^\\])+?)\n\1(?:\n|$)/;
8
7
 
@@ -24,16 +23,24 @@ function inlineKatex(options, renderer) {
24
23
  name: 'inlineKatex',
25
24
  level: 'inline',
26
25
  start(src) {
27
- const match = src.match(inlineStartRule);
28
- if (!match) {
29
- return;
30
- }
26
+ let index;
27
+ let indexSrc = src;
28
+
29
+ while (indexSrc) {
30
+ index = indexSrc.indexOf('$');
31
+ if (index === -1) {
32
+ return;
33
+ }
34
+
35
+ if (index === 0 || indexSrc.charAt(index - 1) === ' ') {
36
+ const possibleKatex = indexSrc.substring(index);
31
37
 
32
- const index = match.index + match[1].length;
33
- const possibleKatex = src.substring(index);
38
+ if (possibleKatex.match(inlineRule)) {
39
+ return index;
40
+ }
41
+ }
34
42
 
35
- if (possibleKatex.match(inlineRule)) {
36
- return index;
43
+ indexSrc = indexSrc.substring(index + 1).replace(/^\$+/, '');
37
44
  }
38
45
  },
39
46
  tokenizer(src, tokens) {
package/lib/index.umd.js CHANGED
@@ -5176,6 +5176,10 @@
5176
5176
  defineSymbol(text, main, textord, _ch3, wideChar);
5177
5177
  wideChar = String.fromCharCode(0xD835, 0xDD04 + _i3); // A-Z a-z Fractur
5178
5178
 
5179
+ defineSymbol(math, main, mathord, _ch3, wideChar);
5180
+ defineSymbol(text, main, textord, _ch3, wideChar);
5181
+ wideChar = String.fromCharCode(0xD835, 0xDD6C + _i3); // A-Z a-z bold Fractur
5182
+
5179
5183
  defineSymbol(math, main, mathord, _ch3, wideChar);
5180
5184
  defineSymbol(text, main, textord, _ch3, wideChar);
5181
5185
  wideChar = String.fromCharCode(0xD835, 0xDDA0 + _i3); // A-Z a-z sans-serif
@@ -5283,8 +5287,9 @@
5283
5287
  ["mathfrak", "textfrak", "Fraktur-Regular"], // a-z Fraktur
5284
5288
  ["mathbb", "textbb", "AMS-Regular"], // A-Z double-struck
5285
5289
  ["mathbb", "textbb", "AMS-Regular"], // k double-struck
5286
- ["", "", ""], // A-Z bold Fraktur No font metrics
5287
- ["", "", ""], // a-z bold Fraktur. No font.
5290
+ // Note that we are using a bold font, but font metrics for regular Fraktur.
5291
+ ["mathboldfrak", "textboldfrak", "Fraktur-Regular"], // A-Z bold Fraktur
5292
+ ["mathboldfrak", "textboldfrak", "Fraktur-Regular"], // a-z bold Fraktur
5288
5293
  ["mathsf", "textsf", "SansSerif-Regular"], // A-Z sans-serif
5289
5294
  ["mathsf", "textsf", "SansSerif-Regular"], // a-z sans-serif
5290
5295
  ["mathboldsf", "textboldsf", "SansSerif-Bold"], // A-Z bold sans-serif
@@ -5460,10 +5465,15 @@
5460
5465
 
5461
5466
  var isFont = mode === "math" || mode === "text" && options.font;
5462
5467
  var fontOrFamily = isFont ? options.font : options.fontFamily;
5468
+ var wideFontName = "";
5469
+ var wideFontClass = "";
5463
5470
 
5464
5471
  if (text.charCodeAt(0) === 0xD835) {
5472
+ [wideFontName, wideFontClass] = wideCharacterFont(text, mode);
5473
+ }
5474
+
5475
+ if (wideFontName.length > 0) {
5465
5476
  // surrogate pairs get special treatment
5466
- var [wideFontName, wideFontClass] = wideCharacterFont(text, mode);
5467
5477
  return makeSymbol(text, wideFontName, mode, options, classes.concat(wideFontClass));
5468
5478
  } else if (fontOrFamily) {
5469
5479
  var fontName;
@@ -18315,7 +18325,7 @@
18315
18325
  /**
18316
18326
  * Current KaTeX version
18317
18327
  */
18318
- version: "0.16.8",
18328
+ version: "0.16.9",
18319
18329
 
18320
18330
  /**
18321
18331
  * Renders the given LaTeX into an HTML+MathML combination, and adds
@@ -18409,7 +18419,6 @@
18409
18419
  }
18410
18420
  };
18411
18421
 
18412
- const inlineStartRule = /(\s|^)\${1,2}(?!\$)/;
18413
18422
  const inlineRule = /^(\${1,2})(?!\$)((?:\\.|[^\\\n])*?(?:\\.|[^\\\n\$]))\1(?=[\s?!\.,:]|$)/;
18414
18423
  const blockRule = /^(\${1,2})\n((?:\\[^]|[^\\])+?)\n\1(?:\n|$)/;
18415
18424
 
@@ -18431,16 +18440,24 @@
18431
18440
  name: 'inlineKatex',
18432
18441
  level: 'inline',
18433
18442
  start(src) {
18434
- const match = src.match(inlineStartRule);
18435
- if (!match) {
18436
- return;
18437
- }
18443
+ let index;
18444
+ let indexSrc = src;
18445
+
18446
+ while (indexSrc) {
18447
+ index = indexSrc.indexOf('$');
18448
+ if (index === -1) {
18449
+ return;
18450
+ }
18438
18451
 
18439
- const index = match.index + match[1].length;
18440
- const possibleKatex = src.substring(index);
18452
+ if (index === 0 || indexSrc.charAt(index - 1) === ' ') {
18453
+ const possibleKatex = indexSrc.substring(index);
18454
+
18455
+ if (possibleKatex.match(inlineRule)) {
18456
+ return index;
18457
+ }
18458
+ }
18441
18459
 
18442
- if (possibleKatex.match(inlineRule)) {
18443
- return index;
18460
+ indexSrc = indexSrc.substring(index + 1).replace(/^\$+/, '');
18444
18461
  }
18445
18462
  },
18446
18463
  tokenizer(src, tokens) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marked-katex-extension",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "MarkedJS extesion to render katex",
5
5
  "main": "./lib/index.cjs",
6
6
  "module": "./src/index.js",
@@ -23,7 +23,9 @@
23
23
  }
24
24
  },
25
25
  "scripts": {
26
- "test": "jest --verbose",
26
+ "test": "npm run build && npm run test:cover && npm run test:spec && npm run test:types && npm run lint",
27
+ "test:katex": "jest --verbose",
28
+ "test:spec": "node --test spec/marked-tests.js",
27
29
  "test:cover": "jest --coverage",
28
30
  "test:types": "tsd -f spec/index.test-d.ts -t src/index.d.ts",
29
31
  "lint": "eslint .",
@@ -46,11 +48,12 @@
46
48
  "devDependencies": {
47
49
  "@babel/core": "^7.23.0",
48
50
  "@babel/preset-env": "^7.22.20",
51
+ "@markedjs/testutils": "9.1.0-3",
49
52
  "@rollup/plugin-node-resolve": "^15.2.1",
50
53
  "@semantic-release/changelog": "^6.0.3",
51
54
  "@semantic-release/commit-analyzer": "^11.0.0",
52
55
  "@semantic-release/git": "^10.0.1",
53
- "@semantic-release/github": "^9.0.7",
56
+ "@semantic-release/github": "^9.2.1",
54
57
  "@semantic-release/npm": "^11.0.0",
55
58
  "@semantic-release/release-notes-generator": "^12.0.0",
56
59
  "babel-jest": "^29.7.0",
@@ -63,12 +66,12 @@
63
66
  "jest-cli": "^29.7.0",
64
67
  "marked": "^9.0.3",
65
68
  "node-fetch": "^3.3.2",
66
- "rollup": "^3.29.3",
69
+ "rollup": "^3.29.4",
67
70
  "semantic-release": "^22.0.5",
68
71
  "tsd": "^0.29.0"
69
72
  },
70
73
  "dependencies": {
71
74
  "@types/katex": "^0.16.3",
72
- "katex": "^0.16.8"
75
+ "katex": "^0.16.9"
73
76
  }
74
77
  }
package/src/index.js CHANGED
@@ -1,6 +1,5 @@
1
1
  import katex from 'katex';
2
2
 
3
- const inlineStartRule = /(\s|^)\${1,2}(?!\$)/;
4
3
  const inlineRule = /^(\${1,2})(?!\$)((?:\\.|[^\\\n])*?(?:\\.|[^\\\n\$]))\1(?=[\s?!\.,:]|$)/;
5
4
  const blockRule = /^(\${1,2})\n((?:\\[^]|[^\\])+?)\n\1(?:\n|$)/;
6
5
 
@@ -22,16 +21,24 @@ function inlineKatex(options, renderer) {
22
21
  name: 'inlineKatex',
23
22
  level: 'inline',
24
23
  start(src) {
25
- const match = src.match(inlineStartRule);
26
- if (!match) {
27
- return;
28
- }
24
+ let index;
25
+ let indexSrc = src;
26
+
27
+ while (indexSrc) {
28
+ index = indexSrc.indexOf('$');
29
+ if (index === -1) {
30
+ return;
31
+ }
32
+
33
+ if (index === 0 || indexSrc.charAt(index - 1) === ' ') {
34
+ const possibleKatex = indexSrc.substring(index);
29
35
 
30
- const index = match.index + match[1].length;
31
- const possibleKatex = src.substring(index);
36
+ if (possibleKatex.match(inlineRule)) {
37
+ return index;
38
+ }
39
+ }
32
40
 
33
- if (possibleKatex.match(inlineRule)) {
34
- return index;
41
+ indexSrc = indexSrc.substring(index + 1).replace(/^\$+/, '');
35
42
  }
36
43
  },
37
44
  tokenizer(src, tokens) {