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, };