|
| 1 | +import {MathML} from "../../../mathjax3/input/mathml.js"; |
| 2 | +import {CHTML} from "../../../mathjax3/output/chtml.js"; |
| 3 | +import {SVG} from "../../../mathjax3/output/svg.js"; |
| 4 | +import {HTMLMathItem} from "../../../mathjax3/handlers/html/HTMLMathItem.js"; |
| 5 | +import {HTMLDocument} from "../../../mathjax3/handlers/html/HTMLDocument.js"; |
| 6 | +import {handleRetriesFor} from "../../../mathjax3/util/Retries.js"; |
| 7 | +import {browserAdaptor} from "../../../mathjax3/adaptors/browserAdaptor.js"; |
| 8 | + |
| 9 | +let mml = new MathML({forceReparse: true}); |
| 10 | +let chtml = new CHTML({fontURL: '../../mathjax2/css/'}); |
| 11 | +let svg = new SVG(); |
| 12 | + |
| 13 | +let docs = { |
| 14 | + CHTML: new HTMLDocument(document, browserAdaptor(), {InputJax: mml, OutputJax: chtml}), |
| 15 | + SVG: new HTMLDocument(document, browserAdaptor(), {InputJax: mml, OutputJax: svg}) |
| 16 | +}; |
| 17 | + |
| 18 | +const samples = [ |
| 19 | + '<mjx-samples>', |
| 20 | + '<mjx-description>', |
| 21 | + '', |
| 22 | + '</mjx-description>', |
| 23 | + '<mjx-tables>', |
| 24 | + '<mjx-chtml-table>', |
| 25 | + '', |
| 26 | + '</mjx-chtml-table>', |
| 27 | + '<mjx-svg-table>', |
| 28 | + '', |
| 29 | + '</mjx-svg-table>', |
| 30 | + '</mjx-tables>', |
| 31 | + '</mjx-samples>' |
| 32 | +]; |
| 33 | + |
| 34 | +const div = document.createElement('div'); |
| 35 | +const template = document.getElementsByTagName('mjx-template')[0]; |
| 36 | + |
| 37 | +function CreateMathML() { |
| 38 | + const mathml = template.innerHTML; |
| 39 | + template.innerHTML = mathml.replace(/\&/g, '&') |
| 40 | + .replace(/</g, '<') |
| 41 | + .replace(/>/g, '>') |
| 42 | + .replace(/\n/g, '<br/>') |
| 43 | + .replace(/\s/g, '\u00A0'); |
| 44 | + Substitute(mathml, window.variables, ''); |
| 45 | +} |
| 46 | + |
| 47 | +function Substitute(mml, data, descr) { |
| 48 | + if (data.length === 0) { |
| 49 | + addMathML(mml, descr); |
| 50 | + } else { |
| 51 | + const n = data.length - 1; |
| 52 | + const [name, values] = data[n]; |
| 53 | + const rest = data.slice(0, n); |
| 54 | + const re = new RegExp('\\{'+name+'\\}', 'g'); |
| 55 | + for (const value of values) { |
| 56 | + Substitute(mml.replace(re, value), rest, name + ': <b>' + value + '</b><br/>' + descr); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +function addMathML(mml, descr) { |
| 62 | + samples[2] = descr; |
| 63 | + samples[6] = samples[9] = mml; |
| 64 | + div.innerHTML = samples.join('\n'); |
| 65 | + template.parentNode.insertBefore(div.firstChild, template); |
| 66 | +} |
| 67 | + |
| 68 | +CreateMathML(); |
| 69 | + |
| 70 | +function linkTables(n, m, arrow) { |
| 71 | + let N = String(n); |
| 72 | + if (N.length == 1) { |
| 73 | + N = '0' + N; |
| 74 | + } |
| 75 | + return '<a href="tables-' + N + '.html"' + (n === m ? ' disabled="true"' : '') + '>&#x' + arrow + ';</a>'; |
| 76 | +} |
| 77 | + |
| 78 | +const testNo = parseInt(this.location.pathname.match(/-(\d+)\.html$/)[1]); |
| 79 | +const maxTest = 60; |
| 80 | + |
| 81 | +const nav = document.body.appendChild(document.createElement('div')); |
| 82 | +nav.id = "navigation"; |
| 83 | +nav.innerHTML = [ |
| 84 | + linkTables(testNo - 1, 0, '25C4'), |
| 85 | + linkTables(testNo + 1, maxTest + 1, '25BA') |
| 86 | +].join(' '); |
| 87 | + |
| 88 | + |
| 89 | +docs.CHTML |
| 90 | + .findMath({elements: ['mjx-chtml-table']}) |
| 91 | + .compile() |
| 92 | + .getMetrics() |
| 93 | + .typeset() |
| 94 | + .updateDocument(); |
| 95 | +docs.SVG |
| 96 | + .findMath({elements: ['mjx-svg-table']}) |
| 97 | + .compile() |
| 98 | + .getMetrics() |
| 99 | + .typeset() |
| 100 | + .updateDocument(); |
0 commit comments