From 54c9b31cfaa3313abeb37ac78b6cf7a14b719002 Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Fri, 20 Oct 2023 20:36:54 -0400 Subject: [PATCH] More HTML handlers --- src/lib/html.ts | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/lib/html.ts b/src/lib/html.ts index 72c9263..1d49fd6 100644 --- a/src/lib/html.ts +++ b/src/lib/html.ts @@ -1,22 +1,38 @@ -import { AsHtml, Concat, TextPiece } from '../words'; +import { AsHtml, Concat, ProcResult, TextPiece } from "../words"; +import { getOptRaw } from "./options"; -const htmlTagCmd = +const htmlBlockCmd = (tag: string) => - ({}, argv: TextPiece[]): TextPiece => { - const [, ...words] = argv; - return ( - words - .map((word) => ({ html: `<${tag}>${AsHtml(word)}` })) - .reduce(Concat, null) ?? { html: "" } - ); - }; + ({}, argv: TextPiece[]): ProcResult => + getOptRaw(argv, { $min: 1 }, (_opts, words) => { + 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"); +const htmlInlineCmd = + (tag: string) => + ({}, argv: TextPiece[]): ProcResult => + getOptRaw(argv, { $min: 1 }, (_opts, words) => { + return { + html: `<${tag}>${words.map((word) => AsHtml(word)).join(" ")}`, + }; + }); + +export const h1 = htmlInlineCmd("h1"); +export const para = htmlBlockCmd("p"); +export const block = htmlBlockCmd("blockquote"); +export const b = htmlInlineCmd("b"); +export const i = htmlInlineCmd("i"); +export const u = htmlInlineCmd("u"); export const ALL = { h1, para, block, + b, + i, + u, };