-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: Support MathML namespace #4364
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1eb9106
feat: Support creating MathML elements
rschristian f413961
test: Add svg & mathml child namespace tests
rschristian ded6e00
refactor: Switch `isSvg` to a `namespace` var to support mathml
rschristian d899c8a
test: Copy over more SVG tests
rschristian fae2f58
refactor: golf & fix comment
rschristian 90edbab
refactor: Fix namespace inheritance from parent
rschristian 5a62c05
test: Determine SVG & MathML determine namespace from parent correctly
rschristian 58a043a
chore: Appease linters
rschristian 7f3d7cb
refactor: golf -- better gzip, worse brotli
rschristian 9c4c61b
test: Remove perhaps superfluous mathml tests for the moment
rschristian 19f7d5b
test: Add tests for namespace after rerender
rschristian 2d07ca8
refactor: golf
rschristian 12b71cf
Merge branch 'main' into feat/mathml
rschristian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { createElement, Component, render } from 'preact'; | ||
import { setupRerender } from 'preact/test-utils'; | ||
import { setupScratch, teardown } from '../_util/helpers'; | ||
|
||
/** @jsx createElement */ | ||
|
||
describe('mathml', () => { | ||
let scratch; | ||
|
||
beforeEach(() => { | ||
scratch = setupScratch(); | ||
}); | ||
|
||
afterEach(() => { | ||
teardown(scratch); | ||
}); | ||
|
||
it('should render with the correct namespace URI', () => { | ||
render(<math />, scratch); | ||
|
||
let namespace = scratch.querySelector('math').namespaceURI; | ||
|
||
expect(namespace).to.equal('http://www.w3.org/1998/Math/MathML'); | ||
}); | ||
|
||
it('should render children with the correct namespace URI', () => { | ||
render( | ||
<math> | ||
<mrow /> | ||
</math>, | ||
scratch | ||
); | ||
|
||
let namespace = scratch.querySelector('mrow').namespaceURI; | ||
|
||
expect(namespace).to.equal('http://www.w3.org/1998/Math/MathML'); | ||
}); | ||
|
||
it('should inherit correct namespace URI from parent', () => { | ||
const math = document.createElementNS( | ||
'http://www.w3.org/1998/Math/MathML', | ||
'math' | ||
); | ||
scratch.appendChild(math); | ||
|
||
render(<mrow />, scratch.firstChild); | ||
|
||
let namespace = scratch.querySelector('mrow').namespaceURI; | ||
expect(namespace).to.equal('http://www.w3.org/1998/Math/MathML'); | ||
}); | ||
|
||
it('should inherit correct namespace URI from parent upon updating', () => { | ||
setupRerender(); | ||
|
||
const math = document.createElementNS( | ||
'http://www.w3.org/1998/Math/MathML', | ||
'math' | ||
); | ||
scratch.appendChild(math); | ||
|
||
class App extends Component { | ||
state = { show: true }; | ||
componentDidMount() { | ||
// eslint-disable-next-line | ||
this.setState({ show: false }, () => { | ||
expect(scratch.querySelector('mo').namespaceURI).to.equal( | ||
'http://www.w3.org/1998/Math/MathML' | ||
); | ||
}); | ||
} | ||
render() { | ||
return this.state.show ? <mi>1</mi> : <mo>2</mo>; | ||
} | ||
} | ||
|
||
render(<App />, scratch.firstChild); | ||
}); | ||
|
||
it('should transition from DOM to MathML and back', () => { | ||
render( | ||
<div> | ||
<math> | ||
<msup> | ||
<mi>c</mi> | ||
<mn>2</mn> | ||
</msup> | ||
</math> | ||
</div>, | ||
scratch | ||
); | ||
|
||
expect(scratch.firstChild).to.be.an('HTMLDivElement'); | ||
expect(scratch.firstChild.firstChild).to.be.an('MathMLElement'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching this to a ternary shaves off -6b or so but performs a fair bit worse.