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:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user