1import { html, RawHTML } from "https://esm.town/v/postpostscript/html";
2
3export function multiFormat<R extends MultiFormat = { text: string }>(
4 strings: TemplateStringsArray,
5 ...replacements: (string | R)[]
31};
32
33export function combineMultiFormat<R extends MultiFormat>(
34 values: (R | string)[],
35 transformers = DEFAULT_TRANSFORMERS as Transformers<R>,
67}
68
69export function joinMultiFormat<R extends MultiFormat>(values: (R | string)[], join: R | string) {
70 if (!values.length) {
71 return {
84}
85
86export function normalizeMultiFormat<R extends MultiFormat>(value: R | string | number | boolean | null | undefined) {
87 if (isString(value)) {
88 return { text: value };
94}
95
96export function getMultiFormatValue<R extends MultiFormat, K extends keyof R>(
97 value: R,
98 key: K,
110}
111
112function isString(value: unknown): value is string {
113 return typeof value === "string" || value instanceof String;
114}
115
116function toString(value: unknown) {
117 if (isString(value)) {
118 return value;
124}
125
126export function addStrings(valueA: unknown, valueB: unknown) {
127 if (!(isString(valueA) && isString(valueB))) {
128 return addStrings(
141}
142
143export function wrapHTMLTag(
144 tag: string,
145 text: string | MultiFormatWithHTML,
161}
162
163export function createFormatMethod<R extends MultiFormat>(method: (value: R) => R) {
164 return (
165 strings: TemplateStringsArray,
170}
171
172export function createWrapTagFormatMethod(tag: string, attrs: Record<string, string> = {}) {
173 return createFormatMethod<MultiFormatWithHTML>((value) => {
174 return wrapHTMLTag(tag, value, attrs);
197});
198
199export function ListItem(item: string | MultiFormatWithHTML, i: number | undefined = undefined) {
200 return combineMultiFormat([
201 {
213}
214
215export function OrderedList(items: (string | MultiFormatWithHTML)[]) {
216 return joinMultiFormat([
217 {
233}
234
235export function UnorderedList(items: (string | MultiFormatWithHTML)[]) {
236 return joinMultiFormat([
237 {