3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-18 22:25:44 +01:00

Write no style attribute in adfToHtml, and name every spelling of <div>, <span> and <mark> in their refusals

This commit is contained in:
2026-11-15 12:53:59 +01:00
committed by Lillem4n
parent 0d49d9e71f
commit a0f81b12a6
18 changed files with 160 additions and 144 deletions
+7 -2
View File
@@ -7,9 +7,14 @@
`0.3.1` wrote the carry element, and `htmlToAdf` reads them back. A link around the image is the media's link
mark. The carry element `0.3.1` wrote for them still reads.
- `adfToHtml` writes underline as `<u>`, subscript and superscript as `<sub>` and `<sup>`, a text colour as
`<span style="color:…">`, a background colour as `<mark style="background-color:…">` and a paragraph's or
heading's alignment as `style="text-align:…"`, where `0.3.1` wrote the carry element, and `htmlToAdf` reads them
`<span data-text-color="…">`, a background colour as `<mark data-background-color="…">` and a paragraph's or
heading's alignment as `data-align="center"` or `data-align="end"`, where `0.3.1` wrote the carry element, and `htmlToAdf` reads them
back. The carry element `0.3.1` wrote for them still reads.
- `adfToHtml` writes a table cell's background as `data-background-color="…"`, where `0.3.1` wrote
`style="background-color:…"`, so the HTML holds no `style` attribute. `htmlToAdf` still reads the `0.3.1` spelling.
A background that isn't letters and digits after an optional `#` is written too, where it rode the carry element.
- `htmlToAdf` names every spelling of the dialect's `<div>`, `<span>` and `<mark>` in the refusal of one it can't
read.
- `adfToHtml` writes a paragraph's or heading's indentation as `data-indent-level="2"`, where `0.3.1` wrote the carry
element, and `htmlToAdf` reads it back. The carry element `0.3.1` wrote for it still reads.
- `htmlToAdf` reads an expand's `<details class="adf-expand" open="">`, as a browser writes one its user opened, as the same expand.
+5 -6
View File
@@ -556,8 +556,7 @@ saving what this pair read replaces mentions, attachments and macros with text.
## HTML
Serves [Goals](#goals) 1, 6, 7 and 10, which `adfToHtml` does not yet meet: it still writes the `style`
attributes the table lists, and a later release replaces them. It writes the nodes and marks the table lists as their
Serves [Goals](#goals) 1, 6, 7 and 10. It writes the nodes and marks the table lists as their
HTML elements, and keeps every other node whole: an element of class `adf-carry` holds the node's JSON in
`data-adf` and shows the node's content, its links included, so a reader of the page loses no
content. No stylesheet ships. The complete dialect:
@@ -572,19 +571,19 @@ content. No stylesheet ships. The complete dialect:
| `decisionList`, `decisionItem` | `<ul class="adf-decision-list">`, `<li class="adf-decision" data-state="DECIDED">` |
| `expand`, `nestedExpand` | `<details class="adf-expand">`, `<details class="adf-nested-expand">`, a `<summary>` holding the `title` |
| `hardBreak` | `<br>` |
| `heading` | `<h1>` to `<h6>`; `style="text-align:center"` for a centered one, `text-align:right` for one aligned to the end, `data-indent-level="2"` for an indented one |
| `heading` | `<h1>` to `<h6>`; `data-align="center"` for a centered one, `data-align="end"` for one aligned to the end, `data-indent-level="2"` for an indented one |
| `inlineCard` holding a `url`, or `data` and no `url` | `<a class="adf-inline-card" href="…">…</a>`; for `data`, `href` is the URL `data` holds, the text its name, else that URL, and `data-data` the whole `data` as JSON |
| `link` | `<a href="…" title="…">` |
| `mediaGroup` | `<div class="adf-media-group">` holding a `<span class="adf-file" data-id="…" data-type="file"></span>` for each `media` |
| `mediaSingle` holding an external `media`, centered, uncaptioned, holding no other attribute such as `width` or `localId` | `<p><img src="…" alt="…"></p>`, the image inside `<a>` where a link marks it |
| any other `mediaSingle` | `<figure class="adf-media-single" data-layout="wide">` holding the `<img>`, then the caption as `<figcaption>` |
| `panel` | `<div class="adf-panel" data-panel-type="info">` |
| `paragraph` | `<p>`; `style="text-align:center"`, `text-align:right` or `data-indent-level="2"`, as on a heading |
| `paragraph` | `<p>`; `data-align="center"`, `data-align="end"` or `data-indent-level="2"`, as on a heading |
| `rule` | `<hr>` |
| `table`, `tableRow`, `tableCell`, `tableHeader` | `<table>`, `<thead>` for a first row of `tableHeader` cells alone, `<tbody>`, `<tr>`, `<td>` and `<th>`; a cell's first paragraph stands as an item's does, and `<td colspan="2" rowspan="2" style="background-color:#fffae6" data-colwidth="120,80">` writes its attributes |
| `table`, `tableRow`, `tableCell`, `tableHeader` | `<table>`, `<thead>` for a first row of `tableHeader` cells alone, `<tbody>`, `<tr>`, `<td>` and `<th>`; a cell's first paragraph stands as an item's does, and `<td colspan="2" rowspan="2" data-background-color="#fffae6" data-colwidth="120,80">` writes its attributes |
| `taskList`, `taskItem` | `<ul class="adf-task-list">`, `<li class="adf-task" data-state="DONE"><input type="checkbox" checked="" disabled=""> text</li>` |
| `text` marked `code`, `em`, `strike`, `strong`, `subsup`, `underline` | `<code>`, `<em>`, `<del>`, `<strong>`, `<sub>` or `<sup>`, `<u>`, the first mark outermost |
| `text` marked `backgroundColor`, `textColor` | `<mark style="background-color:#fffae6">`, `<span style="color:#ae2e24">` |
| `text` marked `backgroundColor`, `textColor` | `<mark data-background-color="#fffae6">`, `<span data-text-color="#ae2e24">` |
| an attribute its type holds that its element does not write, such as `localId`, on a paragraph, heading, quote, list, list item, table, row, cell, code block, rule, panel, expand, task or decision list or item, media, media single, caption, emoji, mention, status, date or card | `data-*` named as HTML's `dataset` names it: `<p data-local-id="a1f3">` |
| any other node, or a node holding what its element cannot, except a shape Atlassian's schema forbids, which is refused ([The errors](#the-errors)) | `<div class="adf-carry" data-adf="{…}"><p>its content</p></div>`, a `<span>` inline |
+17 -8
View File
@@ -420,7 +420,7 @@ for HTML+, its Rovo MCP server's HTML for agents; a published spec reopens the g
The HTML dialect mirrors the markdown flavour: semantic elements, stable `adf-*` classes, `data-*`
for what HTML cannot express, text always escaped. No stylesheet ships.
The spellings, `spec/html.md`, are eight writer panels' (2026-10-23, -24, 2026-11-04, -05 and -14), each of a
The spellings, `spec/html.md`, are nine writer panels' (2026-10-23, -24, 2026-11-04, -05, -14 and -15), each of a
product manager, an engineer and a support agent. The first picked each of these 3 of 3:
- an image standing alone as `<p><img …></p>`, over `<figure>` and a bare `<img>`;
@@ -486,8 +486,9 @@ A sixth panel (2026-11-05, three readers in the same roles) picked each of these
- a first row of header cells alone in `<thead>` and the rest in `<tbody>`, a row to a line, over a
bare `<table>` of `<tr>` rows and over a line per cell;
- a cell's first paragraph bare, `<td>Bolt M8</td>`, as a list item's;
- a cell's attributes as `<td colspan="2" rowspan="2" style="background-color:#fffae6" data-colwidth="120,80">`,
over `data-*` for all four.
- a cell's attributes as `<td colspan="2" rowspan="2">` and `data-*` attributes, over `data-*` for all four; its
`style="background-color:…"` gave way to the ninth panel's spelling, and `htmlToAdf` still reads it, since
`0.3.1` wrote it and every other spelling `0.3.1` wrote still reads.
A seventh panel (2026-11-14, three readers in the same roles, after the reader panel of §The feature
table is a section per corpus example, led by a summary table expected `<s>` or `<del>`) picked
@@ -500,8 +501,7 @@ An eighth panel (2026-11-14, three readers in the same roles; seven for indentat
- a `mediaSingle` as `<figure class="adf-media-single" data-*>` holding an `<img>`, inside `<a>` where
a link marks it, and a `<figcaption>`; a `mediaGroup` as `<div class="adf-media-group">` holding a
`<span class="adf-file" data-*>` for each file;
- `<u>`, `<sub>` and `<sup>`, `<span style="color:…">` and `<mark style="background-color:…">`;
- `style="text-align:center"` and `text-align:right` for an `alignment` of `center` and `end`;
- `<u>`, `<sub>` and `<sup>`, a `<span>` for a text colour and a `<mark>` for a background colour;
- `<details class="adf-expand">` and `<details class="adf-nested-expand">` with the `title` as the
`<summary>` and `<div class="adf-panel" data-panel-type="…">`;
- a task list as `<ul class="adf-task-list">` of `<li class="adf-task" data-state="DONE">` holding
@@ -512,9 +512,18 @@ An eighth panel (2026-11-14, three readers in the same roles; seven for indentat
For an `indentation` mark, five of seven picked `data-indent-level`; whether a `margin-left` style
goes with it split 4 to 3. The maintainer answered on 2026-11-15 that the dialect holds no style at
all (README goal 10), so an indentation is `data-indent-level="2"` alone, on a paragraph or heading
holding no other mark. The `style` attributes above work against that goal: a text colour, a
background colour, an alignment and a cell's `background`. They stand until `todo.md` item 188 spells
each without one.
holding no other mark.
A ninth panel (2026-11-15, three readers in the same roles) picked, 3 of 3, a plain `data-*` attribute
naming what it holds, over a class beside it and over a class per value:
- `data-align="center"` and `data-align="end"` for an `alignment`, ADF's own values;
- `<span data-text-color="#bf2600">` and `<mark data-background-color="#fffae6">`, over a bare
`data-color` that could name either;
- `<td data-background-color="#fffae6">` for a cell's `background`, the highlight's name over ADF's.
Out of `style`, a colour needs no restriction to stay in its attribute, so any string HTML can hold
is one.
## `htmlToAdf` also reads the dialect as a browser serializes it
+17
View File
@@ -1127,3 +1127,20 @@ Read most (opens and searches):
- `src/html/parse/html-to-adf.test.ts` 2
- `.gitignore` 1
- `AGENTS.md` 1
## Reading cost, chunk d23ee0f1e8e2, finished 2026-11-15T11:45:38Z
714516 new input tokens before the first commit.
Read most (opens and searches):
- `src/html/emit/adf-to-html.test.ts` 18
- `spec/html.md` 16
- `src/html/parse/html-to-adf.test.ts` 16
- `docs/decisions.md` 15
- `src/html/parse/html-to-adf.ts` 14
- `src/adf/block-nodes.ts` 11
- `src/adf/document.ts` 9
- `README.md` 8
- `docs/feature-table.md` 8
- `src/html/emit/adf-to-html.ts` 7
+9 -7
View File
@@ -23,10 +23,10 @@ Blocks are separated by a line feed, and a document holding any ends with one. A
| `mediaSingle`, any other | `<figure class="adf-media-single" data-layout="wide">`, its `media` as the `<img>` below, then its caption as `<figcaption>…</figcaption>`, on one line, `</figure>`; the `<img>` inside `<a href="…">` where a link marks the media |
| `orderedList` | as `bulletList` with `<ol>`; `<ol start="3">` for an `order` of 3, a safe integer other than `-0`; no `start` where the list holds no `order` |
| `panel` | `<div class="adf-panel" data-panel-type="info">`, a line feed, its blocks a line each, a line feed, `</div>` |
| `paragraph` | `<p>…</p>`; `<p style="text-align:center">` for an `alignment` mark of `center` and `text-align:right` for `end`, `<p data-indent-level="2">` for an `indentation` mark of `level` 2 |
| `paragraph` | `<p>…</p>`; `<p data-align="center">` for an `alignment` mark of `center` and `data-align="end"` for `end`, `<p data-indent-level="2">` for an `indentation` mark of `level` 2 |
| `rule` | `<hr>` |
| `table` | `<table>`, a line feed, its sections parted by a line feed, a line feed, `</table>`: a `<thead>` where its first row holds cells that are all `tableHeader`, and a `<tbody>` for the other rows where there are any. Each section is its tag, a line feed, its rows a line each, a line feed, its closing tag |
| `tableCell`, `tableHeader` | `<td>`, `<th>`, each holding its blocks as a `listItem` does: `<td>Bolt M8</td>`; attributes `colspan`, `rowspan`, `style="background-color:#fffae6"` for `background`, and `data-colwidth="120,80"` for `colwidth`, first and in that order |
| `tableCell`, `tableHeader` | `<td>`, `<th>`, each holding its blocks as a `listItem` does: `<td>Bolt M8</td>`; attributes `colspan`, `rowspan`, `data-background-color="#fffae6"` for `background`, and `data-colwidth="120,80"` for `colwidth`, first and in that order |
| `tableRow` | `<tr>`, its cells with no line feed between them, `</tr>` |
| `taskList` | `<ul class="adf-task-list">`, a line feed, its items a line each, a line feed, `</ul>`; each `taskItem` is `<li class="adf-task" data-state="TODO"><input type="checkbox" disabled="">`, a space, then its inline content, the checkbox `checked=""` as well where `state` is `DONE`, and the space left out where it holds none |
@@ -49,7 +49,7 @@ is `data-state`, among the other attributes below.
<tr><th>Part</th><th>Stock</th><th>Bin</th></tr>
</thead>
<tbody>
<tr><td rowspan="2">Bolt M8</td><td colspan="2" style="background-color:#fffae6" data-colwidth="120,80">Low</td></tr>
<tr><td rowspan="2">Bolt M8</td><td colspan="2" data-background-color="#fffae6" data-colwidth="120,80">Low</td></tr>
<tr><td>12</td><td>A4</td></tr>
</tbody>
</table>
@@ -68,7 +68,7 @@ block's `data-*` attributes stand on its `<pre>`.
| ADF | HTML |
| --- | --- |
| `backgroundColor`, `textColor` | `<mark style="background-color:#fffae6">`, `<span style="color:#bf2600">` around the text; the colour a `#` and letters and digits, or letters and digits alone |
| `backgroundColor`, `textColor` | `<mark data-background-color="#fffae6">`, `<span data-text-color="#bf2600">` around the text |
| `code`, `em`, `strike`, `strong`, `underline` | `<code>`, `<em>`, `<del>`, `<strong>`, `<u>` around the text |
| `date` | `<time class="adf-date" datetime="2025-08-25" data-timestamp="1756080000000">2025-08-25</time>`, the day in UTC |
| `emoji` | `<span class="adf-emoji" data-id="1f389" data-short-name=":tada:">🎉</span>`, its `text` the content |
@@ -162,7 +162,7 @@ later release writes it as its own element.
holding anything but `media`; a `media` holding more than one mark, a mark that is no link, or a
`height` or `width` that is not a positive safe integer;
- a paragraph or heading holding two marks, or a mark besides a `center` or `end` alignment and an indentation of `level` 1 to 6;
- a `textColor` or `backgroundColor` whose `color` is not letters and digits after an optional `#`;
- a `textColor` or `backgroundColor` whose `color` is no string, or holds a character HTML cannot hold;
- a `panel` or `expand` holding an attribute its type does not hold as that kind; a `taskItem`
whose `state` is not `DONE` or `TODO`, or a task or decision list holding a node that is no
item of its own kind, `blockTaskItem` included: the whole list rides the carry;
@@ -171,8 +171,7 @@ later release writes it as its own element.
- a table holding a node that is no `tableRow`, a row holding a node that is no cell, or a table,
row or cell holding a mark, an empty key or an attribute its type does not hold: the whole table
rides the carry. So does a cell whose `colspan` or `rowspan` isn't a positive safe integer, whose
`colwidth` isn't a list of numbers, or whose `background` isn't a string of one or more letters
and digits, after an optional `#`;
`colwidth` isn't a list of numbers, or whose `background` isn't a string HTML can hold;
- a `listItem`, `tableRow` or cell outside its parent, an inline node in block position and a block
node inline.
- An inline card a link marks, a known block holding `text`, a known non-text inline node holding
@@ -197,6 +196,9 @@ what it shows too:
| a line feed | `\r\n` |
| an expand's or nested expand's `<details>` | the same with `open=""` after its other attributes, which a browser writes for one its user opened; it reads as the same expand, the open state dropped |
`htmlToAdf` also reads a cell's `background` as `0.3.1` wrote it, `style="background-color:#fffae6"` in
the place of `data-background-color`, the colour a `#` and letters and digits, or letters and digits alone.
A refusal's position counts the HTML as handed in. `htmlToAdf` reads a carry element's node from its
`data-adf`, and what the element shows, through its closing tag, must be what `adfToHtml` shows for
that node in either spelling: an edit there would be lost, so it is `unmappable-html`.
+1
View File
@@ -9,6 +9,7 @@ const expandTypes: readonly ExpandType[] = ['expand', 'nestedExpand']
const listTypes: readonly TaskListType[] = ['decisionList', 'taskList']
export const expandClasses: Readonly<Record<ExpandType, string>> = { expand: 'adf-expand', nestedExpand: 'adf-nested-expand' }
export const mediaGroupClass = 'adf-media-group'
export const panelClass = 'adf-panel'
// A panel's type is no attribute of the vocabularies, since a directive spells it as its argument; here it is a data-* attribute like the rest.
export const panelAttributes: AttributeVocabulary = { ...blockNodes.panel.attributes, panelType: 'string' }
+17 -15
View File
@@ -2,14 +2,16 @@ import type { AdfAttributes, AdfNode } from '../adf/document.ts'
import type { JsonValue } from '../json-value.ts'
import type { Read } from '../result.ts'
import { blockNodes } from '../adf/block-nodes.ts'
import { colourDeclaration, readColour } from './colour-style.ts'
import { dataAttributes, dataValue, readDataAttributes } from './data-attributes.ts'
import { isNumberList } from '../adf/attribute-vocabulary.ts'
import { nodeAttrs } from '../adf/document.ts'
import { optionalAttribute } from './escaping.ts'
import { serializeCanonicalJson } from '../canonical-json.ts'
const elementWritten = ['background', 'colspan', 'colwidth', 'rowspan']
const leading = ['colspan', 'rowspan', 'style', 'data-colwidth']
const leading = ['colspan', 'rowspan', 'data-background-color', 'data-colwidth']
// `0.3.1` wrote a cell's background as this `style` in `data-background-color`'s place, and stored HTML still reads.
const releasedBackground = /^background-color:(#?[0-9a-zA-Z]+)$/
const span = /^[1-9][0-9]*$/
export function isHeaderRow(row: { content?: AdfNode[] }): boolean {
@@ -20,7 +22,7 @@ export function isHeaderRow(row: { content?: AdfNode[] }): boolean {
// A cell's attributes in the order `readCellAttributes` takes them; `undefined` where a value has no spelling on the element, so the whole table rides the carry.
export function cellAttributes(cell: AdfNode): string | undefined {
const { background, colspan, colwidth, rowspan } = nodeAttrs(cell)
const own = [spanAttribute('colspan', colspan), spanAttribute('rowspan', rowspan), styleAttribute(background), widthsAttribute(colwidth), dataAttributes(cell, blockNodes.tableCell.attributes, elementWritten)]
const own = [spanAttribute('colspan', colspan), spanAttribute('rowspan', rowspan), backgroundAttribute(background), widthsAttribute(colwidth), dataAttributes(cell, blockNodes.tableCell.attributes, elementWritten)]
return own.every((attribute) => attribute !== undefined) ? own.join('') : undefined
}
@@ -29,41 +31,41 @@ export function readCellAttributes(pairs: readonly (readonly [string, string])[]
let rest = pairs
for (const name of leading) {
const [first] = rest
if (first?.[0] !== name) continue
const value = ownValue(name, first[1])
if (value === undefined) return { fault: { code: name === 'data-colwidth' ? 'unsupported-node-shape' : 'unmappable-html', message: `${name} on <${element}> spells no value adfToHtml writes there` } }
const released = name === 'data-background-color' && first?.[0] === 'style'
if (first?.[0] !== name && !released) continue
const value = released ? releasedBackground.exec(first[1])?.[1] : ownValue(name, first[1])
if (value === undefined) return { fault: { code: name === 'data-colwidth' ? 'unsupported-node-shape' : 'unmappable-html', message: `${first[0]} on <${element}> spells no value adfToHtml writes there` } }
attrs[ownKey(name)] = value
rest = rest.slice(1)
}
const misplaced = rest.find(([name]) => leading.includes(name))
if (misplaced !== undefined) return { fault: { code: 'unmappable-html', message: `<${element}> takes colspan, rowspan, style and data-colwidth first, each once and in that order: found ${misplaced[0]} out of place` } }
if (misplaced !== undefined) return { fault: { code: 'unmappable-html', message: `<${element}> takes colspan, rowspan, data-background-color and data-colwidth first, each once and in that order: found ${misplaced[0]} out of place` } }
const data = readDataAttributes(rest, element, blockNodes.tableCell.attributes, elementWritten)
return data.fault === undefined ? { value: { ...attrs, ...data.value } } : data
}
function backgroundAttribute(background: JsonValue | undefined): string | undefined {
if (background === undefined) return ''
return typeof background === 'string' ? optionalAttribute('data-background-color', background) : undefined
}
function spanAttribute(name: string, value: JsonValue | undefined): string | undefined {
if (value === undefined) return ''
return typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? ` ${name}="${value}"` : undefined
}
function styleAttribute(background: JsonValue | undefined): string | undefined {
if (background === undefined) return ''
const declaration = colourDeclaration('background-color', background)
return declaration === undefined ? undefined : ` style="${declaration}"`
}
function widthsAttribute(colwidth: JsonValue | undefined): string | undefined {
if (colwidth === undefined) return ''
return isNumberList(colwidth) ? ` data-colwidth="${serializeCanonicalJson(colwidth, 'compact').slice(1, -1)}"` : undefined
}
function ownKey(name: string): string {
if (name === 'style') return 'background'
if (name === 'data-background-color') return 'background'
return name === 'data-colwidth' ? 'colwidth' : name
}
function ownValue(name: string, spelled: string): JsonValue | undefined {
if (name === 'style') return readColour('background-color', spelled)
if (name === 'data-background-color') return spelled
if (name === 'data-colwidth') return dataValue(`[${spelled}]`, 'numbers')
const value = Number(spelled)
return span.test(spelled) && Number.isSafeInteger(value) ? value : undefined
-16
View File
@@ -1,16 +0,0 @@
import type { JsonValue } from '../json-value.ts'
// Letters and digits alone, after an optional `#`, so no value can end the declaration or call `url()`.
const colour = /^#?[0-9a-zA-Z]+$/
// `property:colour`, `undefined` where the value is no colour the declaration can hold.
export function colourDeclaration(property: string, value: JsonValue | undefined): string | undefined {
return typeof value === 'string' && colour.test(value) ? `${property}:${value}` : undefined
}
// The colour a `property:colour` declaration holds, `undefined` where it holds another property or no such colour.
export function readColour(property: string, declaration: string): string | undefined {
const prefix = `${property}:`
const value = declaration.slice(prefix.length)
return declaration.startsWith(prefix) && colour.test(value) ? value : undefined
}
+16 -18
View File
@@ -191,17 +191,18 @@ test('carries a media node HTML cannot spell: a width that is no whole number, a
assert.equal(carriedBlock({ content: [{ content: [text('a')], type: 'paragraph' }], type: 'mediaGroup' }), true)
})
test('writes underline, subscript, superscript and the two colours as elements, a colour in a style attribute', () => {
test('writes underline, subscript, superscript and the two colours as elements, a colour in a data-* attribute', () => {
const marked = (...marks: AdfMark[]): string => html(adfToHtml(document(paragraph(text('x', ...marks)))))
assert.equal(marked({ type: 'underline' }), '<p><u>x</u></p>\n')
assert.equal(marked({ attrs: { type: 'sub' }, type: 'subsup' }), '<p><sub>x</sub></p>\n')
assert.equal(marked({ attrs: { type: 'sup' }, type: 'subsup' }), '<p><sup>x</sup></p>\n')
assert.equal(marked({ attrs: { color: '#ff5630' }, type: 'textColor' }), '<p><span style="color:#ff5630">x</span></p>\n')
assert.equal(marked({ attrs: { color: '#fffae6' }, type: 'backgroundColor' }), '<p><mark style="background-color:#fffae6">x</mark></p>\n')
assert.equal(marked({ type: 'strong' }, { type: 'underline' }, { attrs: { color: 'red' }, type: 'textColor' }), '<p><strong><u><span style="color:red">x</span></u></strong></p>\n')
assert.equal(marked({ attrs: { color: '#ff5630' }, type: 'textColor' }), '<p><span data-text-color="#ff5630">x</span></p>\n')
assert.equal(marked({ attrs: { color: '#fffae6' }, type: 'backgroundColor' }), '<p><mark data-background-color="#fffae6">x</mark></p>\n')
assert.equal(marked({ type: 'strong' }, { type: 'underline' }, { attrs: { color: 'red' }, type: 'textColor' }), '<p><strong><u><span data-text-color="red">x</span></u></strong></p>\n')
assert.equal(marked({ attrs: { color: 'rgb(1, 2, 3) "x"' }, type: 'backgroundColor' }), '<p><mark data-background-color="rgb(1, 2, 3) &quot;x&quot;">x</mark></p>\n')
})
test('carries text holding a mark HTML cannot spell: attributes besides those the element takes, a colour that is no plain value, or a type that is neither sub nor sup', () => {
test('carries text holding a mark HTML cannot spell: attributes besides those the element takes, a colour that is no string, or a type that is neither sub nor sup', () => {
const carriedText = (mark: AdfMark): boolean => html(adfToHtml(document(paragraph(text('x', mark))))).includes('adf-carry')
for (const mark of [
{ attrs: {}, type: 'underline' },
@@ -212,21 +213,17 @@ test('carries text holding a mark HTML cannot spell: attributes besides those th
{ type: 'textColor' },
{ attrs: { color: 'red', x: 1 }, type: 'textColor' },
{ attrs: { color: 7 }, type: 'textColor' },
{ attrs: { color: '' }, type: 'textColor' },
{ attrs: { color: 'red;x:y' }, type: 'textColor' },
{ attrs: { color: 'rgb(1,2,3)' }, type: 'backgroundColor' },
{ attrs: { color: '#fff\n' }, type: 'backgroundColor' },
{ type: 'backgroundColor' },
]) assert.equal(carriedText(mark), true, JSON.stringify(mark))
})
test('writes a paragraph or heading marked with center or end alignment as a style attribute, end as right', () => {
test('writes a paragraph or heading marked with center or end alignment as a data-align attribute', () => {
const aligned = (align: string, node: AdfNode = paragraph(text('x'))): string => html(adfToHtml(document({ ...node, marks: [{ attrs: { align }, type: 'alignment' }] })))
assert.equal(aligned('center'), '<p style="text-align:center">x</p>\n')
assert.equal(aligned('end'), '<p style="text-align:right">x</p>\n')
assert.equal(aligned('center', { attrs: { level: 2 }, content: [text('x')], type: 'heading' }), '<h2 style="text-align:center">x</h2>\n')
assert.equal(aligned('end', { attrs: { localId: ids.paragraph }, type: 'paragraph' }), `<p style="text-align:right" data-local-id="${ids.paragraph}"></p>\n`)
assert.equal(html(adfToHtml(document({ content: [item({ content: [text('x')], marks: [{ attrs: { align: 'center' }, type: 'alignment' }], type: 'paragraph' })], type: 'bulletList' }))), '<ul>\n<li><p style="text-align:center">x</p></li>\n</ul>\n')
assert.equal(aligned('center'), '<p data-align="center">x</p>\n')
assert.equal(aligned('end'), '<p data-align="end">x</p>\n')
assert.equal(aligned('center', { attrs: { level: 2 }, content: [text('x')], type: 'heading' }), '<h2 data-align="center">x</h2>\n')
assert.equal(aligned('end', { attrs: { localId: ids.paragraph }, type: 'paragraph' }), `<p data-align="end" data-local-id="${ids.paragraph}"></p>\n`)
assert.equal(html(adfToHtml(document({ content: [item({ content: [text('x')], marks: [{ attrs: { align: 'center' }, type: 'alignment' }], type: 'paragraph' })], type: 'bulletList' }))), '<ul>\n<li><p data-align="center">x</p></li>\n</ul>\n')
})
test('carries a paragraph or heading holding an alignment HTML cannot spell, or a mark besides it', () => {
@@ -445,12 +442,13 @@ test('writes a table\'s attributes as the writer panel picked them', () => {
const table: AdfNode = { attrs: { isNumberColumnEnabled: true, layout: 'wide', width: 760 }, content: [{ attrs: { localId: 'r1' }, content: [{ attrs, content: [paragraph(text('Sold as a pair'))], type: 'tableCell' }], type: 'tableRow' }], type: 'table' }
assert.equal(
html(adfToHtml(document(table))),
'<table data-is-number-column-enabled="true" data-layout="wide" data-width="760">\n<tbody>\n<tr data-local-id="r1"><td colspan="2" rowspan="3" style="background-color:#fffae6" data-colwidth="120,80" data-local-id="c1" data-valign="top">Sold as a pair</td></tr>\n</tbody>\n</table>\n',
'<table data-is-number-column-enabled="true" data-layout="wide" data-width="760">\n<tbody>\n<tr data-local-id="r1"><td colspan="2" rowspan="3" data-background-color="#fffae6" data-colwidth="120,80" data-local-id="c1" data-valign="top">Sold as a pair</td></tr>\n</tbody>\n</table>\n',
)
assert.equal(html(adfToHtml(document({ content: [{ content: [{ attrs: { background: 'red', colwidth: [0.5] }, type: 'tableHeader' }], type: 'tableRow' }], type: 'table' }))), '<table>\n<thead>\n<tr><th style="background-color:red" data-colwidth="0.5"></th></tr>\n</thead>\n</table>\n')
assert.equal(html(adfToHtml(document({ content: [{ content: [{ attrs: { background: 'red', colwidth: [0.5] }, type: 'tableHeader' }], type: 'tableRow' }], type: 'table' }))), '<table>\n<thead>\n<tr><th data-background-color="red" data-colwidth="0.5"></th></tr>\n</thead>\n</table>\n')
assert.equal(html(adfToHtml(document({ content: [{ content: [{ attrs: { background: 'url("x")' }, type: 'tableCell' }], type: 'tableRow' }], type: 'table' }))), '<table>\n<tbody>\n<tr><td data-background-color="url(&quot;x&quot;)"></td></tr>\n</tbody>\n</table>\n')
})
const carriedCellAttrs: readonly AdfAttributes[] = [{ background: 'url(x)' }, { background: 'red;color:blue' }, { background: '' }, { background: 7 }, { colspan: 0 }, { colspan: 1.5 }, { colspan: '2' }, { rowspan: -1 }, { colwidth: [] }, { colwidth: ['1'] }, { colwidth: 120 }, { valign: 7 }, { size: 'big' }]
const carriedCellAttrs: readonly AdfAttributes[] = [{ background: 7 }, { colspan: 0 }, { colspan: 1.5 }, { colspan: '2' }, { rowspan: -1 }, { colwidth: [] }, { colwidth: ['1'] }, { colwidth: 120 }, { valign: 7 }, { size: 'big' }]
for (const attrs of carriedCellAttrs) {
test(`carries the whole table where a cell holds ${JSON.stringify(attrs)}`, () => {
+2 -2
View File
@@ -6,7 +6,7 @@ import { carryContent } from '../carry-content.ts'
import { cellAttributes, isHeaderRow } from '../cell-element.ts'
import { containerElements, headingElement, listStart } from '../block-elements.ts'
import { dataAttributes } from '../data-attributes.ts'
import { expandClasses, panelAttributes, panelClass, taskLists } from '../block-classes.ts'
import { expandClasses, mediaGroupClass, panelAttributes, panelClass, taskLists } from '../block-classes.ts'
import { failure, success, type ConvertErrorPath, type Result } from '../../result.ts'
import { firstParagraphForm } from '../first-paragraph.ts'
import { imageElement } from '../image-element.ts'
@@ -250,7 +250,7 @@ function tryMediaGroup(node: AdfNode): string | undefined {
if (attributes === undefined) return undefined
files += `<span class="adf-file"${attributes}></span>`
}
return `<div class="adf-media-group">${files}</div>`
return `<div class="${mediaGroupClass}">${files}</div>`
}
// `undefined` where `attributes` is undefined, so the node rides the carry.
+16 -14
View File
@@ -1,7 +1,7 @@
import type { AdfMark } from '../adf/document.ts'
import type { JsonValue } from '../json-value.ts'
import { colourDeclaration, readColour } from './colour-style.ts'
import { nodeAttrs } from '../adf/document.ts'
import { optionalAttribute } from './escaping.ts'
type MarkTag = { closer: string; opener: string }
@@ -13,10 +13,10 @@ const markElements: ReadonlyMap<string, string> = new Map([
['strong', 'strong'],
['underline', 'u'],
])
// The element and CSS property each colour mark writes around text, its colour in a `style` attribute.
const colourElements: ReadonlyMap<string, { element: string; property: string }> = new Map([
['backgroundColor', { element: 'mark', property: 'background-color' }],
['textColor', { element: 'span', property: 'color' }],
// The element each colour mark writes around text, its colour in the attribute `colourAttributeOn` names.
const colourElements: ReadonlyMap<string, 'mark' | 'span'> = new Map<string, 'mark' | 'span'>([
['backgroundColor', 'mark'],
['textColor', 'span'],
])
const scripts: ReadonlyMap<JsonValue | undefined, 'sub' | 'sup'> = new Map<JsonValue | undefined, 'sub' | 'sup'>([
['sub', 'sub'],
@@ -34,22 +34,24 @@ export function markTag(mark: AdfMark): MarkTag | undefined {
}
const colour = colourElements.get(mark.type)
if (colour === undefined) return undefined
const declaration = Object.keys(attrs).length === 1 ? colourDeclaration(colour.property, attrs['color']) : undefined
return declaration === undefined ? undefined : tagOf(colour.element, ` style="${declaration}"`)
const { color } = attrs
const attribute = Object.keys(attrs).length === 1 && typeof color === 'string' ? optionalAttribute(colourAttributeOn(colour), color) : undefined
return attribute === undefined ? undefined : tagOf(colour, attribute)
}
// The mark a start tag but an `<a>` opens, as `markTag` writes it; `undefined` where it opens none.
export function markOfTag(name: string, attributes: readonly (readonly [string, string])[]): AdfMark | undefined {
const [style, ...others] = attributes
if (style === undefined) return markOfElement(name)
if (style[0] !== 'style' || others.length > 0) return undefined
for (const [type, { element, property }] of colourElements) {
const color = element === name ? readColour(property, style[1]) : undefined
if (color !== undefined) return { attrs: { color }, type }
}
const [colour, ...others] = attributes
if (colour === undefined) return markOfElement(name)
if (others.length > 0) return undefined
for (const [type, element] of colourElements) if (element === name && colourAttributeOn(element) === colour[0]) return { attrs: { color: colour[1] }, type }
return undefined
}
export function colourAttributeOn(element: 'mark' | 'span'): string {
return element === 'mark' ? 'data-background-color' : 'data-text-color'
}
function markOfElement(name: string): AdfMark | undefined {
for (const [type, element] of markElements) if (element === name) return { type }
return scripts.has(name) ? { attrs: { type: name }, type: 'subsup' } : undefined
+13 -4
View File
@@ -4,8 +4,10 @@ import { carriedNesting, carriedNode, carriedValue } from '../../adf/carried-jso
import { carryContent } from '../carry-content.ts'
import { carryJsonOffset, readCarryAttributes } from '../carry-attributes.ts'
import { classesOfElement } from '../node-element.ts'
import { colourAttributeOn } from '../mark-elements.ts'
import { foundAt, refused, type Place, type ReadNode, type StartTag } from './source.ts'
import { holdableJson, readsAsShown } from '../escaping.ts'
import { mediaGroupClass, panelClass } from '../block-classes.ts'
import { spellsCanonicalJson } from '../../canonical-json.ts'
import { success } from '../../result.ts'
@@ -15,10 +17,7 @@ const holder = "a carry element's data-adf"
export function readCarry(html: string, tag: StartTag, element: 'div' | 'span', levels: number, place: Place): ReadNode {
const json = readCarryAttributes(tag.attributes)
if (json === undefined) {
const others = classesOfElement(tag.name).map((name) => `"${name}"`)
const last = others.pop()
const alternative = last === undefined ? '' : `, or opens with class=${others.length === 0 ? last : `${others.join(', ')} or ${last}`}`
return refused('unmappable-html', `a <${tag.name}> of the dialect is a carry element, holding class="adf-carry" and then data-adf alone${alternative}: ${foundAt(html, tag.start)}`, html, tag.start, place)
return refused('unmappable-html', `a <${element}> of the dialect ${spellings(element)}: ${foundAt(html, tag.start)}`, html, tag.start, place)
}
const jsonAt = tag.start + carryJsonOffset(tag.name)
const node = heldNode(json, levels, html, jsonAt)
@@ -29,6 +28,16 @@ export function readCarry(html: string, tag: StartTag, element: 'div' | 'span',
return refused('unmappable-html', `a carry element shows what adfToHtml writes for its node, as it or a browser spells it, then </${element}>; to change the node, edit its ADF and write the HTML again: ${foundAt(html, read.at)}`, html, read.at, place)
}
// Every way the dialect spells the element, so a refusal names the one meant.
function spellings(element: 'div' | 'span'): string {
const classes = [...classesOfElement(element), ...(element === 'div' ? [mediaGroupClass, panelClass] : [])].sort().map((name) => `"${name}"`)
const last = classes.pop()
const opens = last === undefined ? [] : [`opens with class=${classes.length === 0 ? last : `${classes.join(', ')} or ${last}`}`]
const others = [...opens, ...(element === 'span' ? [`holds ${colourAttributeOn(element)} alone`] : [])]
const final = others.pop()
return `is a carry element, holding class="adf-carry" and then data-adf alone${others.map((other) => `, ${other}`).join('')}${final === undefined ? '' : `, or ${final}`}`
}
function heldNode(json: string, levels: number, html: string, jsonAt: number): Read<AdfNode> {
const held = carriedValue(json, holder, { code: 'unmappable-html', message: `${holder} holds invalid JSON` })
if (held.fault !== undefined) return held
+28 -21
View File
@@ -241,14 +241,14 @@ test('reads underline, subscript, superscript and the two colours from their ele
assert.deepEqual(marked('<u>x</u>'), document(paragraph(text('x', { type: 'underline' }))))
assert.deepEqual(marked('<sub>x</sub>'), document(paragraph(text('x', { attrs: { type: 'sub' }, type: 'subsup' }))))
assert.deepEqual(marked('<sup>x</sup>'), document(paragraph(text('x', { attrs: { type: 'sup' }, type: 'subsup' }))))
assert.deepEqual(marked('<span style="color:#ff5630">x</span>'), document(paragraph(text('x', { attrs: { color: '#ff5630' }, type: 'textColor' }))))
assert.deepEqual(marked('<mark style="background-color:#fffae6">x</mark>'), document(paragraph(text('x', { attrs: { color: '#fffae6' }, type: 'backgroundColor' }))))
assert.deepEqual(marked('<strong><u><span style="color:red">x</span></u></strong>'), document(paragraph(text('x', { type: 'strong' }, { type: 'underline' }, { attrs: { color: 'red' }, type: 'textColor' }))))
assert.deepEqual(marked('a<span style="color:red">b</span>'), document(paragraph(text('a'), text('b', { attrs: { color: 'red' }, type: 'textColor' }))))
assert.deepEqual(marked('<span data-text-color="#ff5630">x</span>'), document(paragraph(text('x', { attrs: { color: '#ff5630' }, type: 'textColor' }))))
assert.deepEqual(marked('<mark data-background-color="#fffae6">x</mark>'), document(paragraph(text('x', { attrs: { color: '#fffae6' }, type: 'backgroundColor' }))))
assert.deepEqual(marked('<strong><u><span data-text-color="red">x</span></u></strong>'), document(paragraph(text('x', { type: 'strong' }, { type: 'underline' }, { attrs: { color: 'red' }, type: 'textColor' }))))
assert.deepEqual(marked('a<span data-text-color="red">b</span>'), document(paragraph(text('a'), text('b', { attrs: { color: 'red' }, type: 'textColor' }))))
})
test('refuses a mark element the writer does not write', () => {
for (const inner of ['<span style="color:red;x:y">x</span>', '<span style="background-color:red">x</span>', '<mark style="color:red">x</mark>', '<mark>x</mark>', '<span style="color:">x</span>', '<span style="color:red" class="c">x</span>', '<u class="c">x</u>', '<sub style="color:red">x</sub>', '<span style="color:red"><span style="color:blue">x</span></span>']) {
for (const inner of ['<span style="color:red">x</span>', '<mark style="background-color:red">x</mark>', '<span data-background-color="red">x</span>', '<mark data-text-color="red">x</mark>', '<mark>x</mark>', '<span data-text-color="red" class="c">x</span>', '<span data-text-color="red" data-background-color="red">x</span>', '<u class="c">x</u>', '<sub data-text-color="red">x</sub>', '<span data-text-color="red"><span data-text-color="blue">x</span></span>']) {
assert.notEqual(refusal(htmlToAdf(`<p>${inner}</p>\n`)), 'read', inner)
}
})
@@ -261,13 +261,13 @@ test('reads a paragraph or heading with a data-indent-level attribute as indente
assert.deepEqual(read(htmlToAdf('<ul>\n<li><p data-indent-level="3">x</p></li>\n</ul>\n')), document({ content: [item({ content: [text('x')], marks: [indentation(3)], type: 'paragraph' })], type: 'bulletList' }))
})
test('reads a paragraph or heading with a style attribute as aligned, right as end', () => {
test('reads a paragraph or heading with a data-align attribute as aligned', () => {
const alignment = (align: string): AdfMark => ({ attrs: { align }, type: 'alignment' })
assert.deepEqual(read(htmlToAdf('<p style="text-align:center">x</p>\n')), document({ content: [text('x')], marks: [alignment('center')], type: 'paragraph' }))
assert.deepEqual(read(htmlToAdf('<h2 style="text-align:right">x</h2>\n')), document({ attrs: { level: 2 }, content: [text('x')], marks: [alignment('end')], type: 'heading' }))
assert.deepEqual(read(htmlToAdf(`<p style="text-align:right" data-local-id="${ids.paragraph}"></p>\n`)), document({ attrs: { localId: ids.paragraph }, marks: [alignment('end')], type: 'paragraph' }))
assert.deepEqual(read(htmlToAdf('<ul>\n<li><p style="text-align:center">x</p></li>\n</ul>\n')), document({ content: [item({ content: [text('x')], marks: [alignment('center')], type: 'paragraph' })], type: 'bulletList' }))
for (const html of ['<p style="text-align:left">x</p>\n', '<p style="text-align:center;color:red">x</p>\n', `<p data-local-id="${ids.paragraph}" style="text-align:center">x</p>\n`, '<figure class="adf-media-single" style="text-align:center"><img src="a"></figure>\n', '<blockquote style="text-align:center">\n<p>x</p>\n</blockquote>\n']) {
assert.deepEqual(read(htmlToAdf('<p data-align="center">x</p>\n')), document({ content: [text('x')], marks: [alignment('center')], type: 'paragraph' }))
assert.deepEqual(read(htmlToAdf('<h2 data-align="end">x</h2>\n')), document({ attrs: { level: 2 }, content: [text('x')], marks: [alignment('end')], type: 'heading' }))
assert.deepEqual(read(htmlToAdf(`<p data-align="end" data-local-id="${ids.paragraph}"></p>\n`)), document({ attrs: { localId: ids.paragraph }, marks: [alignment('end')], type: 'paragraph' }))
assert.deepEqual(read(htmlToAdf('<ul>\n<li><p data-align="center">x</p></li>\n</ul>\n')), document({ content: [item({ content: [text('x')], marks: [alignment('center')], type: 'paragraph' })], type: 'bulletList' }))
for (const html of ['<p style="text-align:center">x</p>\n', '<p data-align="left">x</p>\n', '<p data-align="right">x</p>\n', '<p data-align="">x</p>\n', `<p data-local-id="${ids.paragraph}" data-align="center">x</p>\n`, '<p data-align="center" data-align="end">x</p>\n', '<figure class="adf-media-single" data-align="center"><img src="a"></figure>\n', '<blockquote data-align="center">\n<p>x</p>\n</blockquote>\n']) {
assert.notEqual(refusal(htmlToAdf(html)), 'read', html)
}
})
@@ -305,9 +305,10 @@ test('reads a table back, its rows, cells and attributes as adfToHtml writes the
assert.deepEqual(read(htmlToAdf('<table>\n<tbody>\n<tr><td></td><th></th></tr>\n</tbody>\n</table>\n')), document({ content: [row({ type: 'tableCell' }, { type: 'tableHeader' })], type: 'table' }))
assert.deepEqual(read(htmlToAdf('<table>\n<tbody>\n<tr><td>a\n<p>b</p>\n</td><td>\n<hr>\n</td></tr>\n</tbody>\n</table>\n')), document({ content: [row({ content: [paragraph(text('a')), paragraph(text('b'))], type: 'tableCell' }, { content: [{ type: 'rule' }], type: 'tableCell' })], type: 'table' }))
assert.deepEqual(
read(htmlToAdf('<table data-layout="wide" data-width="760">\n<tbody>\n<tr data-local-id="r1"><td colspan="2" rowspan="3" style="background-color:#fffae6" data-colwidth="120,80" data-local-id="c1" data-valign="top">x</td></tr>\n</tbody>\n</table>\n')),
read(htmlToAdf('<table data-layout="wide" data-width="760">\n<tbody>\n<tr data-local-id="r1"><td colspan="2" rowspan="3" data-background-color="#fffae6" data-colwidth="120,80" data-local-id="c1" data-valign="top">x</td></tr>\n</tbody>\n</table>\n')),
document({ attrs: { layout: 'wide', width: 760 }, content: [{ attrs: { localId: 'r1' }, content: [{ attrs: { background: '#fffae6', colspan: 2, colwidth: [120, 80], localId: 'c1', rowspan: 3, valign: 'top' }, content: [paragraph(text('x'))], type: 'tableCell' }], type: 'tableRow' }], type: 'table' }),
)
assert.deepEqual(read(htmlToAdf('<table>\n<tbody>\n<tr><td colspan="2" style="background-color:#fffae6" data-colwidth="120">x</td></tr>\n</tbody>\n</table>\n')), document({ content: [row({ attrs: { background: '#fffae6', colspan: 2, colwidth: [120] }, content: [paragraph(text('x'))], type: 'tableCell' })], type: 'table' }))
assert.deepEqual(read(htmlToAdf('<ul>\n<li>\n<table></table>\n</li>\n</ul>\n')), document({ content: [item({ type: 'table' })], type: 'bulletList' }))
})
@@ -334,6 +335,8 @@ const tableRefusals: readonly (readonly [string, string])[] = [
['<table>\n<tbody>\n<tr><td rowspan="x">a</td></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<tbody>\n<tr><td style="color:red">a</td></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<tbody>\n<tr><td style="background-color:url(x)">a</td></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<tbody>\n<tr><td style="background-color:red" data-background-color="red">a</td></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<tbody>\n<tr><td data-colwidth="1" data-background-color="red">a</td></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<tbody>\n<tr><td data-colwidth="[1]">a</td></tr>\n</tbody>\n</table>\n', 'unsupported-node-shape'],
['<table>\n<tbody>\n<tr><td data-colwidth="01">a</td></tr>\n</tbody>\n</table>\n', 'unsupported-node-shape'],
['<table data-size="big"></table>\n', 'unsupported-node-shape'],
@@ -342,7 +345,7 @@ const tableRefusals: readonly (readonly [string, string])[] = [
['<table>\n<tfoot>\n<tr></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<thead>\n<tr><th>a</th></tr>\n</tfoot>\n<tbody>\n<tr></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<tbody>\n<tr><td colspan="2x">a</td></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<tbody>\n<tr><td style="color:red;background-color:red">a</td></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<tbody>\n<tr><td data-background-color="red" data-background-color="red">a</td></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
['<table>\n<tbody>\n<tr><td>a<hr>\n</td></tr>\n</tbody>\n</table>\n', 'unmappable-html'],
]
@@ -701,7 +704,7 @@ const pinnedRefusals: readonly (readonly [string, string])[] = [
['<div class="adf-panel" data-panel-type="info" data-local-id="p">\n<p>a</p>\n</div>\n', 'unmappable-html at /content/0: the data-* attributes stand once each, sorted by the attribute they name: found data-local-id after data-panel-type'],
['<div class="adf-panel" data-panel-type="info">\n</div>\n', 'unmappable-html at /content/0/content/0: a block element of the dialect stands here: found "</div>\\n"'],
['<div class="adf-panel" data-panel-type="info"><p>a</p></div>\n', 'unmappable-html at /content/0: <div> holds </div> straight after it, or a line feed and its first block: found "<p>a</p></div>\\n"'],
['<div id="x" class="adf-panel">\n<p>a</p>\n</div>\n', 'unmappable-html at /content/0: a <div> of the dialect is a carry element, holding class="adf-carry" and then data-adf alone: found "<div id=\\"x\\" class=\\"adf-p"…'],
['<div id="x" class="adf-panel">\n<p>a</p>\n</div>\n', 'unmappable-html at /content/0: a <div> of the dialect is a carry element, holding class="adf-carry" and then data-adf alone, or opens with class="adf-media-group" or "adf-panel": found "<div id=\\"x\\" class=\\"adf-p"…'],
['<details class="adf-expand" open="x">\n<p>a</p>\n</details>\n', 'unmappable-html at /content/0: <details> takes open="" once, after its other attributes'],
['<details class="adf-expand" data-title="a">\n<p>a</p>\n</details>\n', 'unsupported-node-shape at /content/0: <details> takes no data-title attribute'],
['<details>\n<p>a</p>\n</details>\n', 'unmappable-html at /content/0: <details> starts with class="adf-expand" or class="adf-nested-expand": found "<details>\\n<p>a</p>\\n</det"…'],
@@ -734,20 +737,24 @@ const pinnedRefusals: readonly (readonly [string, string])[] = [
['<div class="adf-media-group"><span class="adf-file" data-id="a" data-type="file"></span><span class="adf-file" data-bogus="1"></span></div>\n', 'unsupported-node-shape at /content/0/content/1: <span> takes no data-bogus attribute'],
['<div class="adf-media-group"><span class="adf-file" data-id="a" data-type="file">x</span></div>\n', 'unmappable-html at /content/0/content/0: <span class="adf-file"> holds nothing, and ends at </span>: found "x</span></div>\\n"'],
['<div class="adf-media-group"><span class="adf-file" data-id="a" data-type="file"></span>x</div>\n', 'unmappable-html at /content/0: <div> holds its <span class="adf-file"> files, then </div>: found "x</div>\\n"'],
['<p style="color:red">a</p>\n', 'unmappable-html at /content/0: style on <p> holds text-align:center or text-align:right'],
['<h1 style="text-align:left">a</h1>\n', 'unmappable-html at /content/0: style on <h1> holds text-align:center or text-align:right'],
['<p data-align="left">a</p>\n', 'unmappable-html at /content/0: data-align on <p> holds center or end'],
['<p style="text-align:center">a</p>\n', 'unmappable-html at /content/0: <p> takes no style attribute'],
['<h1 data-align="right">a</h1>\n', 'unmappable-html at /content/0: data-align on <h1> holds center or end'],
['<p data-indent-level="7">a</p>\n', 'unmappable-html at /content/0: data-indent-level on <p> holds a whole number from 1 to 6'],
['<p data-indent-level="0">a</p>\n', 'unmappable-html at /content/0: data-indent-level on <p> holds a whole number from 1 to 6'],
['<p data-indent-level="02">a</p>\n', 'unmappable-html at /content/0: data-indent-level on <p> holds a whole number from 1 to 6'],
['<p data-indent-level="1.5">a</p>\n', 'unmappable-html at /content/0: data-indent-level on <p> holds a whole number from 1 to 6'],
['<p data-indent-level="2" style="text-align:center">a</p>\n', 'unmappable-html at /content/0: <p> takes no style attribute'],
['<p data-indent-level="2" data-align="center">a</p>\n', 'unmappable-html at /content/0: <p> takes one of data-align and data-indent-level, first, before its data-* attributes'],
['<blockquote data-indent-level="2">\n<p>a</p>\n</blockquote>\n', 'unsupported-node-shape at /content/0: <blockquote> takes no data-indent-level attribute'],
['<h3 data-indent-level="">a</h3>\n', 'unmappable-html at /content/0: data-indent-level on <h3> holds a whole number from 1 to 6'],
['<p data-local-id="p1" data-indent-level="2">a</p>\n', 'unmappable-html at /content/0: <p> takes data-indent-level once, first, before its data-* attributes'],
['<p data-indent-level="2" data-indent-level="2">a</p>\n', 'unmappable-html at /content/0: <p> takes data-indent-level once, first, before its data-* attributes'],
['<p style="text-align:center" data-indent-level="2">a</p>\n', 'unmappable-html at /content/0: <p> takes data-indent-level once, first, before its data-* attributes'],
['<p data-local-id="p1" data-indent-level="2">a</p>\n', 'unmappable-html at /content/0: <p> takes one of data-align and data-indent-level, first, before its data-* attributes'],
['<p data-indent-level="2" data-indent-level="2">a</p>\n', 'unmappable-html at /content/0: <p> takes one of data-align and data-indent-level, first, before its data-* attributes'],
['<p data-align="center" data-indent-level="2">a</p>\n', 'unmappable-html at /content/0: <p> takes one of data-align and data-indent-level, first, before its data-* attributes'],
['<details class="adf-expand" open="" open="">\n<p>a</p>\n</details>\n', 'unmappable-html at /content/0: <details> takes open="" once, after its other attributes'],
['<p>a <span title="color:red">b</span></p>\n', 'unmappable-html at /content/0/content/1: a <span> of the dialect is a carry element, holding class="adf-carry" and then data-adf alone, or opens with class="adf-emoji", "adf-mention" or "adf-status": found "<span title=\\"color:red\\">"…'],
['<p>a <span title="color:red">b</span></p>\n', 'unmappable-html at /content/0/content/1: a <span> of the dialect is a carry element, holding class="adf-carry" and then data-adf alone, opens with class="adf-emoji", "adf-mention" or "adf-status", or holds data-text-color alone: found "<span title=\\"color:red\\">"…'],
['<p>a <span style="color:red">b</span></p>\n', 'unmappable-html at /content/0/content/1: a <span> of the dialect is a carry element, holding class="adf-carry" and then data-adf alone, opens with class="adf-emoji", "adf-mention" or "adf-status", or holds data-text-color alone: found "<span style=\\"color:red\\">"…'],
['<p>a <mark style="background-color:red">b</mark></p>\n', 'unmappable-html at /content/0/content/1: a <mark> of the dialect holds data-background-color alone: found "<mark style=\\"background-"…'],
['<p>a <mark>b</mark></p>\n', 'unmappable-html at /content/0/content/1: a <mark> of the dialect holds data-background-color alone: found "<mark>b</mark></p>\\n"'],
['<blockquote><p>a</p></blockquote>\n', 'unmappable-html at /content/0: <blockquote> holds </blockquote> straight after it, or a line feed and its first block: found "<p>a</p></blockquote>\\n"'],
['<ul><li>a</li></ul>\n', 'unmappable-html at /content/0: <ul> holds </ul> straight after it, or a line feed and its first item: found "<li>a</li></ul>\\n"'],
['<details class="adf-expand">\n<summary>a\n</details>\n', 'unmappable-html at /content/0: <summary> ends at </summary>: found "a\\n</details>\\n"'],
+2 -2
View File
@@ -6,7 +6,7 @@ import { built, readInlineBlock } from './inline-block.ts'
import { carryContent } from '../carry-content.ts'
import { centeredImage, externalMedia } from '../../adf/plain-image.ts'
import { containerElements, headingElements, headingLevel, readListStart, type ContainerType } from '../block-elements.ts'
import { expandClasses, expandOfClass, panelAttributes, panelClass, taskListOfClass, taskListOfType } from '../block-classes.ts'
import { expandClasses, expandOfClass, mediaGroupClass, panelAttributes, panelClass, taskListOfClass, taskListOfType } from '../block-classes.ts'
import { firstParagraphForm } from '../first-paragraph.ts'
import { foundAt, misread, misspelledText, positionIn, readStartTag, refused, startTagName, type Place, type ReadNode, type StartTag } from './source.ts'
import { isHeaderRow, readCellAttributes } from '../cell-element.ts'
@@ -228,7 +228,7 @@ function readDiv(html: string, tag: StartTag, place: Place, open: Open): Result<
const [first] = tag.attributes
const className = first?.[0] === 'class' ? first[1] : undefined
if (className === panelClass) return readPanel(html, tag, place, open)
return className === 'adf-media-group' ? asStep(readMediaGroup(html, tag, place)) : readBlockCarry(html, tag, place, open)
return className === mediaGroupClass ? asStep(readMediaGroup(html, tag, place)) : readBlockCarry(html, tag, place, open)
}
function readPanel(html: string, tag: StartTag, place: Place, open: Open): Result<BlockStep, ParseError> {
+2 -1
View File
@@ -1,9 +1,9 @@
import type { AdfMark, AdfNode } from '../../adf/document.ts'
import type { ParseError, Result } from '../../result.ts'
import { colourAttributeOn, markOfTag } from '../mark-elements.ts'
import { foundAt, misread, misspelledText, readStartTag, refused, type Place, type ReadNode, type StartTag } from './source.ts'
import { largestNesting } from '../../nesting.ts'
import { linkMarkFrom } from '../../adf/mark-attributes.ts'
import { markOfTag } from '../mark-elements.ts'
import { misspelledAt, unescapedValue } from '../escaping.ts'
import { readAnchorAttributes } from '../anchor-element.ts'
import { readCarry } from './carry-element.ts'
@@ -32,6 +32,7 @@ function readTagged(html: string, index: number, place: Place): ReadNode | undef
const element = tag === undefined ? undefined : readNodeElement(html, tag, place)
if (element !== undefined) return element
if (tag !== undefined && markOf(tag) !== undefined) return readMarked(html, index, place)
if (tag?.name === 'mark') return refused('unmappable-html', `a <mark> of the dialect holds ${colourAttributeOn('mark')} alone: ${foundAt(html, index)}`, html, index, place)
return tag?.name === 'span' ? readCarry(html, tag, 'span', largestNesting, place) : undefined
}
+2 -2
View File
@@ -3,6 +3,7 @@ import { blockNodes } from '../../adf/block-nodes.ts'
import { built, readInlineBlock } from './inline-block.ts'
import { foundAt, readStartTag, refused, type Place, type ReadNode, type StartTag } from './source.ts'
import { linkMarkFrom } from '../../adf/mark-attributes.ts'
import { mediaGroupClass } from '../block-classes.ts'
import { readAnchorAttributes } from '../anchor-element.ts'
import { readDataAttributes } from '../data-attributes.ts'
import { readMediaImage } from '../media-element.ts'
@@ -10,7 +11,6 @@ import { success } from '../../result.ts'
const figureClass = 'adf-media-single'
const fileClass = 'adf-file'
const groupClass = 'adf-media-group'
// A `mediaSingle` as `adfToHtml` writes it: its media's image, then its caption, on one line.
export function readFigure(html: string, tag: StartTag, place: Place): ReadNode {
@@ -34,7 +34,7 @@ export function readFigure(html: string, tag: StartTag, place: Place): ReadNode
// A `mediaGroup` as `adfToHtml` writes it: a span for each media, none between.
export function readMediaGroup(html: string, tag: StartTag, place: Place): ReadNode {
if (tag.attributes.length !== 1) return refused('unmappable-html', `<div class="${groupClass}"> takes no other attribute: ${foundAt(html, tag.start)}`, html, tag.start, place)
if (tag.attributes.length !== 1) return refused('unmappable-html', `<div class="${mediaGroupClass}"> takes no other attribute: ${foundAt(html, tag.start)}`, html, tag.start, place)
const content: AdfNode[] = []
let at = tag.end
for (let span = readStartTag(html, at); span?.name === 'span'; span = readStartTag(html, at)) {
+6 -14
View File
@@ -4,14 +4,8 @@ import type { Read } from '../result.ts'
import { dataAttributes, readDataAttributes } from './data-attributes.ts'
import { nodeAttrs, nodeMarks } from '../adf/document.ts'
// The `text-align` value each alignment names.
function alignments(): ReadonlyMap<string, string> {
return new Map([
['center', 'center'],
['end', 'right'],
])
}
const alignAttribute = 'data-align'
const alignments = ['center', 'end']
const indentAttribute = 'data-indent-level'
const indentLevels = ['1', '2', '3', '4', '5', '6']
@@ -30,8 +24,7 @@ function markAttribute(mark: AdfMark): string | undefined {
const attrs = nodeAttrs(mark)
if (Object.keys(attrs).length !== 1) return undefined
const { align, level } = attrs
const textAlign = [...alignments()].find(([name]) => name === align)?.[1]
if (mark.type === 'alignment') return textAlign === undefined ? undefined : ` style="text-align:${textAlign}"`
if (mark.type === 'alignment') return typeof align === 'string' && alignments.includes(align) ? ` ${alignAttribute}="${align}"` : undefined
return mark.type === 'indentation' && typeof level === 'number' && indentLevels.includes(String(level)) ? ` ${indentAttribute}="${level}"` : undefined
}
@@ -41,7 +34,7 @@ export function readTextBlockAttributes(pairs: readonly (readonly [string, strin
const mark = first === undefined ? undefined : readMark(first, element)
if (mark?.fault !== undefined) return mark
const rest = mark === undefined ? pairs : pairs.slice(1)
if (rest.some(([name]) => name === indentAttribute)) return { fault: { code: 'unmappable-html', message: `<${element}> takes ${indentAttribute} once, first, before its data-* attributes` } }
if (rest.some(([name]) => name === alignAttribute || name === indentAttribute)) return { fault: { code: 'unmappable-html', message: `<${element}> takes one of ${alignAttribute} and ${indentAttribute}, first, before its data-* attributes` } }
const data = readDataAttributes(rest, element, vocabulary, written)
if (data.fault !== undefined) return data
return { value: { attrs: data.value, marks: mark === undefined ? [] : [mark.value] } }
@@ -51,7 +44,6 @@ function readMark([name, spelled]: readonly [string, string], element: string):
if (name === indentAttribute) {
return indentLevels.includes(spelled) ? { value: { attrs: { level: Number(spelled) }, type: 'indentation' } } : { fault: { code: 'unmappable-html', message: `${indentAttribute} on <${element}> holds a whole number from 1 to 6` } }
}
if (name !== 'style') return undefined
const align = [...alignments()].find(([, textAlign]) => spelled === `text-align:${textAlign}`)?.[0]
return align === undefined ? { fault: { code: 'unmappable-html', message: `style on <${element}> holds text-align:center or text-align:right` } } : { value: { attrs: { align }, type: 'alignment' } }
if (name !== alignAttribute) return undefined
return alignments.includes(spelled) ? { value: { attrs: { align: spelled }, type: 'alignment' } } : { fault: { code: 'unmappable-html', message: `${alignAttribute} on <${element}> holds center or end` } }
}
-12
View File
@@ -12,10 +12,8 @@
| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 188 | 0.4.0 | | defect | **Write no `style` attribute in `adfToHtml`: spell text and background colours, alignment and a cell's background with classes or `data-*` attributes, and read them back in `htmlToAdf`.** | 3 | 1 | 2 | 4 | 5 | 10 by 10 | 21.2 |
| 189 | 0.4.0 | | | **Lower the reading cost of the files a chunk reads most before its first commit.** | 2 | 1 | 1 | 2 | 3 | code health by 3 | 15.9 |
| 46 | 0.4.0 | | | **Publish the bundle size in the README, failing the release pipeline when it drifts.** | 2 | 2 | 1 | 3 | 4 | 3 by 3 | 2.6 |
| 186 | 0.4.0 | | | **Name every spelling of the dialect's `<div>`, `<span>` and `<mark>` in the refusal of one that matches none.** | 1 | 1 | 1 | 1 | 1 | 6 by 1 | 1.9 |
| 174 | 0.4.0 | | defect | **Bound the passes `trimmedEdges` takes by a constant, so a line of alternating code and emphasized blanks trims in linear time.** | 3 | 1 | 2 | 4 | 7 | 9 by 3 | 1.9 |
| 51 | 0.4.0 | | | **Match a reference label to its definition under Unicode case folding.** | 2 | 1 | 2 | 3 | 4 | 4 by 2 | 1.7 |
| 148 | 0.4.0 | | | **Ship conversion between ADF and Jira wiki markup both ways, under a README goal for wiki markup.** | 3 | 2 | 2 | 5 | 7 | 3 by 5 | 0.8 |
@@ -49,12 +47,6 @@
## Details
### 188. Write no `style` attribute in `adfToHtml`: spell text and background colours, alignment and a cell's background with classes or `data-*` attributes, and read them back in `htmlToAdf`.
The unreleased dialect writes four `style` attributes, which README goal 10 rules out: `style="text-align:center|right"` on a paragraph or heading, `<span style="color:…">`, `<mark style="background-color:…">` and a cell's `style="background-color:…"`.
A colour is any run of letters and digits after an optional `#`, so a class per colour cannot spell it. The likely spelling is a `data-*` attribute holding the value beside a class naming the element, and for an alignment a class such as `adf-align-center`. Each spelling is settled by a writer panel (AGENTS.md §7), then written in `spec/html.md`, the README table, the `CHANGELOG.md` bullets that name the `style` spellings and `docs/decisions.md` §The HTML dialect, whose style lines this item replaces. The carry element `0.3.1` wrote still reads; the style spellings were never released, so `htmlToAdf` stops reading them.
### 189. Lower the reading cost of the files a chunk reads most before its first commit.
The last 5 chunks' median is 155854 new input tokens before their first commit, the 5 before them 92724 (`~/.claude/bin/reading-cost`, `docs/reading-cost.md`).
@@ -73,10 +65,6 @@ or report the unminified gzip). The figure lands in README §The package beside
dependencies" claim, and in a size column of the comparison table. Measured today,
unminified: tarball 60.4 kB, unpacked 221.5 kB, JS gzipped 45.6 kB.
### 186. Name every spelling of the dialect's `<div>`, `<span>` and `<mark>` in the refusal of one that matches none.
A `<div>` or `<span>` of the dialect that is no carry element is refused with a message naming the carry element and the classes of `nodeElements`, which leaves out the panel, the media group, the file `<span>` and the colour spans. A reader who writes `<span style="color: red">`, `<mark style="background-color: #fffae6">` or a bare `<mark>` gets that message or "no inline element of the dialect", neither of which names the spelling `adfToHtml` writes: `style="color:#rrggbb"`, no space, and `<mark style="background-color:#rrggbb">`. Name each spelling in the message of `readCarry` and in the one `readTagged` gives a `mark`, each pinned in `pinnedRefusals`.
### 174. Bound the passes `trimmedEdges` takes by a constant, so a line of alternating code and emphasized blanks trims in linear time.
`trimmedEdges` (`src/markdown/portable/inline-reduction.ts`) repeats a pass until nothing changes, and