π¬ A browser extension and desktop app that turns your clicks into step-by-step guides with annotated screenshots π
TypeScript browser-extensionchrome-extensiondocumentationfirefox-extensionguide-generatorlocal-firstmanifest-v3privacy-firstproductivityreactscreenshotstep-by-step-guidetutorialtypescriptworkflowwxt
feat(export): render blocks as sections in HTML and Markdown
Luis Ortizc7c3839d90e4
diff --git a/src/core/export/__tests__/markdown-export.test.ts b/src/core/export/__tests__/markdown-export.test.tsindex c37d1c8..2296cb8 100644--- a/src/core/export/__tests__/markdown-export.test.ts+++ b/src/core/export/__tests__/markdown-export.test.ts@@ -138,4 +138,65 @@ describe('exportGuideAsMarkdown', () => {const b64 = btoa('pixel-data');expect(md).toContain(b64);});++ it('renders a heading block as an H2 without a step number', async () => {+ const guide = makeGuide();+ const steps = [makeStep({ id: 'block-1', blockType: 'heading', description: 'Section title', url: '' })];++ const md = await exportGuideAsMarkdown(guide, steps, new Map());+ expect(md).toContain('## Section title');+ expect(md).not.toContain('export.stepLabel');+ });++ it('renders a callout block as a blockquote with its variant label', async () => {+ const guide = makeGuide();+ const steps = [+ makeStep({+ id: 'block-1',+ blockType: 'callout',+ calloutVariant: 'warning',+ description: 'Do not skip this',+ url: '',+ }),+ ];++ const md = await exportGuideAsMarkdown(guide, steps, new Map());+ expect(md).toContain('> **blocks.variantWarning**');+ expect(md).toContain('> Do not skip this');+ });++ it('prefixes every line of a multi-line callout', async () => {+ const guide = makeGuide();+ const steps = [makeStep({ id: 'block-1', blockType: 'callout', description: 'First line\nSecond line', url: '' })];++ const md = await exportGuideAsMarkdown(guide, steps, new Map());+ expect(md).toContain('> First line\n> Second line');+ });++ it('keeps step numbering sequential across an interleaved block', async () => {+ const guide = makeGuide();+ const steps = [+ makeStep({ index: 0, description: 'First action' }),+ makeStep({ id: 'block-1', index: 1, blockType: 'heading', description: 'Section title', url: '' }),+ makeStep({ id: 'step-2', index: 2, description: 'Second action' }),+ ];++ const md = await exportGuideAsMarkdown(guide, steps, new Map());+ expect(md).toContain('## export.stepLabel[01]: First action');+ expect(md).toContain('## export.stepLabel[02]: Second action');+ expect(md).not.toContain('export.stepLabel[03]');+ });++ it('counts only action steps in the metadata line', async () => {+ const guide = makeGuide();+ const steps = [+ makeStep({ index: 0 }),+ makeStep({ id: 'block-1', index: 1, blockType: 'heading', description: 'Section title', url: '' }),+ makeStep({ id: 'block-2', index: 2, blockType: 'callout', description: 'Heads up', url: '' }),+ makeStep({ id: 'step-2', index: 3, description: 'Type text' }),+ ];++ const md = await exportGuideAsMarkdown(guide, steps, new Map());+ expect(md).toContain('export.stepsCount[2]');+ });});diff --git a/src/core/export/html-export.ts b/src/core/export/html-export.tsindex f0f5aff..4c6fa39 100644--- a/src/core/export/html-export.ts+++ b/src/core/export/html-export.ts@@ -2,12 +2,29 @@ import { i18n } from '#imports';import { fitLogo, loadBranding } from '@/core/export/branding';import { type ExportOptions, IMAGE_SCALE_FACTORS, loadExportOptions } from '@/core/export/options';import { blobToBase64, escapeHtml, extractDomain, formatDate } from '@/core/export/utils';+import { actionSteps, calloutAccent, isBlock, stepNumbers, tint, variantLabel } from '@/core/guides/blocks';import type { Guide, Screenshot, Step } from '@/core/guides/types';import { renderScreenshot } from '@/core/screenshot/render';const LOGO_MAX_WIDTH = 148;const LOGO_MAX_HEIGHT = 56;+function blockSection(step: Step): string {+ if (step.blockType === 'heading') {+ return `+ <section data-block="heading" style="margin-bottom:26px;">+ <h2 style="font-size:24px;font-weight:700;line-height:1.3;color:#1E1B4B;white-space:pre-wrap;padding-bottom:10px;border-bottom:2px solid #1E1B4B;">${escapeHtml(step.description)}</h2>+ </section>`;+ }++ const accent = calloutAccent(step);+ const label = variantLabel(step.calloutVariant ?? 'info');+ return `+ <section data-block="callout" role="note" aria-label="${escapeHtml(label)}" style="margin-bottom:52px;padding:14px 18px;border-left:3px solid ${accent};border-radius:8px;background:${tint(accent)};">+ <p style="margin:0;font-size:15px;line-height:1.6;color:#1E1B4B;white-space:pre-wrap;">${escapeHtml(step.description)}</p>+ </section>`;+}+function stepUrlLabel(url: string): string {try {const parsed = new URL(url);@@ -29,25 +46,32 @@ export async function exportGuideAsHTML(const accent = brand.accent;const imgWidthPct = Math.round(IMAGE_SCALE_FACTORS[opts.imageScale] * 100);const domain = extractDomain(steps);+ const numbers = stepNumbers(steps);const stepSections: string[] = [];for (const step of steps) {+ if (isBlock(step)) {+ stepSections.push(blockSection(step));+ continue;+ }++ const number = numbers.get(step.id) ?? 0;const screenshot = opts.screenshots ? screenshots.get(step.id) : undefined;let imgHtml = '';if (screenshot) {const b64 = await blobToBase64(await renderScreenshot(screenshot));- const altText = screenshot.edits?.alt || i18n.t('export.stepLabel', [String(step.index + 1)]);+ const altText = screenshot.edits?.alt || i18n.t('export.stepLabel', [String(number)]);imgHtml = `<img src="data:${screenshot.mimeType};base64,${b64}" alt="${escapeHtml(altText)}" style="display:block;width:${imgWidthPct}%;margin-top:14px;border:1px solid #CBD5E1;" />`;}- const stepNumber = String(step.index + 1).padStart(2, '0');+ const stepNumber = String(number).padStart(2, '0');const urlHtml =step.url && opts.stepUrls? `<a href="${escapeHtml(step.url)}" target="_blank" rel="noopener" style="font-size:14px;font-weight:400;color:${accent};">${escapeHtml(stepUrlLabel(step.url))}</a>`: '';stepSections.push(`- <section data-step="${step.index + 1}" style="display:flex;gap:26px;margin-bottom:52px;">+ <section data-step="${number}" style="display:flex;gap:26px;margin-bottom:52px;"><div style="flex:0 0 76px;font-size:34px;font-weight:700;color:${accent};line-height:.9;">${stepNumber}</div><div style="flex:1;min-width:0;border-top:1px solid #1E1B4B;padding-top:12px;"><p style="margin:0;font-size:17px;font-weight:700;line-height:1.45;color:#1E1B4B;">${escapeHtml(step.description)}${@@ -92,7 +116,7 @@ export async function exportGuideAsHTML(<div style="border-top:2px solid #1E1B4B;padding-top:18px;display:flex;align-items:baseline;"><div style="flex:0 0 190px;"><div style="font-size:11px;font-weight:700;color:#6B7280;letter-spacing:0.06em;">${i18n.t('export.steps').toUpperCase()}</div>- <div style="font-size:38px;font-weight:700;color:${accent};line-height:1;margin-top:2px;">${String(steps.length).padStart(2, '0')}</div>+ <div style="font-size:38px;font-weight:700;color:${accent};line-height:1;margin-top:2px;">${String(actionSteps(steps).length).padStart(2, '0')}</div></div>${metaCell(i18n.t('export.created').toUpperCase(), formatDate(guide.createdAt))}${diff --git a/src/core/export/markdown-export.ts b/src/core/export/markdown-export.tsindex d9fa6c2..302c848 100644--- a/src/core/export/markdown-export.ts+++ b/src/core/export/markdown-export.ts@@ -1,16 +1,25 @@import { i18n } from '#imports';import { blobToBase64, extractDomain, formatDate } from '@/core/export/utils';+import { actionSteps, isBlock, stepNumbers, variantLabel } from '@/core/guides/blocks';import type { Guide, Screenshot, Step } from '@/core/guides/types';import { renderScreenshot } from '@/core/screenshot/render';+function blockLines(step: Step): string[] {+ if (step.blockType === 'heading') return [`## ${step.description}`];+ const label = variantLabel(step.calloutVariant ?? 'info');+ const body = step.description.split('\n').map((line) => (line ? `> ${line}` : '>'));+ return [`> **${label}**`, '>', ...body];+}+export async function exportGuideAsMarkdown(guide: Guide,steps: Step[],screenshots: Map<string, Screenshot>,): Promise<string> {const domain = extractDomain(steps);+ const numbers = stepNumbers(steps);const meta = [- i18n.t('export.stepsCount', [String(steps.length)]),+ i18n.t('export.stepsCount', [String(actionSteps(steps).length)]),i18n.t('export.createdLabel', [formatDate(guide.createdAt)]),...(domain ? [i18n.t('export.sourceLabel', [domain])] : []),].join(' Β· ');@@ -20,7 +29,12 @@ export async function exportGuideAsMarkdown(lines.push(`*${meta}*`, '', '---', '');for (const step of steps) {- const num = String(step.index + 1).padStart(2, '0');+ if (isBlock(step)) {+ lines.push(...blockLines(step), '');+ continue;+ }++ const num = String(numbers.get(step.id) ?? 0).padStart(2, '0');lines.push(`## ${i18n.t('export.stepLabel', [num])}: ${step.description}`, '');const screenshot = screenshots.get(step.id);