# Design: one card layout, for every export Status: **in progress** · Owner: xet7 · Related: [#1173](https://github.com/wekan/wekan/issues/1173) (print a board with params), [#6586](https://github.com/wekan/wekan/issues/6586) (PDF: umlauts, markdown, and what a card export should contain). **The rule this document exists for:** *the same functions, layouts and templates for every PDF and Excel export, so that there is no duplicated code.* ## What an export should be One layout — the one **Export card to Excel** already draws — used by every scope and both formats: | | Excel | PDF | | --- | --- | --- | | Card | the layout | the layout | | List | the layout, per card | the layout, per card | | Swimlane | the layout, per card | the layout, per card | | Board | the layout, per card | the layout, per card | with **images included** and **markdown rendered the way WeKan renders it**. ## Where it already is, and where it is not Two of the four quarters are done, and were done by the same method — one renderer, called by every scope: - **Excel** already draws the card layout at every scope. `ExporterExcelBoard` renders each card through `ExporterExcelCard.renderCardBlock`, so a board, a swimlane and a list are that block repeated. Images are embedded there (`EMBEDDABLE_IMAGE_MIME`, `IMG_WIDTH_PX`, …). - **PDF** already shares its block across scopes: `ExporterBoardPDF` and `ExporterCardPDF` both render through `PDFExporterBase.cardBlockLines`. What is missing is that the PDF's block is **not that layout**. It is a monospaced list of lines — no sections with a filled header, no label/value columns, no boxes, and no images. So the two formats agree about *what* a card export contains and disagree about what it *looks like*. ## The shape of the fix **A card becomes a DOCUMENT, and each format DRAWS one.** Not "make the PDF look like the Excel code": one description of a card's layout, built once, rendered twice. ``` buildCardDocument(card, data, fields) models/lib/cardDocument.js │ ├── renderCardToWorksheet(doc, ws) models/server/ExporterExcelCard.js └── renderCardToPdf(doc, lines) models/server/ExporterCardPDF.js ``` The document is a list of blocks, in the order the Excel layout already puts them: | Block | Carries | Excel draws | PDF draws | | --- | --- | --- | --- | | `section` | a title | merged A–F, grey fill, thick border | filled bar, bold, rule under it | | `meta` | up to three label/value pairs | three label/value column pairs | label/value columns | | `text` | markdown runs (see below) | one merged cell, rich text | wrapped styled lines | | `list` | items, each with runs and a state | one row per item | one line per item | | `images` | attachments that are images | embedded, 4 per row | embedded, 4 per row | | `table` | header + rows | a bordered grid | a bordered grid | Nothing in a block names a colour, a column letter or a font size: those are the renderer's business, and they are what legitimately differ between a spreadsheet and a page. ## Markdown *(done)* [`models/lib/exportMarkdown.js`](../../../../models/lib/exportMarkdown.js) parses a card's text with **the same markdown-it options the reader's renderer uses** — `html`, `linkify`, `typographer`, `breaks` — and returns blocks of styled runs: ```js [{ type: 'heading', level: 2, runs: [{ text: 'Plan', bold: true }] }, { type: 'bullet', level: 0, runs: [{ text: 'first' }] }, { type: 'code', text: 'npm install' }] ``` A run is `{ text, bold, italic, code, strike, link }`. Excel turns runs into an ExcelJS `richText` array; the PDF picks one of the four Courier faces. Neither knows markdown. HTML in a card is kept as **text** — an export is a document, and a card containing `