From a6c5f3e4317a0b8d300ee4fa63272b17783ab6cc Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Fri, 8 Sep 2023 00:04:00 -0400 Subject: [PATCH] Stub out HTML generation --- src/3x5.ts | 5 +++-- src/lib/html.ts | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/lib/html.ts diff --git a/src/3x5.ts b/src/3x5.ts index 5ed3b9c..428c2a6 100644 --- a/src/3x5.ts +++ b/src/3x5.ts @@ -1,3 +1,4 @@ +import { ALL as HTML } from './lib/html'; import { parse } from './parser'; import { runNoctl, Vm } from './vm'; import { AsHtml } from './words'; @@ -52,7 +53,7 @@ let theCard: Card = { [button "No we want to render UI" \\{noop}] } { - Since we want escapes to work, these blocks [i will] be subject to substitutions. + Since we want escapes to work, these blocks [i will] be subject to substitutions, maybe via a relaxed bareWordTmpl. } # A comment para { @@ -84,7 +85,7 @@ const debugDisplay = document.createElement("pre"); function render() { const vm: Vm = { mode: "render", - commands: {}, + commands: { ...HTML }, output: "", }; const html = renderCard(vm, theCard.code); diff --git a/src/lib/html.ts b/src/lib/html.ts new file mode 100644 index 0000000..72c9263 --- /dev/null +++ b/src/lib/html.ts @@ -0,0 +1,22 @@ +import { AsHtml, Concat, TextPiece } from '../words'; + +const htmlTagCmd = + (tag: string) => + ({}, argv: TextPiece[]): TextPiece => { + const [, ...words] = argv; + return ( + words + .map((word) => ({ html: `<${tag}>${AsHtml(word)}` })) + .reduce(Concat, null) ?? { html: "" } + ); + }; + +export const h1 = htmlTagCmd("h1"); +export const para = htmlTagCmd("p"); +export const block = htmlTagCmd("blockquote"); + +export const ALL = { + h1, + para, + block, +};