3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 14:45:44 +01:00

Write media, colours, alignment, panels, expands and task lists as HTML in adfToHtml and read them back in htmlToAdf

This commit is contained in:
2026-11-15 00:03:44 +01:00
committed by Lillem4n
parent 4f81a65254
commit f5c8a48706
24 changed files with 1062 additions and 123 deletions
+15
View File
@@ -0,0 +1,15 @@
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 value = declaration.slice(property.length + 1)
return declaration.startsWith(`${property}:`) && colour.test(value) ? value : undefined
}