No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
5313419
... +78 ...
63a5f76
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
1 | + | /** |
|
2 | + | * @typedef {import('hast').Root} Root |
|
3 | + | * @typedef {import('hast').Element} Element |
|
4 | + | * |
|
5 | + | * @typedef {[string, string]} MathNotation |
|
6 | + | * Markers to use for math. |
|
7 | + | * See: <http://docs.mathjax.org/en/latest/options/input/tex.html#the-configuration-block> |
|
8 | + | * |
|
9 | + | * @typedef OutputSvgOptions |
|
10 | + | * <http://docs.mathjax.org/en/latest/options/output/svg.html#the-configuration-block> |
|
11 | + | * @property {number} [scale] |
|
12 | + | * @property {number} [minScale] |
|
13 | + | * @property {boolean} [mtextInheritFont] |
|
14 | + | * @property {boolean} [merrorInheritFont] |
|
15 | + | * @property {boolean} [mathmlSpacing] |
|
16 | + | * @property {Record<string, boolean>} [skipAttributes] |
|
17 | + | * @property {number} [exFactor] |
|
18 | + | * @property {'left'|'center'|'right'} [displayAlign] |
|
19 | + | * @property {string} [displayIndent] |
|
20 | + | * @property {'local'|'global'} [fontCache] |
|
21 | + | * @property {string|null} [localID] |
|
22 | + | * @property {boolean} [internalSpeechTitles] |
|
23 | + | * @property {number} [titleID] |
|
24 | + | * |
|
25 | + | * @typedef OutputCHtmlOptions |
|
26 | + | * <http://docs.mathjax.org/en/latest/options/output/chtml.html#the-configuration-block> |
|
27 | + | * @property {number} [scale] |
|
28 | + | * @property {number} [minScale] |
|
29 | + | * @property {boolean} [matchFontHeight] |
|
30 | + | * @property {boolean} [mtextInheritFont] |
|
31 | + | * @property {boolean} [merrorInheritFont] |
|
32 | + | * @property {boolean} [mathmlSpacing] |
|
33 | + | * @property {Record<string, boolean>} [skipAttributes] |
|
34 | + | * @property {number} [exFactor] |
|
35 | + | * @property {'left'|'center'|'right'} [displayAlign] |
|
36 | + | * @property {string} [displayIndent] |
|
37 | + | * @property {string} fontURL |
|
38 | + | * @property {boolean} [adaptiveCSS] |
|
39 | + | * |
|
40 | + | * @typedef InputTexOptions |
|
41 | + | * <http://docs.mathjax.org/en/latest/options/input/tex.html#the-configuration-block> |
|
42 | + | * @property {string[]} [packages] |
|
43 | + | * @property {MathNotation[]} [inlineMath] |
|
44 | + | * @property {MathNotation[]} [displayMath] |
|
45 | + | * @property {boolean} [processEscapes] |
|
46 | + | * @property {boolean} [processEnvironments] |
|
47 | + | * @property {boolean} [processRefs] |
|
48 | + | * @property {RegExp} [digits] |
|
49 | + | * @property {'none'|'ams'|'all'} [tags] |
|
50 | + | * @property {'left'|'right'} [tagSide] |
|
51 | + | * @property {string} [tagIndent] |
|
52 | + | * @property {boolean} [useLabelIds] |
|
53 | + | * @property {string} [multlineWidth] |
|
54 | + | * @property {number} [maxMacros] |
|
55 | + | * @property {number} [maxBuffer] |
|
56 | + | * @property {string} [baseURL] |
|
57 | + | * @property {(jax: any, error: any) => string} [formatError] |
|
58 | + | * |
|
59 | + | * @typedef Options |
|
60 | + | * Configuration. |
|
61 | + | * @property {InputTexOptions} [tex] |
|
62 | + | * Configuration for the input TeX. |
|
63 | + | * @property {OutputCHtmlOptions} [chtml] |
|
64 | + | * Configuration for the output (when CHTML). |
|
65 | + | * @property {OutputSvgOptions} [svg] |
|
66 | + | * Configuration for the output (when SVG). |
|
67 | + | * |
|
68 | + | * @typedef Renderer |
|
69 | + | * @property {(node: Element, options: {display: boolean}) => void} render |
|
70 | + | * @property {() => Element} [styleSheet] |
|
71 | + | * |
|
72 | + | * @callback CreateRenderer |
|
73 | + | * @param {Options} options |
|
74 | + | * @returns {Renderer} |
|
75 | + | */ |
|
76 | + | ||
77 | + | import {visit, SKIP} from 'unist-util-visit' |
|
78 | + | ||
79 | + | /** |
|
80 | + | * @param {CreateRenderer} createRenderer |
|
81 | + | */ |
|
82 | + | export function createPlugin(createRenderer) { |
|
83 | + | /** @type {import('unified').Plugin<[Options?]|void[], Root>} */ |
|
84 | + | return (options = {}) => |
|
85 | + | (tree) => { |
|
86 | + | const renderer = createRenderer(options) |
|
87 | + | let found = false |
|
88 | + | /** @type {Root|Element} */ |
|
89 | + | let context = tree |
|
90 | + | ||
91 | + | visit(tree, 'element', (node) => { |
|
92 | + | const classes = |
|
93 | + | node.properties && Array.isArray(node.properties.className) |
|
94 | + | ? node.properties.className |
|
95 | + | : [] |
|
96 | + | const inline = classes.includes('math-inline') |
|
97 | + | const display = classes.includes('math-display') |
|
98 | + | ||
99 | + | if (node.tagName === 'head') { |
|
100 | + | context = node |
|
101 | + | } |
|
102 | + | ||
103 | + | if (!inline && !display) { |
|
104 | + | return |
|
105 | + | } |
|
106 | + | ||
107 | + | found = true |
|
108 | + | renderer.render(node, {display}) |
|
109 | + | ||
110 | + | return SKIP |
|
111 | + | }) |
|
112 | + | ||
113 | + | if (found && renderer.styleSheet) { |
|
114 | + | context.children.push(renderer.styleSheet()) |
|
115 | + | } |
|
116 | + | } |
|
117 | + | } |
1 | - | const inlinePlugin = require('./inline') |
|
2 | - | const blockPlugin = require('./block') |
|
1 | + | /** |
|
2 | + | * @typedef {import('mdast').Root} Root |
|
3 | + | * @typedef {import('mdast-util-math').ToOptions} Options |
|
4 | + | * |
|
5 | + | * @typedef {import('mdast-util-math')} DoNotTouchAsThisImportIncludesMathInTree |
|
6 | + | */ |
|
3 | 7 | ||
4 | - | module.exports = math |
|
8 | + | import {math} from 'micromark-extension-math' |
|
9 | + | import {mathFromMarkdown, mathToMarkdown} from 'mdast-util-math' |
|
5 | 10 | ||
6 | - | function math(options) { |
|
7 | - | var settings = options || {} |
|
8 | - | blockPlugin.call(this, settings) |
|
9 | - | inlinePlugin.call(this, settings) |
|
11 | + | /** |
|
12 | + | * Plugin to support math. |
|
13 | + | * |
|
14 | + | * @type {import('unified').Plugin<[Options?] | void[], Root, Root>} |
|
15 | + | */ |
|
16 | + | export default function remarkMath(options = {}) { |
|
17 | + | const data = this.data() |
|
18 | + | ||
19 | + | add('micromarkExtensions', math(options)) |
|
20 | + | add('fromMarkdownExtensions', mathFromMarkdown()) |
|
21 | + | add('toMarkdownExtensions', mathToMarkdown(options)) |
|
22 | + | ||
23 | + | /** |
|
24 | + | * @param {string} field |
|
25 | + | * @param {unknown} value |
|
26 | + | */ |
|
27 | + | function add(field, value) { |
|
28 | + | const list = /** @type {unknown[]} */ ( |
|
29 | + | // Other extensions |
|
30 | + | /* c8 ignore next 2 */ |
|
31 | + | data[field] ? data[field] : (data[field] = []) |
|
32 | + | ) |
|
33 | + | ||
34 | + | list.push(value) |
|
35 | + | } |
|
10 | 36 | } |
1 | + | /** |
|
2 | + | * @typedef {import('hast').Element} Element |
|
3 | + | * @typedef {import('mathjax-full/js/core/OutputJax').OutputJax<HTMLElement, Text, Document>} OutputJax |
|
4 | + | * @typedef {import('mathjax-full/js/core/MathDocument.js').MathDocument<HTMLElement, Text, Document>} MathDocument |
|
5 | + | * @typedef {import('mathjax-full/js/input/tex.js').TeX<HTMLElement, Text, Document>} TeX_ |
|
6 | + | * @typedef {import('./create-plugin.js').Options} Options |
|
7 | + | * @typedef {import('./create-plugin.js').Renderer} Renderer |
|
8 | + | */ |
|
9 | + | ||
10 | + | import {mathjax} from 'mathjax-full/js/mathjax.js' |
|
11 | + | import {RegisterHTMLHandler} from 'mathjax-full/js/handlers/html.js' |
|
12 | + | import {TeX} from 'mathjax-full/js/input/tex.js' |
|
13 | + | import {AllPackages} from 'mathjax-full/js/input/tex/AllPackages.js' |
|
14 | + | import {fromDom} from 'hast-util-from-dom' |
|
15 | + | import {toText} from 'hast-util-to-text' |
|
16 | + | import {createAdaptor} from './create-adaptor.js' |
|
17 | + | ||
18 | + | const adaptor = createAdaptor() |
|
19 | + | ||
20 | + | // To do next major: Keep resultant HTML handler from `register(adaptor)` to |
|
21 | + | // allow registering the `AssistiveMmlHandler` as in this demo: |
|
22 | + | // <https://github.com/mathjax/MathJax-demos-node/tree/master/direct> |
|
23 | + | // |
|
24 | + | // To do next major: If registering `AssistiveMmlHandler` is supported through |
|
25 | + | // configuration, move HTML handler registration to beginning of transformer and |
|
26 | + | // unregister at the end of transformer with |
|
27 | + | // `mathjax.handlers.unregister(handler)`. |
|
28 | + | // That is to prevent memory leak in `mathjax.handlers` whenever a new instance |
|
29 | + | // of the plugin is used. |
|
30 | + | /* eslint-disable-next-line new-cap */ |
|
31 | + | RegisterHTMLHandler(adaptor) |
|
32 | + | ||
33 | + | /** |
|
34 | + | * @param {Options} options |
|
35 | + | * @param {OutputJax} output |
|
36 | + | * @returns {Renderer} |
|
37 | + | */ |
|
38 | + | export function createRenderer(options, output) { |
|
39 | + | const input = new TeX(Object.assign({packages: AllPackages}, options.tex)) |
|
40 | + | /** @type {MathDocument} */ |
|
41 | + | const doc = mathjax.document('', {InputJax: input, OutputJax: output}) |
|
42 | + | ||
43 | + | return { |
|
44 | + | render(node, options) { |
|
45 | + | const domNode = fromDom( |
|
46 | + | // @ts-expect-error: assume mathml nodes can be handled by |
|
47 | + | // `hast-util-from-dom`. |
|
48 | + | doc.convert(toText(node, {whitespace: 'pre'}), options) |
|
49 | + | ) |
|
50 | + | // @ts-expect-error: `fromDom` returns an element for a given element. |
|
51 | + | node.children = [domNode] |
|
52 | + | }, |
|
53 | + | styleSheet() { |
|
54 | + | const value = adaptor.textContent(output.styleSheet(doc)) |
|
55 | + | ||
56 | + | return { |
|
57 | + | type: 'element', |
|
58 | + | tagName: 'style', |
|
59 | + | properties: {}, |
|
60 | + | children: [{type: 'text', value}] |
|
61 | + | } |
|
62 | + | } |
|
63 | + | } |
|
64 | + | } |
1 | - | const createInput = require('./lib/input') |
|
2 | - | const createOutput = require('./lib/output-svg') |
|
3 | - | const createRenderer = require('./lib/renderer') |
|
4 | - | const createPlugin = require('./lib/core') |
|
1 | + | /** |
|
2 | + | * @typedef {import('./lib/create-plugin.js').Options} Options |
|
3 | + | */ |
|
5 | 4 | ||
6 | - | module.exports = createPlugin('rehypeMathJaxSvg', renderSvg) |
|
5 | + | import {SVG} from 'mathjax-full/js/output/svg.js' |
|
6 | + | import {createRenderer} from './lib/create-renderer.js' |
|
7 | + | import {createPlugin} from './lib/create-plugin.js' |
|
7 | 8 | ||
8 | - | function renderSvg(options) { |
|
9 | - | return createRenderer(createInput(), createOutput(options)) |
|
10 | - | } |
|
9 | + | const rehypeMathJaxSvg = createPlugin((options) => |
|
10 | + | createRenderer(options, new SVG(options.svg)) |
|
11 | + | ) |
|
12 | + | ||
13 | + | export default rehypeMathJaxSvg |
Learn more Showing 3 files with coverage changes found.
packages/rehype-mathjax/lib/create-renderer.js
packages/rehype-mathjax/lib/create-adaptor.js
packages/rehype-mathjax/lib/create-plugin.js
Files | Coverage |
---|---|
packages | 100.00% |
Project Totals (9 files) | 100.00% |
63a5f76
accaf29
c4d9ace
08c7efc
21a430e
326f164
fec9acc
26bb0e3
dc2d10c
e7e36f0
f9c559e
fa4ada1
b2066bb
849960c
d2f2dc7
a54c27b
10686c4
68b797d
f2af1bd
ce0ba8c
a98996f
d90fd19
b65a156
1809416
7676a20
8ec6c96
fa17953
52b1458
3f97570
5cfcbbf
9193bc2
52d3acb
db0d5a5
c6fc7a0
6899b07
0b77136
edf4ca2
5d86d87
a68e8b8
2948e91
b7ecce0
769a827
ed4b492
7efe5f6
1f04763
0b5f209
5136ded
2e4ae4b
9ef6604
c7d0aee
6400b20
a585a46
8ad51d0
1abc044
72d1000
11ce981
9469a26
7bbce01
29a7816
f0f852b
6675ba0
39070ab
5afd06d
d84223d
5011621
9b4b3c3
0523bd2
a6dbb93
415e180
d57f0cf
01c9295
70c1e27
d41639b
abc25a1
cc54782
b82ce7b
dedc472
fdf2309
6c93942
5313419