3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-14 04:30:24 +01:00

Answer prose round 1: 0 🔴, 7 🟡 (0 misread); say a card shows its name, else its URL, and tighten the item 133 detail

This commit is contained in:
2026-11-04 16:44:10 +01:00
committed by Lillem4n
parent 4dfea72c9c
commit 1b0eec19d1
4 changed files with 13 additions and 20 deletions
+3 -3
View File
@@ -4,7 +4,7 @@ import { inlineNodeModel } from '../adf/inline-nodes.ts'
import { nodeAttrs } from '../adf/document.ts'
import { shownText, shownUrl } from '../adf/shown-text.ts'
// `shown` is the text the element holds and `leading.value` the attribute right after the class, each `undefined` where the node cannot be written as this element and rides the carry. The reader builds the node from the element's `data-*` attributes and text, then holds both to what `shown` and `leading.value` answer for it, so only what the writer writes reads back. `written` names the attributes the text stands in for, which no `data-*` attribute repeats.
// `shown` is the text the element holds and `leading.value` the attribute right after the class, each `undefined` where the node cannot be written as this element and rides the carry. The reader builds a node from the element's `data-*` attributes and text, and refuses it unless `shown` and `leading.value` give back that text and attribute, so only what the writer writes reads back. `written` names the attributes no `data-*` attribute may hold, since the text or `leading` spells them.
export type NodeElement = {
build(data: AdfAttributes, shown: string): AdfAttributes
class: string
@@ -33,7 +33,7 @@ const nodeElements: Readonly<Record<string, NodeElement>> = {
class: 'adf-inline-card',
element: 'a',
leading: { name: 'href', value: (node) => card(node)?.href },
mismatch: 'holds one URL, as its href and as its text, or the name and URL its data-data holds, as its text and its href; to change the card, change them together',
mismatch: 'holds one URL, as its href and as its text, or the URL its data-data holds as its href and its name, else that URL, as its text; to change the card, change them together',
shown: (node) => card(node)?.text,
vocabulary: attributesOf('inlineCard'),
written: ['url'],
@@ -46,7 +46,7 @@ function attributesOf(type: string): AttributeVocabulary {
return inlineNodeModel(type)?.attributes ?? {}
}
// A card holding `data` shows its name and links to the URL `data` holds; one holding both `data` and a `url` rides the carry, since read back its href would not say which of the two it spells.
// A card holding both `data` and a `url` rides the carry: its href, read back, could not say which of the two URLs it spells.
function card(node: AdfNode): { href: string; text: string } | undefined {
const { data, url } = nodeAttrs(node)
if (data === undefined) return typeof url === 'string' && url !== '' ? { href: url, text: url } : undefined
+2 -2
View File
@@ -430,8 +430,8 @@ const messages: readonly (readonly [string, string])[] = [
['<ol start="2" start="3">\n<li>a</li>\n</ol>\n', '<ol> takes start once, before its data-* attributes: found start after start'],
['<pre data-wrap="yes"><code>x</code></pre>\n', 'data-wrap holds no boolean written as compact JSON'],
['<p><span class="adf-emoji"></span></p>\n', '<span class="adf-emoji"> holds its text, which is not empty: found "</span></p>\\n"'],
['<p><a class="adf-inline-card" href="https://example.com/">Spec</a></p>\n', '<a class="adf-inline-card"> holds one URL, as its href and as its text, or the name and URL its data-data holds, as its text and its href; to change the card, change them together: found "Spec</a></p>\\n"'],
[`<p><a class="adf-inline-card" href="https://example.org/plan" data-data="${planData}">Plan</a></p>\n`, '<a class="adf-inline-card"> holds one URL, as its href and as its text, or the name and URL its data-data holds, as its text and its href; to change the card, change them together: found "Plan</a></p>\\n"'],
['<p><a class="adf-inline-card" href="https://example.com/">Spec</a></p>\n', '<a class="adf-inline-card"> holds one URL, as its href and as its text, or the URL its data-data holds as its href and its name, else that URL, as its text; to change the card, change them together: found "Spec</a></p>\\n"'],
[`<p><a class="adf-inline-card" href="https://example.org/plan" data-data="${planData}">Plan</a></p>\n`, '<a class="adf-inline-card"> holds one URL, as its href and as its text, or the URL its data-data holds as its href and its name, else that URL, as its text; to change the card, change them together: found "Plan</a></p>\\n"'],
['<p><time class="adf-date" datetime="2025-08-26" data-timestamp="1756080000000">x</time></p>\n', '<time class="adf-date"> shows the day its data-timestamp names, in datetime and as its text; to change the date, change all three: found "x</time></p>\\n"'],
['<p><span class="adf-emoji" data-size="big">a</span></p>\n', '<span class="adf-emoji"> takes no data-size attribute'],
['<p><span class="adf-status">a&b</span></p>\n', 'text escapes & as &amp;, < as &lt; and > as &gt;, and holds no character HTML cannot hold: found "&b</span></p>\\n"'],