-
Notifications
You must be signed in to change notification settings - Fork 83
fix(plugin-formula): 修复公式绝对值分隔符长度异常 #882
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@wangeditor-next/plugin-formula': patch | ||
| --- | ||
|
|
||
| fix formula absolute value delimiter rendering by switching formula card output to htmlAndMathml and documenting required css import |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import '../src/register-custom-elem' | ||
|
|
||
| describe('plugin-formula custom element', () => { | ||
| it('renders htmlAndMathml output and keeps stretchy absolute delimiters', () => { | ||
| const elem = document.createElement('w-e-formula-card') | ||
| const formula = String.raw`\left|-2\frac{4}{7}\right|` | ||
|
|
||
| elem.setAttribute('data-value', formula) | ||
| document.body.appendChild(elem) | ||
|
|
||
| expect(elem.shadowRoot).toBeNull() | ||
| expect(elem.querySelector('.katex')).not.toBeNull() | ||
| expect(elem.querySelector('.katex-html')).not.toBeNull() | ||
| expect(elem.querySelector('.katex-html .delimsizing.mult')).not.toBeNull() | ||
|
|
||
| elem.remove() | ||
| }) | ||
| }) | ||
|
Comment on lines
+3
to
+18
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major | 🏗️ Heavy lift Add the required round-trip serialization coverage for this style-related change. This adds a useful DOM regression test, but it still misses the required round-trip matrix ( As per coding guidelines, " 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ import './native-shim' | |
| import katex from 'katex' | ||
|
|
||
| class WangEditorFormulaCard extends HTMLElement { | ||
| private span: HTMLElement | ||
| private span: HTMLElement | null = null | ||
|
|
||
| // 监听的 attr | ||
| static get observedAttributes() { | ||
|
|
@@ -17,13 +17,6 @@ class WangEditorFormulaCard extends HTMLElement { | |
|
|
||
| constructor() { | ||
| super() | ||
| const shadow = this.attachShadow({ mode: 'open' }) | ||
| const document = shadow.ownerDocument | ||
| const span = document.createElement('span') | ||
|
|
||
| span.style.display = 'inline-block' | ||
| shadow.appendChild(span) | ||
| this.span = span | ||
| } | ||
|
|
||
| // connectedCallback() { | ||
|
|
@@ -45,10 +38,25 @@ class WangEditorFormulaCard extends HTMLElement { | |
| } | ||
| } | ||
|
|
||
| private ensureSpan() { | ||
| if (this.span) { return this.span } | ||
|
|
||
| const document = this.ownerDocument || window.document | ||
| const span = document.createElement('span') | ||
|
|
||
| span.style.display = 'inline-block' | ||
| this.appendChild(span) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Appending the KaTeX render container into the custom element’s light DOM makes Useful? React with 👍 / 👎. |
||
| this.span = span | ||
|
|
||
| return span | ||
| } | ||
|
|
||
| private render(value: string) { | ||
| katex.render(value, this.span, { | ||
| const span = this.ensureSpan() | ||
|
|
||
| katex.render(value, span, { | ||
| throwOnError: false, | ||
| output: 'mathml', | ||
| output: 'htmlAndMathml', | ||
| }) | ||
| } | ||
| } | ||
|
|
||
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.
Ensure cleanup runs even when an assertion fails.
elem.remove()should be infinallyto avoid leaking DOM state on failed assertions.Suggested change
it('renders htmlAndMathml output and keeps stretchy absolute delimiters', () => { const elem = document.createElement('w-e-formula-card') const formula = String.raw`\left|-2\frac{4}{7}\right|` - elem.setAttribute('data-value', formula) - document.body.appendChild(elem) - - expect(elem.shadowRoot).toBeNull() - expect(elem.querySelector('.katex')).not.toBeNull() - expect(elem.querySelector('.katex-html')).not.toBeNull() - expect(elem.querySelector('.katex-html .delimsizing.mult')).not.toBeNull() - - elem.remove() + try { + elem.setAttribute('data-value', formula) + document.body.appendChild(elem) + + expect(elem.shadowRoot).toBeNull() + expect(elem.querySelector('.katex')).not.toBeNull() + expect(elem.querySelector('.katex-html')).not.toBeNull() + expect(elem.querySelector('.katex-html .delimsizing.mult')).not.toBeNull() + } finally { + elem.remove() + } })🤖 Prompt for AI Agents