1 |
|
2 | import defineFunction from "../defineFunction";
|
3 | import buildCommon from "../buildCommon";
|
4 | import mathMLTree from "../mathMLTree";
|
5 | import ParseError from "../ParseError";
|
6 |
|
7 | import type {ParseNode} from "../parseNode";
|
8 |
|
9 | defineFunction({
|
10 | type: "verb",
|
11 | names: ["\\verb"],
|
12 | props: {
|
13 | numArgs: 0,
|
14 | allowedInText: true,
|
15 | },
|
16 | handler(context, args, optArgs) {
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | throw new ParseError(
|
22 | "\\verb ended by end of line instead of matching delimiter");
|
23 | },
|
24 | htmlBuilder(group, options) {
|
25 | const text = makeVerb(group);
|
26 | const body = [];
|
27 |
|
28 | const newOptions = options.havingStyle(options.style.text());
|
29 | for (let i = 0; i < text.length; i++) {
|
30 | let c = text[i];
|
31 | if (c === '~') {
|
32 | c = '\\textasciitilde';
|
33 | }
|
34 | body.push(buildCommon.makeSymbol(c, "Typewriter-Regular",
|
35 | group.mode, newOptions, ["mord", "texttt"]));
|
36 | }
|
37 | return buildCommon.makeSpan(
|
38 | ["mord", "text"].concat(newOptions.sizingClasses(options)),
|
39 | buildCommon.tryCombineChars(body),
|
40 | newOptions,
|
41 | );
|
42 | },
|
43 | mathmlBuilder(group, options) {
|
44 | const text = new mathMLTree.TextNode(makeVerb(group));
|
45 | const node = new mathMLTree.MathNode("mtext", [text]);
|
46 | node.setAttribute("mathvariant", "monospace");
|
47 | return node;
|
48 | },
|
49 | });
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | const makeVerb = (group: ParseNode<"verb">): string =>
|
58 | group.body.replace(/ /g, group.star ? '\u2423' : '\xA0');
|