Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update check for spacelike mml nodes to be more sensible. (mathjax/MathJax#3098) #1002

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ts/core/MmlTree/MmlNodes/mspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ export class MmlMspace extends AbstractMmlTokenNode {
}

/**
* Only make mspace be space-like if it doesn't have certain attributes
*
* @override
*/
public get isSpacelike() {
return true;
return this.attributes.getExplicit('linebreak') === undefined && this.canBreak;
}

/**
Expand Down
11 changes: 9 additions & 2 deletions ts/core/MmlTree/MmlNodes/mtext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ export class MmlMtext extends AbstractMmlTokenNode {
}

/**
* <mtext> is always space-like according to the spec
* <mtext> is always space-like according to the spec,
* but we make it so only if it contains only spaces and
* doesn't have certain attributes
*
* @override
*/
public get isSpacelike() {
return true;
const attributes = this.attributes;
const spaces = !!this.getText().match(/^\s*$/);
return spaces && (attributes.getExplicit('mathbackground') === undefined &&
attributes.getExplicit('background') === undefined &&
attributes.getExplicit('style') === undefined);
Copy link
Member

@zorkow zorkow Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should those attributes go into a dedicated constant, in case we need more or need to change them in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a couple of places where this type of check is being made, and I was thinking about making a service function to check them. I'll look into that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added hasOneOf() to the Attributes object to handle this, and made lists for the styles to use for space and mtext elements. I also added a hasExplicit() method to the Attributes object to make checking for explicit attributes more natural, and unset() to make removing an attribute easier. I edited a number of other files to use these new functions. So there are a bunch of new edits here. Do you want to review again?

}

}