mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-13 04:08:29 +01:00
Answer product-owner round 2: 0 🔴, 2 🟡 (0 misread); a code element, an item's line and a mark element's content refused through misread, naming what they found
This commit is contained in:
@@ -279,7 +279,13 @@ const messages: readonly (readonly [string, string])[] = [
|
||||
['<p><a href="a"b">a</a></p>\n', '<a> holds its attributes as name="value", each value escaped as text is, then >: found "b\\">a</a></p>\\n"'],
|
||||
['<p>a \u00a0</p>\n', 'text escapes &, <, > and " as &, <, > and ", and holds no character HTML cannot hold: found " \\u00a0</p>\\n"'],
|
||||
['<pre><code>a</code></pre\n', 'a code block\'s text ends at </code></pre>: found "</code></pre\\n"'],
|
||||
['<ul>\n<li>a</ul>\n', 'an item\'s line ends at </li>, or at a line feed before the item\'s next block: found "</ul>\\n"'],
|
||||
['<pre><code class="hljs language-js">x</code></pre>\n', '<code> as written here is no code element of the dialect, which writes <code> or <code class="language-…">: found "<code class=\\"hljs langua"…'],
|
||||
['<ul>\n<li>a</ul>\n', 'an item\'s line ends at </li>, or at a line feed before the item\'s next block, and its text spells < as <: found "</ul>\\n"'],
|
||||
['<ul>\n<li>a<b>b</b></li>\n</ul>\n', '<b> as written here is no inline element of the dialect: found "<b>b</b></li>\\n</ul>\\n"'],
|
||||
['<ul>\n<li>if a < b</li>\n</ul>\n', 'an item\'s line ends at </li>, or at a line feed before the item\'s next block, and its text spells < as <: found "< b</li>\\n</ul>\\n"'],
|
||||
['<ul>\n<li>see <a href="https://x.test/?a=1&b=2">x</a></li>\n</ul>\n', '<a> holds its attributes as name="value", each value escaped as text is, then >: found "&b=2\\">x</a></li>\\n</ul>\\n"'],
|
||||
['<p><strong><b>x</b></strong></p>\n', '<b> as written here is no mark element of the dialect: found "<b>x</b></strong></p>\\n"'],
|
||||
['<p><strong><a href="https://x.test/?a=1&b=2">x</a></strong></p>\n', '<a> holds its attributes as name="value", each value escaped as text is, then >: found "&b=2\\">x</a></strong></p>"…'],
|
||||
[`<p>a</p>\n${carry('div', panel, '<p>Check the <b>collation</b>.</p>')}\n`, 'a carry element shows its node\'s text as adfToHtml writes it, then ends at </div>; an edit to it is no edit to the node: found "<b>collation</b>.</p></d"…'],
|
||||
]
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ function readCodeBlock(html: string, tag: StartTag, place: Place): Result<BlockS
|
||||
const code = readStartTag(html, tag.end)
|
||||
const named = code?.name === 'code' ? readLanguageClass(code.attributes) : undefined
|
||||
if (code === undefined || named === undefined) {
|
||||
const stop = misread(html, tag.end, '<pre> holds <code>, or <code class="language-…"> naming the language', 'neither')
|
||||
const stop = misread(html, tag.end, '<pre> holds <code>, or <code class="language-…"> naming the language', 'no code element of the dialect, which writes <code> or <code class="language-…">')
|
||||
return refused('unmappable-html', stop.message, html, stop.at, place)
|
||||
}
|
||||
const next = html.indexOf('<', code.end)
|
||||
@@ -248,7 +248,8 @@ function readItemLine(html: string, index: number, open: Open): Result<BlockStep
|
||||
if (!line.ok) return line
|
||||
const { end, node } = line.value
|
||||
if (!html.startsWith('</li>', end) && !html.startsWith('\n', end)) {
|
||||
return refused('unmappable-html', `an item's line ends at </li>, or at a line feed before the item's next block: ${foundAt(html, end)}`, html, end, open.place)
|
||||
const stop = misread(html, end, "an item's line ends at </li>, or at a line feed before the item's next block, and its text spells < as <", 'no inline element of the dialect')
|
||||
return refused('unmappable-html', stop.message, html, stop.at, open.place)
|
||||
}
|
||||
const paragraph = asFirstParagraph({ end, node }, line.value.form, html, index, place)
|
||||
if (!paragraph.ok) return paragraph
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AdfMark, AdfNode } from '../../adf/document.ts'
|
||||
import type { ParseError, Result } from '../../result.ts'
|
||||
import { foundAt, readStartTag, refused, type Place, type ReadNode, type StartTag } from './source.ts'
|
||||
import { foundAt, misread, readStartTag, refused, type Place, type ReadNode, type StartTag } from './source.ts'
|
||||
import { largestNesting } from '../../nesting.ts'
|
||||
import { linkMarkFrom } from '../../adf/mark-attributes.ts'
|
||||
import { markOfElement } from '../mark-elements.ts'
|
||||
@@ -46,7 +46,10 @@ function readMarked(html: string, index: number, place: Place): ReadNode {
|
||||
closers.unshift(`</${tag.name}>`)
|
||||
at = tag.end
|
||||
}
|
||||
if (at === html.length || html.startsWith('<', at)) return refused('unmappable-html', `a mark element holds one text, or one mark element holding it: ${foundAt(html, at)}`, html, at, place)
|
||||
if (at === html.length || html.startsWith('<', at)) {
|
||||
const stop = misread(html, at, 'a mark element holds one text, or one mark element holding it', 'no mark element of the dialect')
|
||||
return refused('unmappable-html', stop.message, html, stop.at, place)
|
||||
}
|
||||
const text = readText(html, at, marks, place)
|
||||
if (!text.ok) return text
|
||||
at = text.value.end
|
||||
|
||||
Reference in New Issue
Block a user