mathpix-markdown-it 1.0.72 → 1.0.73
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/.idea/vcs.xml +1 -0
- package/.idea/workspace.xml +649 -92
- package/README.md +133 -1
- package/doc/ACCESSIBILITY.md +156 -0
- package/es5/bundle.js +1 -1
- package/es5/context-menu.js +1 -0
- package/es5/index.js +1 -1
- package/lib/components/mathpix-markdown/index.js +3 -2
- package/lib/components/mathpix-markdown/index.js.map +1 -1
- package/lib/contex-menu/index.d.ts +16 -0
- package/lib/contex-menu/index.js +108 -0
- package/lib/contex-menu/index.js.map +1 -0
- package/lib/contex-menu/menu/consts.d.ts +16 -0
- package/lib/contex-menu/menu/consts.js +21 -0
- package/lib/contex-menu/menu/consts.js.map +1 -0
- package/lib/contex-menu/menu/helper.d.ts +10 -0
- package/lib/contex-menu/menu/helper.js +113 -0
- package/lib/contex-menu/menu/helper.js.map +1 -0
- package/lib/contex-menu/menu/index.d.ts +5 -0
- package/lib/contex-menu/menu/index.js +106 -0
- package/lib/contex-menu/menu/index.js.map +1 -0
- package/lib/contex-menu/menu/interfaces.d.ts +6 -0
- package/lib/contex-menu/menu/interfaces.js +3 -0
- package/lib/contex-menu/menu/interfaces.js.map +1 -0
- package/lib/contex-menu/menu/menu-item-actions.d.ts +7 -0
- package/lib/contex-menu/menu/menu-item-actions.js +112 -0
- package/lib/contex-menu/menu/menu-item-actions.js.map +1 -0
- package/lib/contex-menu/menu/menu-item.d.ts +1 -0
- package/lib/contex-menu/menu/menu-item.js +66 -0
- package/lib/contex-menu/menu/menu-item.js.map +1 -0
- package/lib/contex-menu/menu/menu-items.d.ts +1 -0
- package/lib/contex-menu/menu/menu-items.js +34 -0
- package/lib/contex-menu/menu/menu-items.js.map +1 -0
- package/lib/contex-menu/styles.d.ts +1 -0
- package/lib/contex-menu/styles.js +8 -0
- package/lib/contex-menu/styles.js.map +1 -0
- package/lib/context-menu.d.ts +7 -0
- package/lib/context-menu.js +10 -0
- package/lib/context-menu.js.map +1 -0
- package/lib/helpers/parse-mmd-element.d.ts +6 -0
- package/lib/helpers/parse-mmd-element.js +82 -0
- package/lib/helpers/parse-mmd-element.js.map +1 -0
- package/lib/markdown/index.js +3 -2
- package/lib/markdown/index.js.map +1 -1
- package/lib/markdown/mathpix-markdown-plugins.js +3 -2
- package/lib/markdown/mathpix-markdown-plugins.js.map +1 -1
- package/lib/markdown/md-ascii/index.js +3 -1
- package/lib/markdown/md-ascii/index.js.map +1 -1
- package/lib/markdown/mdPluginRaw.js +14 -4
- package/lib/markdown/mdPluginRaw.js.map +1 -1
- package/lib/mathjax/index.d.ts +14 -26
- package/lib/mathjax/index.js +139 -136
- package/lib/mathjax/index.js.map +1 -1
- package/lib/mathjax/mathjax.d.ts +24 -0
- package/lib/mathjax/mathjax.js +97 -0
- package/lib/mathjax/mathjax.js.map +1 -0
- package/lib/mathpix-markdown-model/index.d.ts +8 -1
- package/lib/mathpix-markdown-model/index.js +24 -65
- package/lib/mathpix-markdown-model/index.js.map +1 -1
- package/lib/sre/index.d.ts +5 -0
- package/lib/sre/index.js +53 -0
- package/lib/sre/index.js.map +1 -0
- package/lib/sre/sre-browser.d.ts +1 -0
- package/lib/sre/sre-browser.js +11 -0
- package/lib/sre/sre-browser.js.map +1 -0
- package/lib/sre/sre-node.d.ts +6 -0
- package/lib/sre/sre-node.js +34 -0
- package/lib/sre/sre-node.js.map +1 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -519,6 +519,89 @@ need to install anything. Simply use a `script` tag that loads
|
|
|
519
519
|
* [Example of markdownToHTML function usage](https://github.com/Mathpix/mathpix-markdown-it/blob/master/examples/html/input-mmd-to-html.html.md)([View Demo](https://htmlpreview.github.io/?https://github.com/Mathpix/mathpix-markdown-it/blob/master/examples/html/input-mmd-to-html.html))
|
|
520
520
|
|
|
521
521
|
|
|
522
|
+
## Accessibility math
|
|
523
|
+
|
|
524
|
+
By default, math is not accessibility.
|
|
525
|
+
In order for math to become accessibility, need to load the library speech-rule-engine for semantic interpretation.
|
|
526
|
+
|
|
527
|
+
### 1. For **Browser libraries**, synchronous loading is used.
|
|
528
|
+
|
|
529
|
+
```js
|
|
530
|
+
import { MathpixMarkdownModel } from "mathpix-markdown-it";
|
|
531
|
+
import { loadSre } from "mathpix-markdown-it/lib/sre/sre-browser";
|
|
532
|
+
|
|
533
|
+
const html = MathpixMarkdownModel.markdownToHTML("$x^y$", {
|
|
534
|
+
accessibility: {
|
|
535
|
+
sre: loadSre()
|
|
536
|
+
},
|
|
537
|
+
});
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
### 2. For **Node modules**, asynchronous loading is used.
|
|
541
|
+
|
|
542
|
+
```js
|
|
543
|
+
const { MathpixMarkdownModel } = require('mathpix-markdown-it');
|
|
544
|
+
const { loadSreAsync } = require('mathpix-markdown-it/lib/sre/sre-node');
|
|
545
|
+
|
|
546
|
+
(async() => {
|
|
547
|
+
const html = MathpixMarkdownModel.markdownToHTML("$x^y$", {
|
|
548
|
+
accessibility: {
|
|
549
|
+
sre: await loadSreAsync()
|
|
550
|
+
},
|
|
551
|
+
});
|
|
552
|
+
})
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
_If the accessibility option is specified, then `assistive-mml` into `mjx-container` will be added for math_
|
|
556
|
+
|
|
557
|
+
### Result html
|
|
558
|
+
|
|
559
|
+
```html
|
|
560
|
+
<div>
|
|
561
|
+
<span class="math-inline ">
|
|
562
|
+
<mjx-container class="MathJax" jax="SVG" role="math" style="position: relative" aria-label="x Superscript y" tabindex="0">
|
|
563
|
+
<svg style="vertical-align: -0.025ex" xmlns="http://www.w3.org/2000/svg" width="2.191ex" height="1.553ex" role="img" focusable="false" viewBox="0 -675.5 968.5 686.5" aria-hidden="true"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="math"><g data-mml-node="msup"><g data-mml-node="mi"><path data-c="78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g><g data-mml-node="mi" transform="translate(572, 363) scale(0.707)"><path data-c="79" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g></g></g></g></svg>
|
|
564
|
+
<mjx-assistive-mml role="presentation" unselectable="on" display="inline" aria-hidden="true"><math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mi>y</mi></msup></math></mjx-assistive-mml>
|
|
565
|
+
</mjx-container>
|
|
566
|
+
</span>
|
|
567
|
+
</div>
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
The math will then be read by screen readers as `x Superscript y`
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
## Context menu for export math
|
|
574
|
+
|
|
575
|
+
The context menu for selecting math export options is only available for browser libraries
|
|
576
|
+
|
|
577
|
+
In the rendering options, specify the export formats that should be displayed in the menu:
|
|
578
|
+
```js
|
|
579
|
+
const html = MM.markdownToHTML("$x^y$", {
|
|
580
|
+
outMath: {
|
|
581
|
+
include_error: true,
|
|
582
|
+
// Show in context menu:
|
|
583
|
+
include_asciimath: true,
|
|
584
|
+
include_latex: true,
|
|
585
|
+
include_mathml: true,
|
|
586
|
+
include_mathml_word: true,
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
Then we can use:
|
|
592
|
+
```js
|
|
593
|
+
import {
|
|
594
|
+
addListenerContextMenuEvents,
|
|
595
|
+
removeListenerContextMenuEvents,
|
|
596
|
+
} from "mathpix-markdown-it/lib/contex-menu";
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
`addListenerContextMenuEvents` - listens for events to invoke and create the context menu
|
|
600
|
+
`removeListenerContextMenuEvents` - stop listening to these events
|
|
601
|
+
|
|
602
|
+
<img width="370" alt="Screen Shot 2022-05-03 at 17 21 50" src="https://user-images.githubusercontent.com/32493105/166471623-fd3f6a5b-84e4-4d43-afcd-0384e83eb2df.png">
|
|
603
|
+
|
|
604
|
+
|
|
522
605
|
# Documentation
|
|
523
606
|
|
|
524
607
|
## React components
|
|
@@ -590,6 +673,7 @@ The `MathpixMarkdown` React element accepts the following props:
|
|
|
590
673
|
| | | Removes script tags and stuff. Removes broken and malicious html. Set to `false` to disable |
|
|
591
674
|
| `smiles` | [ISmilesOptions](https://github.com/Mathpix/mathpix-markdown-it#ismilesoptions);*`{}`* | Sets options to output chemistry equation |
|
|
592
675
|
| `htmlWrapper` | [THtmlWrapper](https://github.com/Mathpix/mathpix-markdown-it#thtmlwrapper);*`{}`* | Sets options for output full html page |
|
|
676
|
+
| `accessibility` | [TAccessibility](https://github.com/Mathpix/mathpix-markdown-it#taccessibility);*`{}`* | Sets options to accessibility |
|
|
593
677
|
|
|
594
678
|
### optionsMathpixMarkdown
|
|
595
679
|
|
|
@@ -629,7 +713,7 @@ The `MathpixMarkdown` React element accepts the following props:
|
|
|
629
713
|
| `tsv_separators` | `{column: '\t', row: '\n'}` | Separators for tsv tables |
|
|
630
714
|
| `not_catch_errors` | boolean *`false`* | Do not catch math rendering errors |
|
|
631
715
|
| `include_error` | boolean *`false`* | outputs error `<error style="display: none">...</error>` |
|
|
632
|
-
|
|
716
|
+
| `include_speech` | boolean *`false`* | outputs speech `<speech>...</speech` |
|
|
633
717
|
|
|
634
718
|
### TOutputMathJax
|
|
635
719
|
|
|
@@ -669,6 +753,54 @@ The `MathpixMarkdown` React element accepts the following props:
|
|
|
669
753
|
| `includeFonts` | boolean *`false`* | Includes mathpix-markdown fonts |
|
|
670
754
|
|
|
671
755
|
|
|
756
|
+
### TAccessibility
|
|
757
|
+
|
|
758
|
+
| | type *`default`* | description
|
|
759
|
+
|-----------------------------|-----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
760
|
+
| `assistiveMml` | boolean *`false`* | Should Assistive MathML be enabled to math (mjx-container). |
|
|
761
|
+
| `sre` | object *`null`* | spe object from library [speech-rule-engine](https://www.npmjs.com/package/speech-rule-engine) for semantic interpretation. |
|
|
762
|
+
| | | If this value is not set then the aria-label for accessibility will not be added to the math at render time. |
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
`sre` Has different loaders for node and browser.
|
|
766
|
+
|
|
767
|
+
1. For **Browser libraries**, synchronous loading is used.
|
|
768
|
+
```js
|
|
769
|
+
import { loadSre } from "mathpix-markdown-it/lib/sre/sre-browser";
|
|
770
|
+
const sre = loadSre();
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
2. For **Node modules**, asynchronous loading is used.
|
|
774
|
+
|
|
775
|
+
```js
|
|
776
|
+
const { loadSreAsync } = require('mathpix-markdown-it/lib/sre/sre-node');
|
|
777
|
+
|
|
778
|
+
(async() => {
|
|
779
|
+
const sre = await loadSreAsync();
|
|
780
|
+
})
|
|
781
|
+
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
Then just pass the resulting value to `accessibility.spe`
|
|
785
|
+
```js
|
|
786
|
+
accessibility: {
|
|
787
|
+
assistiveMml: true, // assistive-mml will be added to mjx-container
|
|
788
|
+
sre: sre
|
|
789
|
+
}
|
|
790
|
+
```
|
|
791
|
+
|
|
792
|
+
### Adding accessibility to math on already rendered html.
|
|
793
|
+
|
|
794
|
+
`addAriaToMathHTML(sre, html)` function will add accessibility attributes.
|
|
795
|
+
Can only be used for **Browser libraries**
|
|
796
|
+
|
|
797
|
+
```js
|
|
798
|
+
import { loadSre } from "mathpix-markdown-it/lib/sre/sre-browser";
|
|
799
|
+
const sre = loadSre();
|
|
800
|
+
|
|
801
|
+
const htmlAssistive = addAriaToMathHTML(sre, html);
|
|
802
|
+
```
|
|
803
|
+
|
|
672
804
|
# Development
|
|
673
805
|
|
|
674
806
|
Install dependencies:
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# ACCESSIBILITY
|
|
2
|
+
|
|
3
|
+
[speech-rule-engine](https://www.npmjs.com/package/speech-rule-engine)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Browser
|
|
7
|
+
|
|
8
|
+
To form accessibility attributes, the browser version of `speech-rule-engine` is used.
|
|
9
|
+
This requires access to window and DOM
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { loadSre } from "mathpix-markdown-it/lib/sre/sre-browser";
|
|
13
|
+
const sre = loadSre();
|
|
14
|
+
|
|
15
|
+
import { MathpixMarkdownModel } from "mathpix-markdown-it";
|
|
16
|
+
|
|
17
|
+
const mmdOptions = {
|
|
18
|
+
outMath: {
|
|
19
|
+
include_svg: true,
|
|
20
|
+
include_speech: true,
|
|
21
|
+
},
|
|
22
|
+
accessibility: {
|
|
23
|
+
assistiveMml: true, // assistive-mml will be added to mjx-container
|
|
24
|
+
sre: sre
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const html = MathpixMarkdownModel.markdownToHTML("$x^y$", mmdOptions);
|
|
29
|
+
console.log('html => ', html);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<div>
|
|
34
|
+
<span class="math-inline ">
|
|
35
|
+
<speech style="display: none">x Superscript y</speech>
|
|
36
|
+
<mjx-container class="MathJax" jax="SVG" role="math" aria-label="x Superscript y" style="position: relative;">
|
|
37
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="2.191ex" height="1.553ex" role="img" focusable="false" viewBox="0 -675.5 968.5 686.5" aria-hidden="true" style="vertical-align: -0.025ex;"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="math"><g data-mml-node="msup"><g data-mml-node="mi"><path data-c="78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g><g data-mml-node="mi" transform="translate(572, 363) scale(0.707)"><path data-c="79" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g></g></g></g></svg>
|
|
38
|
+
<mjx-assistive-mml role="presentation" unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mi>y</mi></msup></math></mjx-assistive-mml>
|
|
39
|
+
</mjx-container>
|
|
40
|
+
</span>
|
|
41
|
+
</div>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Node.js
|
|
46
|
+
|
|
47
|
+
To form accessibility, the node version of `speech-rule-engine` is used.
|
|
48
|
+
Modules are loaded asynchronously.
|
|
49
|
+
|
|
50
|
+
`const { loadSreAsync } = require('mathpix-markdown-it/lib/sre/sre-node');`
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
const { loadSreAsync } = require('mathpix-markdown-it/lib/sre/sre-node');;
|
|
55
|
+
const { MathpixMarkdownModel } = require('mathpix-markdown-it');
|
|
56
|
+
|
|
57
|
+
( async() => {
|
|
58
|
+
const sre = await loadSreAsync();
|
|
59
|
+
|
|
60
|
+
const options = {
|
|
61
|
+
accessibility: {
|
|
62
|
+
assistiveMml: true,
|
|
63
|
+
sre: sre
|
|
64
|
+
},
|
|
65
|
+
outMath: {
|
|
66
|
+
include_svg: true,
|
|
67
|
+
include_speech: true,
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
const htmlMM = MathpixMarkdownModel.markdownToHTML("$x^y$", options);
|
|
74
|
+
console.log('==>htmlMM=>', htmlMM)
|
|
75
|
+
|
|
76
|
+
})();
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```html
|
|
81
|
+
<div>
|
|
82
|
+
<span class="math-inline ">
|
|
83
|
+
<speech style="display: none">x Superscript y</speech>
|
|
84
|
+
<mjx-container class="MathJax" jax="SVG" role="math" style="position: relative" aria-label="x Superscript y">
|
|
85
|
+
<svg style="vertical-align: -0.025ex" xmlns="http://www.w3.org/2000/svg" width="2.191ex" height="1.553ex" role="img" focusable="false" viewBox="0 -675.5 968.5 686.5" aria-hidden="true"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="math"><g data-mml-node="msup"><g data-mml-node="mi"><path data-c="78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g><g data-mml-node="mi" transform="translate(572, 363) scale(0.707)"><path data-c="79" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g></g></g></g></svg>
|
|
86
|
+
<mjx-assistive-mml role="presentation" unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mi>y</mi></msup></math></mjx-assistive-mml>
|
|
87
|
+
</mjx-container>
|
|
88
|
+
</span>
|
|
89
|
+
</div>
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## Web Worker
|
|
95
|
+
|
|
96
|
+
For the Web worker, we cannot use any of the `speech-rule-engine` versions.
|
|
97
|
+
This will throw errors. Since the Web worker does not have access to the DOM and Window,
|
|
98
|
+
the `speech-rule-engine` will try to switch to the node version.
|
|
99
|
+
And it will throw a `process` and `require` access error.
|
|
100
|
+
|
|
101
|
+
Solutions to this problem:
|
|
102
|
+
- Render to html in Web worker.
|
|
103
|
+
- Then, after the messages from the Web Worker with rendered html are received.
|
|
104
|
+
We can add the necessary attributes to the resulting html using the function `addAriaToMathHTML`
|
|
105
|
+
|
|
106
|
+
`import { addAriaToMathHTML } from "mathpix-markdown-it/lib/mmd-sre";`
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
#### Web worker
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
const mmdOptions = {
|
|
113
|
+
outMath: {
|
|
114
|
+
include_svg: true,
|
|
115
|
+
},
|
|
116
|
+
accessibility: {
|
|
117
|
+
assistiveMml: true, // This should be set to true
|
|
118
|
+
sre: false // This should be set to false
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const html = MM.markdownToHTML("$x^y$", mmdOptions);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```html
|
|
126
|
+
<div>
|
|
127
|
+
<span class="math-inline ">
|
|
128
|
+
<mjx-container class="MathJax" jax="SVG" role="presentation" style="position: relative">
|
|
129
|
+
<svg style="vertical-align: -0.025ex" xmlns="http://www.w3.org/2000/svg" width="2.191ex" height="1.553ex" role="img" focusable="false" viewBox="0 -675.5 968.5 686.5" aria-hidden="true"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="math"><g data-mml-node="msup"><g data-mml-node="mi"><path data-c="78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g><g data-mml-node="mi" transform="translate(572, 363) scale(0.707)"><path data-c="79" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g></g></g></g></svg>
|
|
130
|
+
<mjx-assistive-mml role="presentation" unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mi>y</mi></msup></math></mjx-assistive-mml>
|
|
131
|
+
</mjx-container>
|
|
132
|
+
</span>
|
|
133
|
+
</div>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### After the messages from the Web Worker with rendered html are received.
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
import { loadSre } from "mathpix-markdown-it/lib/sre/sre-browser";
|
|
140
|
+
import { addAriaToMathHTML } from "mathpix-markdown-it/lib/sre";
|
|
141
|
+
const sre = loadSre();
|
|
142
|
+
|
|
143
|
+
const htmlNew = addAriaToMathHTML(sre, html);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
```html
|
|
147
|
+
<div>
|
|
148
|
+
<span class="math-inline ">
|
|
149
|
+
<mjx-container class="MathJax" jax="SVG" role="math" style="position: relative" aria-label="x Superscript y">
|
|
150
|
+
<svg style="vertical-align: -0.025ex" xmlns="http://www.w3.org/2000/svg" width="2.191ex" height="1.553ex" role="img" focusable="false" viewBox="0 -675.5 968.5 686.5" aria-hidden="true"><g stroke="currentColor" fill="currentColor" stroke-width="0" transform="matrix(1 0 0 -1 0 0)"><g data-mml-node="math"><g data-mml-node="msup"><g data-mml-node="mi"><path data-c="78" d="M52 289Q59 331 106 386T222 442Q257 442 286 424T329 379Q371 442 430 442Q467 442 494 420T522 361Q522 332 508 314T481 292T458 288Q439 288 427 299T415 328Q415 374 465 391Q454 404 425 404Q412 404 406 402Q368 386 350 336Q290 115 290 78Q290 50 306 38T341 26Q378 26 414 59T463 140Q466 150 469 151T485 153H489Q504 153 504 145Q504 144 502 134Q486 77 440 33T333 -11Q263 -11 227 52Q186 -10 133 -10H127Q78 -10 57 16T35 71Q35 103 54 123T99 143Q142 143 142 101Q142 81 130 66T107 46T94 41L91 40Q91 39 97 36T113 29T132 26Q168 26 194 71Q203 87 217 139T245 247T261 313Q266 340 266 352Q266 380 251 392T217 404Q177 404 142 372T93 290Q91 281 88 280T72 278H58Q52 284 52 289Z"></path></g><g data-mml-node="mi" transform="translate(572, 363) scale(0.707)"><path data-c="79" d="M21 287Q21 301 36 335T84 406T158 442Q199 442 224 419T250 355Q248 336 247 334Q247 331 231 288T198 191T182 105Q182 62 196 45T238 27Q261 27 281 38T312 61T339 94Q339 95 344 114T358 173T377 247Q415 397 419 404Q432 431 462 431Q475 431 483 424T494 412T496 403Q496 390 447 193T391 -23Q363 -106 294 -155T156 -205Q111 -205 77 -183T43 -117Q43 -95 50 -80T69 -58T89 -48T106 -45Q150 -45 150 -87Q150 -107 138 -122T115 -142T102 -147L99 -148Q101 -153 118 -160T152 -167H160Q177 -167 186 -165Q219 -156 247 -127T290 -65T313 -9T321 21L315 17Q309 13 296 6T270 -6Q250 -11 231 -11Q185 -11 150 11T104 82Q103 89 103 113Q103 170 138 262T173 379Q173 380 173 381Q173 390 173 393T169 400T158 404H154Q131 404 112 385T82 344T65 302T57 280Q55 278 41 278H27Q21 284 21 287Z"></path></g></g></g></g></svg>
|
|
151
|
+
<mjx-assistive-mml role="presentation" unselectable="on" display="inline"><math xmlns="http://www.w3.org/1998/Math/MathML"><msup><mi>x</mi><mi>y</mi></msup></math></mjx-assistive-mml>
|
|
152
|
+
</mjx-container>
|
|
153
|
+
<speech style="display: none;">x Superscript y</speech>
|
|
154
|
+
</span>
|
|
155
|
+
</div>
|
|
156
|
+
```
|