(this: Renderer, {
h,
cursor,
block,
token,
outerClass,
}: ISyntaxRenderOptions & { token: CodeEmojiMathToken })
| 8 | import 'katex/dist/katex.min.css'; |
| 9 | |
| 10 | export default function inlineMath(this: Renderer, { |
| 11 | h, |
| 12 | cursor, |
| 13 | block, |
| 14 | token, |
| 15 | outerClass, |
| 16 | }: ISyntaxRenderOptions & { token: CodeEmojiMathToken }) { |
| 17 | const className = this.getClassName(outerClass, block, token, cursor); |
| 18 | const { i18n } = this.muya; |
| 19 | const mathSelector |
| 20 | = className === CLASS_NAMES.MU_HIDE |
| 21 | ? `span.${className}.${CLASS_NAMES.MU_MATH}` |
| 22 | : `span.${CLASS_NAMES.MU_MATH}`; |
| 23 | |
| 24 | const { start, end } = token.range; |
| 25 | const { marker } = token; |
| 26 | |
| 27 | const startMarker = this.highlight( |
| 28 | h, |
| 29 | block, |
| 30 | start, |
| 31 | start + marker.length, |
| 32 | token, |
| 33 | ); |
| 34 | const endMarker = this.highlight(h, block, end - marker.length, end, token); |
| 35 | const content = this.highlight( |
| 36 | h, |
| 37 | block, |
| 38 | start + marker.length, |
| 39 | end - marker.length, |
| 40 | token, |
| 41 | ); |
| 42 | |
| 43 | const { content: math, type } = token; |
| 44 | |
| 45 | const { loadMathMap } = this; |
| 46 | |
| 47 | const displayMode = false; |
| 48 | const key = `${math}_${type}`; |
| 49 | let mathVnode = null; |
| 50 | let previewSelector = `span.${CLASS_NAMES.MU_MATH_RENDER}`; |
| 51 | if (loadMathMap.has(key)) { |
| 52 | mathVnode = loadMathMap.get(key); |
| 53 | } |
| 54 | else { |
| 55 | try { |
| 56 | const html = katex.renderToString(math, { |
| 57 | displayMode, |
| 58 | }); |
| 59 | mathVnode = htmlToVNode(html); |
| 60 | loadMathMap.set(key, mathVnode); |
| 61 | } |
| 62 | catch { |
| 63 | mathVnode = `<${i18n.t('Invalid Mathematical Formula')}>`; |
| 64 | previewSelector += `.${CLASS_NAMES.MU_MATH_ERROR}`; |
| 65 | } |
| 66 | } |
| 67 |
nothing calls this directly
no test coverage detected