More HTML handlers
This commit is contained in:
parent
06633d9acd
commit
54c9b31cfa
1 changed files with 29 additions and 13 deletions
|
@ -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)}</${tag}>` }))
|
||||
.reduce(Concat, null) ?? { html: "" }
|
||||
);
|
||||
};
|
||||
({}, argv: TextPiece[]): ProcResult =>
|
||||
getOptRaw(argv, { $min: 1 }, (_opts, words) => {
|
||||
return (
|
||||
words
|
||||
.map((word) => ({ html: `<${tag}>${AsHtml(word)}</${tag}>` }))
|
||||
.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(" ")}</${tag}>`,
|
||||
};
|
||||
});
|
||||
|
||||
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,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue