Preserve QWord subscript superscript in DOCX
This commit is contained in:
@@ -119,6 +119,25 @@ describe("wordOffice helpers", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves HTML subscript and superscript as inline runs for DOCX", () => {
|
||||
const blocks = htmlToWordBlocks('<p>H<sub>2</sub>O m<sup>2</sup> <span style="vertical-align: super;">x</span></p>');
|
||||
|
||||
expect(blocks).toEqual([
|
||||
{
|
||||
type: "paragraph",
|
||||
text: "H2O m2 x",
|
||||
runs: [
|
||||
{ text: "H" },
|
||||
{ text: "2", subscript: true },
|
||||
{ text: "O m" },
|
||||
{ text: "2", superscript: true },
|
||||
{ text: " " },
|
||||
{ text: "x", superscript: true }
|
||||
]
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
it("сохраняет выравнивание абзацев и заголовков для DOCX", () => {
|
||||
const blocks = htmlToWordBlocks(`
|
||||
<h1 align="right">Итоги</h1>
|
||||
@@ -405,6 +424,27 @@ describe("wordOffice helpers", () => {
|
||||
expect(wordInlineRunsToTextRunOptions([{ text: "Deleted", strike: true }])).toEqual([{ text: "Deleted", strike: true }]);
|
||||
});
|
||||
|
||||
it("converts subscript and superscript inline runs into docx parameters", () => {
|
||||
expect(
|
||||
wordInlineRunsToTextRunOptions([
|
||||
{ text: "2", subscript: true },
|
||||
{ text: "2", superscript: true }
|
||||
])
|
||||
).toEqual([
|
||||
{ text: "2", subScript: true },
|
||||
{ text: "2", superScript: true }
|
||||
]);
|
||||
});
|
||||
|
||||
it("writes subscript and superscript to exported DOCX XML", async () => {
|
||||
const blob = await exportDocxBlob("Indexes.docx", "<p>H<sub>2</sub>O m<sup>2</sup></p>");
|
||||
const zip = await JSZip.loadAsync(await blob.arrayBuffer());
|
||||
const documentXml = await zip.file("word/document.xml")?.async("string");
|
||||
|
||||
expect(documentXml).toMatch(/<w:vertAlign\b[^>]*w:val="subscript"[^>]*\/>/);
|
||||
expect(documentXml).toMatch(/<w:vertAlign\b[^>]*w:val="superscript"[^>]*\/>/);
|
||||
});
|
||||
|
||||
it("записывает зачеркнутый текст в XML экспортированного DOCX", async () => {
|
||||
const blob = await exportDocxBlob("Зачеркнутый.docx", "<p><s>Удаленный текст</s></p>");
|
||||
const zip = await JSZip.loadAsync(await blob.arrayBuffer());
|
||||
|
||||
Reference in New Issue
Block a user