fix(docx): inline EQ fields with single-quoted fldCharType (#382)
FLD_CHAR_RE only matched double quotes, leaving single-quoted EQ fields as raw instrText. Co-authored-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
This commit is contained in:
co-authored by
Aniruddha Adak
parent
ef04164b02
commit
4c17dc0036
@@ -266,7 +266,7 @@ export function eqFieldToOmml(instr: string): EqField | null {
|
||||
return { omml: `<m:oMath>${body.omml}</m:oMath>`, text: body.text }
|
||||
}
|
||||
|
||||
const FLD_CHAR_RE = /<w:fldChar[^>]*w:fldCharType="(begin|separate|end)"/g
|
||||
const FLD_CHAR_RE = /<w:fldChar[^>]*w:fldCharType=(?:"(begin|separate|end)"|'(begin|separate|end)')/g
|
||||
|
||||
/**
|
||||
* Paragraph XML with every renderable EQ field replaced by a plain run of its
|
||||
@@ -282,10 +282,11 @@ export function inlineEqFieldResults(xml: string): string {
|
||||
let m: RegExpExecArray | null
|
||||
FLD_CHAR_RE.lastIndex = 0
|
||||
while ((m = FLD_CHAR_RE.exec(xml)) !== null) {
|
||||
if (m[1] === 'begin') {
|
||||
const kind = m[1] ?? m[2]
|
||||
if (kind === 'begin') {
|
||||
if (depth === 0) spanStart = runStartBefore(xml, m.index)
|
||||
depth++
|
||||
} else if (m[1] === 'end') {
|
||||
} else if (kind === 'end') {
|
||||
depth = Math.max(0, depth - 1)
|
||||
if (depth !== 0 || spanStart < 0) continue
|
||||
const spanEnd = xml.indexOf('</w:r>', m.index) + '</w:r>'.length
|
||||
|
||||
@@ -92,6 +92,14 @@ describe('EQ field instructions', () => {
|
||||
`<w:p><w:r>${SZ36}<w:t xml:space="preserve">1/2</w:t></w:r></w:p>`,
|
||||
)
|
||||
})
|
||||
|
||||
it('inlineEqFieldResults handles single-quoted fldCharType', () => {
|
||||
const xml =
|
||||
`<w:p><w:r><w:fldChar w:fldCharType='begin'/></w:r>` +
|
||||
`<w:r><w:instrText xml:space="preserve"> EQ \\f(a,b) </w:instrText></w:r>` +
|
||||
`<w:r><w:fldChar w:fldCharType='end'/></w:r></w:p>`
|
||||
expect(inlineEqFieldResults(xml)).toContain('a/b')
|
||||
})
|
||||
})
|
||||
|
||||
describe('EQ field paragraphs', () => {
|
||||
|
||||
Reference in New Issue
Block a user