Skip to content

Commit

Permalink
Combine unknown elements into a single utext element (allows combinin…
Browse files Browse the repository at this point in the history
…g characters to combine)
  • Loading branch information
dpvc committed Aug 5, 2022
1 parent da143cc commit 115c542
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions ts/output/chtml/Wrappers/TextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,48 @@ export const ChtmlTextNode = (function <N, T, D>(): ChtmlTextNodeClass<N, T, D>
*/
public toCHTML(parents: N[]) {
this.markUsed();
const parent = parents[0];
const adaptor = this.adaptor;
const variant = this.parent.variant;
const text = (this.node as TextNode).getText();
if (text.length === 0) return;
if (variant === '-explicitFont') {
adaptor.append(parents[0], this.jax.unknownText(text, variant, this.getBBox().w));
adaptor.append(parent, this.jax.unknownText(text, variant, this.getBBox().w));
} else {
let utext = '';
const chars = this.remappedText(text, variant);
for (const n of chars) {
const data = (this.getVariantChar(variant, n) as ChtmlCharData)[3];
const font = (data.f ? ' TEX-' + data.f : '');
const node = (data.unknown ?
this.jax.unknownText(String.fromCodePoint(n), variant) :
this.html('mjx-c', {class: this.char(n) + font}, [this.text(data.c || String.fromCodePoint(n))]));
adaptor.append(parents[0], node);
!data.unknown && this.font.charUsage.add([variant, n]);
if (data.unknown) {
utext += String.fromCodePoint(n);
} else {
utext = this.addUtext(utext, variant, parent);
const font = (data.f ? ' TEX-' + data.f : '');
adaptor.append(parent, this.html('mjx-c', {class: this.char(n) + font}, [
this.text(data.c || String.fromCodePoint(n))
]));
this.font.charUsage.add([variant, n]);
}
}
this.addUtext(utext, variant, parent);
}
}

/**
* Append unknown text, if any
*
* @param {string} utext The text to add
* @param {string} variant The mathvariant for the text
* @param {N} parent The parent node where the text is being added
* @return {string} The new value for utext
*/
protected addUtext(utext: string, variant: string, parent: N): string {
if (utext) {
this.adaptor.append(parent, this.jax.unknownText(utext, variant));
}
return '';
}

};

})<any, any, any>();

0 comments on commit 115c542

Please sign in to comment.