diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-06-13 12:09:16 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-06-13 12:09:16 +0200 |
commit | 9d4ce0b515fd71dc38fb24db77be9572ebf0df64 (patch) | |
tree | 3d0b005c4ab79577fe4847210e78a54f310dbebf /static/formatters.ts | |
parent | Cleanup of zic. (diff) | |
parent | Replace some .tagName with instanceof. (diff) | |
download | calp-9d4ce0b515fd71dc38fb24db77be9572ebf0df64.tar.gz calp-9d4ce0b515fd71dc38fb24db77be9572ebf0df64.tar.xz |
Merge html-validator.
Adds an HTML validator which checks the soundness of our generated
document, both before and after javascript is ran (thanks to selenium).
This merge also fixes the initial problems, meaning that the HTML should
validate as of this commit.
Diffstat (limited to 'static/formatters.ts')
-rw-r--r-- | static/formatters.ts | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/static/formatters.ts b/static/formatters.ts index 828a0e8b..70f63504 100644 --- a/static/formatters.ts +++ b/static/formatters.ts @@ -6,11 +6,11 @@ import { makeElement } from './lib' declare global { interface Window { - formatters : Map<string, (e : HTMLElement, s : any) => void>; + formatters: Map<string, (e: HTMLElement, s: any) => void>; } } -let formatters : Map<string, (e : HTMLElement, s : any) => void>; +let formatters: Map<string, (e: HTMLElement, s: any) => void>; formatters = window.formatters = new Map(); @@ -18,13 +18,34 @@ formatters.set('categories', (el, d) => { for (let item of d) { let q = encodeURIComponent( `(member "${item}" (or (prop event (quote CATEGORIES)) (quote ())))`) - el.appendChild(makeElement('a', { - textContent: item, - href: `/search/?q=${q}`, - })) + el.appendChild(makeElement('a', { + textContent: item, + href: `/search/?q=${q}`, + })) } }) +function format_time_tag(el: HTMLElement, d: any): void { + if (el instanceof HTMLTimeElement) { + if (d instanceof Date) { + let fmt = ''; + if (!d.utc) { + fmt += '~L'; + } + fmt += '~Y-~m-~d' + if (!d.dateonly) { + fmt += 'T~H:~M:~S' + } + el.dateTime = d.format(fmt); + } + } + + formatters.get('default')!(el, d); +} + +formatters.set('dtstart', format_time_tag) +formatters.set('dtend', format_time_tag) + formatters.set('default', (el, d) => { let fmt; if ((fmt = el.dataset.fmt)) { |