${title}`).test(xml));
@@ -118,7 +118,8 @@ test('PPTX layout: no text is cut; long steps carry on to "(continued)" slides',
const { slides } = deck(ast, path.join(root, 'out'));
const all = slides.map(slideText).join(' ');
for (const step of ast.steps) {
- for (const para of step.descriptionText.split('\n')) assert.ok(all.includes(para.trim()), `"${para.slice(0, 40)}…" is on a slide`);
+ // List items are real bullets on the slide, not "•" in the text.
+ for (const para of step.descriptionText.split('\n')) assert.ok(all.includes(para.replace(/^• /, '').trim()), `"${para.slice(0, 40)}…" is on a slide`);
}
assert.ok(all.includes('Do not reset service accounts') && all.includes('Service accounts break integrations'));
const long = stepSlides(slides, 'If the reset email never arrives');
@@ -179,7 +180,8 @@ test('PPTX layout: speaker notes hold each step’s full text, and can be left o
for (const [name, xml] of z) {
if (!name.endsWith('.rels')) continue;
const base = path.posix.dirname(path.posix.dirname(name));
- for (const m of xml.matchAll(/Target="([^"]+)"/g)) assert.ok(z.has(path.posix.normalize(path.posix.join(base, m[1]))), `${name} → ${m[1]}`);
+ // Web links point outside the package.
+ for (const m of xml.matchAll(/Target="([^"]+)"(?! TargetMode="External")/g)) assert.ok(z.has(path.posix.normalize(path.posix.join(base, m[1]))), `${name} → ${m[1]}`);
}
const none = deck(ast, path.join(root, 'none'), { speakerNotes: false }).z;
diff --git a/tests/unit/rich-text-exports.test.js b/tests/unit/rich-text-exports.test.js
new file mode 100644
index 0000000..24938c6
--- /dev/null
+++ b/tests/unit/rich-text-exports.test.js
@@ -0,0 +1,201 @@
+'use strict';
+
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const path = require('node:path');
+
+const { GuideStore } = require('../../core/store');
+const { buildRenderAst } = require('../../core/renderast');
+const { exportDocx } = require('../../exporters/docx');
+const { exportPptx } = require('../../exporters/pptx');
+const { richParagraphs, sliceRuns, markedText } = require('../../exporters/pptx-text');
+const { WordRichText } = require('../../exporters/word-rich');
+const { unzipSync } = require('../../core/zip');
+const { encodePng } = require('../../core/png');
+const raster = require('../../core/raster');
+const { makeTmpDir, rmrf } = require('./helpers');
+
+const LONG = 'Check the account name and email carefully before you continue. The reset signs the user out of every device. '.repeat(30);
+
+/** A guide whose steps use every kind of formatting a description can hold. */
+function richGuide(t) {
+ const root = makeTmpDir('rich-text');
+ t.after(() => rmrf(root));
+ const store = new GuideStore(path.join(root, 'data'));
+ const guide = store.createGuide({ title: 'Rich text', descriptionHtml: 'For the service desk.
' });
+ const png = encodePng(raster.createImage(640, 380, [240, 242, 245, 255]));
+ const first = store.addStep(guide.guideId, {
+ title: 'Open the Users page',
+ descriptionHtml: 'Select Users. See the Users guide for bulk changes and old notes.
',
+ }, png, { width: 640, height: 380 });
+ store.addStep(guide.guideId, {
+ title: 'Reset the password',
+ descriptionHtml: `Run adminctl unlock first:
- Pick Email a link.
- Choose Send.
`
+ + `The old password stops working.
Go back to the Users page.
`,
+ textBlocks: [{ position: 'after-description', level: 'success', title: 'Shortcut', descriptionHtml: 'Press Ctrl+R:
' }],
+ }, png, { width: 640, height: 380 });
+ store.addStep(guide.guideId, { kind: 'empty', title: 'A long one', descriptionHtml: `Start with ${LONG} and ${LONG}
` });
+ return { root, ast: buildRenderAst(store, guide.guideId), firstId: first.stepId };
+}
+
+const unzip = (file) => new Map(unzipSync(fs.readFileSync(file)).map((e) => [e.name, e.data.toString('utf8')]));
+
+test('Word keeps description formatting: bold, italic, strikethrough, code, links, real lists and quotes', (t) => {
+ const { root, ast } = richGuide(t);
+ const z = unzip(exportDocx(ast, path.join(root, 'docx')).file);
+ const doc = z.get('word/document.xml');
+ const rels = z.get('word/_rels/document.xml.rels');
+ assert.match(doc, /<\/w:rPr>Users<\/w:t><\/w:r>/, 'bold');
+ assert.match(doc, /[^]*?bulk<\/w:t>/, 'italic');
+ assert.match(doc, /[^]*?old<\/w:t>/, 'strikethrough');
+ assert.match(doc, /]*\/>[^]*?adminctl unlock<\/w:t>/, 'inline code');
+ // A web link is a hyperlink relationship; a link to a step goes to its heading's bookmark.
+ const id = doc.match(/[^]*?<\/w:rPr>Users guide<\/w:t>/)[1];
+ assert.match(rels, new RegExp(`Id="${id}" Type="[^"]+/hyperlink" Target="https://docs.example.com/users" TargetMode="External"`));
+ const anchor = doc.match(/[^]*?the Users page/)[1];
+ assert.match(doc, new RegExp(`[^]*?Open the Users page`));
+ // Real numbered and bulleted lists, with a numbering part.
+ const items = [...doc.matchAll(/<\/w:numPr>[^]*?([^<]+) [m[1], m[2]]);
+ assert.deepEqual(items.map(([, text]) => text), ['Pick ', 'Choose ', 'works anywhere']);
+ assert.equal(items[0][0], items[1][0], 'one numbered list');
+ assert.notEqual(items[1][0], items[2][0], 'then a separate bulleted one');
+ const numbering = z.get('word/numbering.xml');
+ assert.match(numbering, //);
+ assert.match(numbering, //, 'a bullet any font has');
+ assert.match(rels, /Type="[^"]+\/numbering" Target="numbering.xml"/);
+ assert.match(z.get('[Content_Types].xml'), /PartName="\/word\/numbering.xml" ContentType="[^"]+numbering\+xml"/);
+ assert.match(doc, /[^]*?The old password stops working\./, 'quote');
+ // The guide's description on the cover keeps its formatting too.
+ assert.match(doc, /<\/w:rPr>service desk);
+});
+
+test('Word callouts keep their formatting in one box, with lists as lines inside it', (t) => {
+ const { root, ast } = richGuide(t);
+ const doc = unzip(exportDocx(ast, path.join(root, 'docx')).file).get('word/document.xml');
+ const box = '';
+ const paras = [...doc.matchAll(/([^]*?)<\/w:pPr>([^]*?)<\/w:p>/g)].filter((m) => m[1].includes(box));
+ assert.equal(paras.length, 3, 'label, text and list item share the border and shading');
+ assert.match(paras[0][2], /Tip: Shortcut/);
+ assert.match(paras[1][2], /[^]*?Ctrl\+R/);
+ assert.match(paras[2][2], /• <\/w:t>[^]*?works in /);
+ assert.ok(paras.every((m) => !m[1].includes('') && !m[1].includes('/, 'space after the box, not inside it');
+});
+
+test('PowerPoint keeps description formatting, real bullets and numbers, and links', (t) => {
+ const { root, ast } = richGuide(t);
+ const { file, slideCount } = exportPptx(ast, path.join(root, 'pptx'));
+ const z = unzip(file);
+ const slides = Array.from({ length: slideCount }, (_, i) => z.get(`ppt/slides/slide${i + 1}.xml`));
+ const slideOf = (title) => slides.findIndex((xml) => xml.includes('name="Step number"') && xml.includes(`${title}`)) + 1;
+ const first = slideOf('Open the Users page');
+ const second = slideOf('Reset the password');
+ const s1 = z.get(`ppt/slides/slide${first}.xml`);
+ const s2 = z.get(`ppt/slides/slide${second}.xml`);
+ assert.match(s1, /[^]*?Users<\/a:t>/, 'bold');
+ assert.match(s1, /i="1"[^>]*>[^]*?bulk<\/a:t>/, 'italic');
+ assert.match(s1, /strike="sngStrike"[^>]*>[^]*?old<\/a:t>/, 'strikethrough');
+ assert.match(s2, /<\/a:rPr>adminctl unlock<\/a:t>/, 'inline code');
+ assert.match(s2, /<\/a:pPr>[^]*?Pick , 'a numbered list');
+ assert.match(s2, /<\/a:pPr>[^]*?Choose );
+ assert.match(s2, /<\/a:pPr>[^]*?works anywhere<\/a:t>/, 'a bulleted list');
+ assert.match(s2, /i="1"[^>]*>[^]*?The old password stops working\.<\/a:t>/, 'quote');
+ // The web link points at its page; the step link jumps to that step's slide.
+ const web = s1.match(/<\/a:rPr>Users guide<\/a:t>/)[1];
+ assert.match(z.get(`ppt/slides/_rels/slide${first}.xml.rels`), new RegExp(`Id="${web}" Type="[^"]+/hyperlink" Target="https://docs.example.com/users" TargetMode="External"`));
+ const jump = s2.match(/<\/a:rPr>the Users page<\/a:t>/)[1];
+ assert.match(z.get(`ppt/slides/_rels/slide${second}.xml.rels`), new RegExp(`Id="${jump}" Type="[^"]+/slide" Target="slide${first}.xml"`));
+ // A callout's text keeps its formatting, its list items marked.
+ assert.match(s2, /Tip: Shortcut<\/a:t>[^]*?b="1"[^>]*>[^]*?Ctrl\+R<\/a:t>[^]*?• <\/a:t>[^]*?works in <\/a:t>/);
+});
+
+test('PowerPoint keeps formatting on both sides of a split onto a "(continued)" slide', (t) => {
+ const { root, ast } = richGuide(t);
+ const { file, slideCount } = exportPptx(ast, path.join(root, 'pptx'));
+ const z = unzip(file);
+ const slides = Array.from({ length: slideCount }, (_, i) => z.get(`ppt/slides/slide${i + 1}.xml`)).filter((xml) => xml.includes('A long one'));
+ assert.ok(slides.length >= 2, 'the long step continues');
+ const runs = (xml) => [...xml.matchAll(/]*?b="(\d)"(?: i="1")?[^>]*>[^]*?([^<]*)<\/a:t>/g)];
+ // Bold text stays bold and italic text stays italic on every slide it reaches.
+ for (const xml of slides) {
+ for (const m of [...xml.matchAll(/]*)>(?:(?!<\/a:rPr>)[^])*<\/a:rPr>([^<]*)<\/a:t>/g)]) {
+ if (m[2].startsWith('Check the account') && !m[1].includes('sz="2800"')) assert.ok(m[1].includes('b="1"') || m[1].includes('i="1"'), `"${m[2].slice(0, 30)}" keeps its style`);
+ }
+ }
+ assert.ok(runs(slides[0]).length > 0);
+});
+
+test('slide text helpers: paragraphs, list markers and splitting runs', () => {
+ const paras = richParagraphs('A bold word
next line
- one
- two
');
+ assert.deepEqual(paras.slice(0, 2).map((p) => p.text), ['A bold word', 'next line']);
+ assert.deepEqual(paras[0].runs.map((r) => [r.text, Boolean(r.bold)]), [['A ', false], ['bold', true], [' word', false]]);
+ assert.deepEqual(paras.slice(2, 4).map(markedText), ['1. one', '2. two']);
+ assert.deepEqual(paras[4].rows, [['A', 'B'], ['1', '2']]);
+ const runs = paras[0].runs;
+ assert.deepEqual(sliceRuns(runs, 0, 4).map((r) => r.text), ['A ', 'bo']);
+ assert.deepEqual(sliceRuns(runs, 6).map((r) => [r.text, Boolean(r.bold)]), [['word', false]], 'leading space dropped');
+});
+
+test('Word rich text: the Confluence (styled) form refers to styles and keeps the Symbol bullet', () => {
+ const rels = [];
+ const rich = new WordRichText({ ast: { steps: [] }, rel: (type, target) => { rels.push(target); return 'rId9'; }, anchorFor: () => 'x', table: () => '' });
+ const xml = rich.richText('q
l
');
+ assert.match(xml, //);
+ assert.match(xml, //);
+ assert.match(xml, //);
+ assert.deepEqual(rels, ['https://example.com']);
+ assert.match(rich.numberingXml(), /[^]*? rmrf(root));
+ const store = new GuideStore(path.join(root, 'data'));
+ const guide = store.createGuide({ title: 'One step' });
+ store.addStep(guide.guideId, { kind: 'empty', title: 'The step', descriptionHtml });
+ return { root, ast: buildRenderAst(store, guide.guideId) };
+}
+
+const NESTED = '- Parent
- Next
';
+
+test('nested lists keep their depth on slides and in Word, and the outer list keeps counting', (t) => {
+ assert.deepEqual(richParagraphs(NESTED).map((p) => [p.text, p.list.level]), [['Parent', 0], ['Child', 1], ['Grandchild', 2], ['Next', 0]]);
+ assert.deepEqual(richParagraphs(NESTED).map(markedText), ['1. Parent', ' • Child', ' 1. Grandchild', '2. Next']);
+
+ const { root, ast } = oneStepGuide(t, NESTED);
+ const doc = unzip(exportDocx(ast, path.join(root, 'docx')).file).get('word/document.xml');
+ const items = [...doc.matchAll(/[^]*?([^<]*)<\/w:t>/g)]
+ .map((m) => ({ text: m[3], lvl: Number(m[1]), num: m[2] }));
+ assert.deepEqual(items.map((i) => [i.text, i.lvl]), [['Parent', 0], ['Child', 1], ['Grandchild', 2], ['Next', 0]]);
+ assert.equal(items[3].num, items[0].num, '"Next" continues the outer numbered list, so it is numbered 2');
+});
+
+test('links with several query parameters keep their "&" in Word and PowerPoint', (t) => {
+ const { root, ast } = oneStepGuide(t, 'See the page.
');
+ const docxRels = unzip(exportDocx(ast, path.join(root, 'docx')).file).get('word/_rels/document.xml.rels');
+ assert.match(docxRels, /Target="https:\/\/example\.com\/\?a=1&b=2" TargetMode="External"/);
+ const pptx = unzip(exportPptx(ast, path.join(root, 'pptx')).file);
+ const slideRels = [...pptx].filter(([name]) => /^ppt\/slides\/_rels\/slide\d+\.xml\.rels$/.test(name)).map(([, xml]) => xml).join('');
+ assert.match(slideRels, /Target="https:\/\/example\.com\/\?a=1&b=2" TargetMode="External"/);
+ assert.doesNotMatch(docxRels + slideRels, /&/);
+});
+
+test('PowerPoint splits long unbroken text onto "(continued)" slides without repeating or losing any of it', (t) => {
+ // No spaces to wrap at, so lines break between characters.
+ const bold = '粗'.repeat(1500);
+ const plain = '文'.repeat(1500);
+ const { root, ast } = oneStepGuide(t, `${bold}${plain}
`);
+ const { file, slideCount } = exportPptx(ast, path.join(root, 'pptx'));
+ const z = unzip(file);
+ const slides = Array.from({ length: slideCount }, (_, i) => z.get(`ppt/slides/slide${i + 1}.xml`)).filter((xml) => xml.includes('The step'));
+ assert.ok(slides.length >= 2, 'the step continues');
+ const runs = slides.flatMap((xml) => [...xml.matchAll(/]*)>(?:(?!<\/a:rPr>)[^])*<\/a:rPr>([^<]*)<\/a:t>/g)]);
+ const count = (ch) => runs.reduce((n, m) => n + [...m[2]].filter((c) => c === ch).length, 0);
+ assert.equal(count('粗'), 1500);
+ assert.equal(count('文'), 1500);
+ for (const m of runs) {
+ if (m[2].includes('粗')) assert.ok(m[1].includes('b="1"') && !m[2].includes('文'), 'bold text stays bold and apart from plain text');
+ }
+});