aboutsummaryrefslogtreecommitdiff
path: root/util/wrap.ts
blob: d616a2340a764c42f028fcb0a1a6d088838f6724 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
export type Wrapper = [string, string];

/** @summary make Wrapper that starts and ends with `input` */
export function WrapWith(input: string): Wrapper {
	return [input, input];
}

/** @summary make Wrapper that starts and ends with XML tags with name `tagName` */
export function WrapTag(tagName: string): Wrapper {
	return [`<${tagName}>`, `</${tagName}>`];
}

// this type is internal to this file
type WrapType = { [K: string]: Wrapper | WrapType };

export const Wrap = {
	/** @prop (input) */
	parenthesis: ["(", ")"],
	/** @prop [input] */
	bracket: ["[", "]"],
	/** @prop \{input\} */
	brace: ["{", "}"],
	/** @prop HTML-specifics */
	HTML: {
		/** @prop \<b>input\</b> */
		bold: WrapTag("b"),
		/** @prop \<i>input\</i> */
		italic: WrapTag("i"),
		/** @prop \<span>input\</span> */
		span: WrapTag("span"),
		/** @prop \<ruby>input\</ruby> */
		ruby: WrapTag("ruby"),
		/** @prop \<rt>input\</rt> */
		rubyText: WrapTag("rt"),
		/** @prop \<p>input\</p> */
		paragraph: WrapTag("p"),
		/** @prop \<pre>input\</pre> */
		preformatted: WrapTag("pre"),
	},
	/** @prop \*input\* */
	asterisk: WrapWith("*"),
	/** @prop \_input\_ */
	underscore: WrapWith("_"),
} satisfies WrapType;