Skip to content

Commit

Permalink
Allow stylesheet to be obtained even after it was created. (mathjax/M…
Browse files Browse the repository at this point in the history
  • Loading branch information
dpvc committed Mar 22, 2021
1 parent c125626 commit 7f838db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions ts/handlers/html/HTMLDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,14 @@ export class HTMLDocument<N, T, D> extends AbstractMathDocument<N, T, D> {
*/
public addStyleSheet() {
const sheet = this.documentStyleSheet();
if (sheet) {
const head = this.adaptor.head(this.document);
let styles = this.findSheet(head, this.adaptor.getAttribute(sheet, 'id'));
const adaptor = this.adaptor;
if (sheet && !adaptor.parent(sheet)) {
const head = adaptor.head(this.document);
let styles = this.findSheet(head, adaptor.getAttribute(sheet, 'id'));
if (styles) {
this.adaptor.replace(sheet, styles);
adaptor.replace(sheet, styles);
} else {
this.adaptor.append(head, sheet);
adaptor.append(head, sheet);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion ts/output/chtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ CommonOutputJax<N, T, D, CHTMLWrapper<N, T, D>, CHTMLWrapperFactory<N, T, D>, CH
*/
public styleSheet(html: MathDocument<N, T, D>) {
if (this.chtmlStyles && !this.options.adaptiveCSS) {
return null; // stylesheet is already added to the document
return this.chtmlStyles; // stylesheet is already added to the document
}
const sheet = this.chtmlStyles = super.styleSheet(html);
this.adaptor.setAttribute(sheet, 'id', CHTML.STYLESHEETID);
Expand Down
2 changes: 1 addition & 1 deletion ts/output/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ CommonOutputJax<N, T, D, SVGWrapper<N, T, D>, SVGWrapperFactory<N, T, D>, SVGFon
*/
public styleSheet(html: MathDocument<N, T, D>) {
if (this.svgStyles) {
return null; // stylesheet is already added to the document
return this.svgStyles; // stylesheet is already added to the document
}
const sheet = this.svgStyles = super.styleSheet(html);
this.adaptor.setAttribute(sheet, 'id', SVG.STYLESHEETID);
Expand Down

0 comments on commit 7f838db

Please sign in to comment.