Skip to content

feat(content): export the page from the Content Editor as Word, HTML or Markdown - #1348

Merged
gkhngyk merged 22 commits into
ansvisor:mainfrom
cihan-gyk:feature/editor-export
Oct 22, 2026
Merged

gkhngyk merged 22 commits into
ansvisor:mainfrom
cihan-gyk:feature/editor-export

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

Content Editor feedback item 3: there was no Export in the editor. Export now sits beside Copy HTML in the header, with Export Word, Export HTML and Export Markdown. Each downloads the page as written now, from the same HTML Copy HTML gives (publishableHtml, the HTML view included).

Stacked on #1337 (it adds docx, pinned to 9.7.0) and #1347 (the header's new top row). Until they merge, this diff shows theirs too; this PR's own commit is the last one (7aef5446).

  • New lib/content/draft-export.ts:
    • draftBlocks reads the page as blocks: headings, paragraphs, quotes, nested and numbered lists, tables, and links, bold and italic within them. Unsafe link addresses go through safeLinkHref; the text stays.
    • Markdown (draftMarkdown): # headings, **/*, [text](url), - / 1. lists (nested 4 spaces), > quotes and GFM tables (pipes escaped). Text that Markdown would read as its own syntax is escaped. An HTML block stays as HTML.
    • Word (draftDocx, docx loaded on the click as in feat(content): export an opportunity as CSV, Excel or Word #1337): Heading 1–3, runs with hyperlinks, bullets, decimal numbering (each list restarts), indented italic quotes, full-width tables with bold header rows. An HTML block keeps its text.
    • HTML (draftHtmlDocument): the page in a document of its own, with charset and <title>.
    • The schema JSON-LD is markup rather than content, so only the HTML file carries it.
    • A page without an H1 opens with its title.
    • Files are named ansvisor_content_<slug>.docx|html|md.
  • New _export-menu.tsx: the button is labelled from sm up, so it is easy to find. On a phone it is an icon, and the actions' gap is gap-1.5 sm:gap-3, so the header's top row still fits 375px.
  • Library export later: the Library's export (Excel/CSV/Word, list and date range) can reuse draftExportBlob for each draft.

Related issue

Content Editor feedback round (no issue).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. Open a draft in the Content Editor that has headings, a list, a link and a table.
  2. Click Export → Export Word and open the .docx. Check that headings, bold/italic, the link, the bullets and numbering, and the table are there.
  3. Click Export → Export Markdown and Export HTML, and open the files. The HTML file includes the JSON-LD script; the Markdown and Word files don't.
  4. At 1024px the button reads "Export"; at 375px it is an icon and the top row doesn't overflow. Check light and dark.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

Also run: yarn test (2618 tests pass, including draft-export.test.ts and an editor test for the menu) and yarn build.

🤖 Generated with Claude Code

cihan-gyk and others added 21 commits October 21, 2026 21:39
…e in its final layout

- "What AI cites in your topics" drew both shares on one track scaled to
  AI's largest share, so a type the brand leans on more than AI does
  (e.g. 35% · 73%) ran its bar past the track onto the shares column. The
  two shares are now two thin bars on one scale, the larger of the two,
  never past the track.
- The list and the sections above it (AI results, the mix) were read and
  drawn apart, so the list showed mid-screen first and jumped down when
  the sections came in. The page now shows one spinner until both reads
  are in; a list that fails says so at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rlap warning

More of the brand's pages cited for the same prompts is no loss (AI
answers aren't a ranking), so neither Start nor the Plan treats it as a
problem any more:

- Start's "Overlap check" is an "Overview": a plain box listing the
  brand's pages AI already cites for these prompts, with no amber warning,
  no "Safe to create" and no "Recommended". The action the person clicked
  stays chosen (Create stays Create); the choices are the plan's page when
  it named one, a new page, and optimizing the page cited most.
- The Plan drops the Overlaps card, the ⚠ Overlap tag on rows, and the
  rows that were listed only because another page of the brand is cited
  for the same prompts.

content_plan_pages (00220/00221) still returns overlaps; the Plan no
longer reads it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each Priority list row gets a "…" menu:
- Assign to… (every member): a row with a draft assigns its Action
  Center task (sending the draft first when needed); a row without one
  opens Start on Team, which now has an "Assign to" picker. The Who
  column shows the assignee.
- Mark as priority (admins and managers): the row goes to the top with a
  Priority tag; a Priority card counts and filters the marked rows.
- Hide from the plan (admins and managers): the row leaves the list, with
  Undo and "N hidden rows · Show"; an opportunity's row also dismisses the
  opportunity and gets its status back when shown again.

Migration 00229 adds content_plan_marks (members read; admins and
managers write).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…type

Content Opportunities gave every brand the same ten asset types, so a
shop could get a glossary or landing page and a SaaS brand a product or
category page. The generator now reads brands.site_type (or the
editor's guess from Shopping mode and industry), lists that site's page
types with their formats in the prompt, and limits assetType and the
supporting types to them, plus the earned third_party_article and
backlink. No calculation changes.

Older opportunities keep their stored types and are read as the brand's
page types (pillar_guide -> guide / buying_guide, landing_page ->
solution_page / collection_page / destination_page, and so on). The
opportunities list, the drawer, the assets card and Copy All Data name
them with the editor's labels. Start preselects an opportunity's type
for a new page; an existing page goes by its own address or title
first. The Content Plan follows the same rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/src/components/content/new-content-dialog.tsx
#	web/src/lib/actions/content-plan.ts
From the user's spec, PR B of the Content Editor entry points, with the
user's follow-up choices:

- Opportunity panel: three buttons in front, in this order: Send to
  Actions, Generate Brief and Send to Editor. Each turns into its done
  state in place (Open in Actions, Brief Generated, Open draft). The
  rest move into a "..." menu on the right: Send to Plan, Another angle,
  Send to Workflow, Copy All Data, Mark as reviewed, Restore, Dismiss.
- Opportunities list: a row's actions sit in one "..." menu: Send to
  Editor or Open draft, Send to Plan or Open in Plan, Send to Workflow,
  Open in new tab, Dismiss. The Actions column narrows to fit.
- Send to Editor opens New content > Start. A create decision starts a
  new page; any other decision starts on its first target page
  (lib/content/opportunity-start.ts). Owned work still open only.
  getOpportunityDrafts finds the draft already being written.
- Send to Plan marks the opportunity's Plan row as a priority
  (content_plan_marks, ansvisor#1321) for admins and managers;
  getPlanPriorities reads which rows already are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The user asked for an Export button on the opportunity's full page and in
the right-hand panel, listing Export CSV, Export Excel and Export Word one
under the other. It sits on the actions row, left of the "..." menu.

All three formats come from what Copy All Data copies.
opportunityToMarkdown now renders a structured write-up
(opportunityDocument: sections of fields, items, numbered steps and
text), and its Markdown output is unchanged. lib/content/opportunity-export.ts
writes that same write-up as:
- CSV: section, field and value rows, with a byte order mark;
- Excel: one sheet with a bold header (write-excel-file);
- Word: a .docx with the title, section headings, bold field labels
  and lists.

Word uses the docx package, added at the user's OK. It is pinned to 9.9.0,
a release at least two weeks old, and loaded only on the click.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	supabase/schema.sql
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-insights.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.tsx
#	web/src/components/content/new-content-dialog.test.tsx
#	web/src/lib/content/plan.test.ts
#	web/src/lib/content/plan.ts
… only what is still dismissed

hidePlanRow and showPlanRow no longer take an opportunity id from the client:
the server reads it from the row key the mark is written under (a uuid, or
'invalid'). Show again gives an opportunity back its status only while it
is still dismissed; one completed or reopened elsewhere keeps its status and
only the mark goes. Hidden rows read only dismissed opportunities. The
Priority card's dot is in ink, as its outline badge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and tell the list about Send to Plan

- A failed getOpportunityDrafts is no "no draft": the row menu and the
  panel offer "Couldn't check for a draft · Retry" instead of Start, so a
  failed read never starts a second draft for the same opportunity.
- Send to Plan from the panel calls the page's onPrioritized, so the row's
  menu says Open in Plan without a reload.
- Start's page types come from the opportunity's brand, not the active one.
- content.send is gone; content.alternative.hint is Another angle's title.
- Drop the unused contains mock and fix the content prop's doc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ansvisor#1334's retry test lists the panel's front buttons; with this PR's Export
button there is one more.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-export

# Conflicts:
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.tsx
#	web/src/components/content/opportunity-actions.test.tsx
#	web/src/components/content/opportunity-actions.tsx
#	web/src/components/content/opportunity-detail.tsx
#	web/src/lib/actions/content-drafts-start.test.ts
#	web/src/lib/content/drafts.ts
#	web/src/lib/content/opportunity-markdown.ts
#	web/src/lib/content/plan.test.ts
#	web/yarn.lock
[email protected] depends on nanoid@^6, whose engines need Node 22+, so CI's
Node 20 web job (and Vercel's install on Node 20) stopped at yarn install.
9.7.0 is the last release on nanoid@^5 (Node ^18 || >=20) and @types/node
^25, and has every API the export uses. The lockfile drops docx 9.9.0's
nanoid 6, @types/node 26 and undici-types 8.9; @types/node@^25.2.3 joins
the existing 25.7.0 entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r case in the CSV

An outline step's points sit on their own lines in one value; the sheet's
cell now wraps, so Excel shows them. The CSV's header reads Section,Field,Value
like the sheet's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ide panel's tabs in sight, Rules first

The header's top row keeps the title and the page's actions; the page type,
method, status, rules and cited-passages tags move to a line of their own
under the title, all of them at any width and lined up (the status badge sat
lower in its wrapper). While the side panel is closed, its tabs stay down the
editor's right edge and open it on the one picked, so the panel is never out
of sight on a window under 1280px, where it starts closed. Rules is the first
tab and the panel opens on it; Impact reads when first opened.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…or Markdown

Export sits beside Copy HTML in the editor's header and downloads the page as
Copy HTML gives it. HTML is that page as a titled document. Word and Markdown
read it as blocks first (headings, paragraphs, quotes, nested and numbered
lists, tables, links, bold and italic): Markdown keeps an HTML block as HTML,
Word keeps its text. The schema JSON-LD is markup, so only the HTML file
carries it. A page without an H1 opens with its title. On a phone the button
is an icon, so the header's one row still fits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk this is the Content Editor's Export (Word/HTML/Markdown), stacked on #1337 (docx) and #1347 (header). Its own change is the last commit, 7aef544. Once those two merge, I'll merge main in so the diff shows only this PR's files.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I reviewed 7aef5446, this PR's own commit. Two small follow-ups.

  1. web/src/lib/content/draft-export.ts:179: <html lang="en"> is fixed, but the page is written in the brand's language. Drop lang, or pass the brand's language in.
  2. Optional, draft-export.ts:362: the HTML file is a text/html Blob, saved through an object URL in the app's origin. <a download> saves it, so nothing renders in the app. The file does carry the HTML blocks' code unchanged, as Copy HTML does, by design. Typing the Blob application/octet-stream makes sure no browser ever opens it inline in our origin. The file name and its extension stay the same.

Checked, and fine:

  • The HTML file's content. The page's HTML is publishableHtml: DOMPurify's allow-list, links through cleanHref, and JSON-LD written again from its JSON. The <title> is escaped.
  • Links in Word and Markdown. They go through safeLinkHref, and a test covers javascript:. DOMParser runs no scripts and loads no images.
  • The file name. It's slugify output ([a-z0-9-]), capped at 60 characters, with a fixed prefix and extension.
  • Dependencies on Node 20. The only new dependency is [email protected] (engines node >=10). Its new transitive packages are [email protected] (^18 || >=20), [email protected] (>=11), and hash.js, minimalistic-assert, xml and xml-js, which set no engines. @types/node@^25.2.3 and jszip@^3.10.1 resolve to entries already in the lockfile. So yarn install --frozen-lockfile passes on Node 20.

Merge notes

  • It contains #1337 at its current head (baf7e42e) and #1347 at its current head (91959bdc). Re-merging the parents of 33e492b4 gives the same tree, so that merge has no hidden changes.
  • It merges cleanly on main. Merge it after #1337 and #1347, updating from main after each squash. No migration.
  • Through #1347, it conflicts with #1346 in page.test.tsx.
  • No conflicts with #1349, #1350, #1351 or #1353.

Tested on top of main together with #1353, #1347, #1348, #1350 and #1351: web and server tests, tsc, lint and Prettier pass.

@gkhngyk
gkhngyk merged commit 03ff150 into ansvisor:main Oct 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants