Treat svg-wrapping spans differently from DOM-wrapping spans. (#1239)

* Treat svg-wrapping spans differently from DOM-wrapping spans.

In preparation for the conversion of buildHTML to @flow, separate the two
different uses of domTree.span -- one to wrap a single SVG and one to wrap
arbitrary DOM nodes. This separation is to help avoid type issues that pop up
due to buildHTML methods accessing the .children field of spans as if they are
DOM elements and not SVG ones.

* Simplify the domTree DOM definitions based on separation of two span types.
This commit is contained in:
Ashish Myles
2018-03-27 22:47:15 -04:00
committed by GitHub
parent e31cceed58
commit 850a0713cb
6 changed files with 90 additions and 76 deletions

View File

@@ -7,7 +7,7 @@ import Settings from "./Settings";
import Style from "./Style";
import type ParseNode from "./ParseNode";
import type domTree from "./domTree";
import type {DomSpan} from "./domTree";
const optionsFromSettings = function(settings: Settings) {
return new Options({
@@ -20,7 +20,7 @@ export const buildTree = function(
tree: ParseNode[],
expression: string,
settings: Settings,
): domTree.span {
): DomSpan {
const options = optionsFromSettings(settings);
// `buildHTML` sometimes messes with the parse tree (like turning bins ->
// ords), so we build the MathML version first.
@@ -42,7 +42,7 @@ export const buildHTMLTree = function(
tree: ParseNode[],
expression: string,
settings: Settings,
): domTree.span {
): DomSpan {
const options = optionsFromSettings(settings);
const htmlNode = buildHTML(tree, options);
const katexNode = buildCommon.makeSpan(["katex"], [htmlNode]);