3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-20 07:05:44 +01:00

Kill the surviving mutants of the wiki writer's cell, heading and carry-path changes

This commit is contained in:
2026-11-17 03:09:51 +01:00
committed by Lillem4n
parent f36c0378fe
commit 43ec9f1db8
2 changed files with 17 additions and 4 deletions
+6 -4
View File
@@ -7,8 +7,11 @@ const alwaysEscaped = '[]{}|'
const delimiters = '*+-^_~'
const lineStartMarkers = '#*-'
const lineStartWords = /^(?:bq|h[1-6])\./i
const smileyOpeners = '(:;'
const smileyCharacters = smileys.map((smiley) => ({ characters: Array.from(smiley), parenthesised: /[()]$/.test(smiley) }))
const smileysByOpener = new Map<string, { characters: string[]; parenthesised: boolean }[]>()
for (const smiley of smileys) {
const opener = smiley.charAt(0)
smileysByOpener.set(opener, [...(smileysByOpener.get(opener) ?? []), { characters: Array.from(smiley), parenthesised: /[()]/.test(smiley) }])
}
const unprotectable = /[\\\r\n]|https?:\/\//i
// spec/wiki.md, Inline: `undefined` where no backslash protects the text, so it rides the carry. `inCell`: the text stands in a table cell, where an escaped `|` still ends the cell.
@@ -40,8 +43,7 @@ function escapes(character: string, characters: readonly string[], index: number
function smileyStops(characters: readonly string[], end: Side): Set<number> | undefined {
const stops = new Set<number>()
for (const [index, character] of characters.entries()) {
if (!smileyOpeners.includes(character)) continue
for (const { characters: spelled, parenthesised } of smileyCharacters) {
for (const { characters: spelled, parenthesised } of smileysByOpener.get(character) ?? []) {
const held = characters.slice(index, index + spelled.length)
if (held.some((heldCharacter, offset) => heldCharacter !== spelled[offset])) continue
const cut = held.length < spelled.length