The best way to control Claude Code, Codex and more from any computer or phone

main
patch 146 lines 4.22 KB
Raw
1 diff --git a/dev/lib/syntax.js b/dev/lib/syntax.js
2 --- a/dev/lib/syntax.js
3 +++ b/dev/lib/syntax.js
4 @@ -46,6 +46,10 @@
5 let sizeB = 0
6 /** @type {boolean | undefined} */
7 let seen
8 + let mathEnd = 0
9 + let afterMath
10 + let literalRow = -1
11 + let literalRanges = []
12
13 return start
14
15 @@ -223,6 +227,21 @@
16 * @type {State}
17 */
18 function headRowData(code) {
19 + const construct = (self.parser.constructs.text[code] || []).find(
20 + (entry) => entry.name === 'mathText' || entry.name === 'mathTexText'
21 + )
22 + if (construct && (!construct.previous || construct.previous.call(self, self.previous))) {
23 + afterMath = headRowData
24 + return effects.check({tokenize: checkMath}, mathData, ordinaryData)(code)
25 + }
26 + return ordinaryData(code)
27 +
28 + function ordinaryData(code) {
29 + return headRowDataOrdinary(code)
30 + }
31 + }
32 +
33 + function headRowDataOrdinary(code) {
34 if (
35 code === codes.eof ||
36 code === codes.verticalBar ||
37 @@ -585,6 +604,21 @@
38 * @type {State}
39 */
40 function bodyRowData(code) {
41 + const construct = (self.parser.constructs.text[code] || []).find(
42 + (entry) => entry.name === 'mathText' || entry.name === 'mathTexText'
43 + )
44 + if (construct && (!construct.previous || construct.previous.call(self, self.previous))) {
45 + afterMath = bodyRowData
46 + return effects.check({tokenize: checkMath}, mathData, ordinaryData)(code)
47 + }
48 + return ordinaryData(code)
49 +
50 + function ordinaryData(code) {
51 + return bodyRowDataOrdinary(code)
52 + }
53 + }
54 +
55 + function bodyRowDataOrdinary(code) {
56 if (
57 code === codes.eof ||
58 code === codes.verticalBar ||
59 @@ -618,6 +652,75 @@
60
61 return bodyRowData(code)
62 }
63 + function checkMath(effects, ok, nok) {
64 + const context = this
65 + const startLine = context.now().line
66 + const mathStart = context.now().offset
67 + const row = self.events.findLast(
68 + (event) => event[0] === 'enter' && event[1].type === 'tableRow'
69 + )[1]
70 + return startMath
71 +
72 + function startMath(code) {
73 + const construct = context.parser.constructs.text[code].find(
74 + (entry) => entry.name === 'mathText' || entry.name === 'mathTexText'
75 + )
76 + const inlineContext = Object.create(context)
77 + inlineContext.mathSingleLine = true
78 + return effects.attempt({
79 + partial: true,
80 + tokenize: (effects, ok, nok) => construct.tokenize.call(inlineContext, effects, ok, nok)
81 + }, done, nok)(code)
82 + }
83 +
84 + function done(code) {
85 + if (context.now().line !== startLine) return nok(code)
86 + mathEnd = context.now().offset
87 + if (literalRow === row.start.offset) return acceptMath(code)
88 + if (code === codes.eof || markdownLineEnding(code)) return inspectRow(code)
89 + effects.enter(types.data)
90 + return rowEnd(code)
91 + }
92 +
93 + function rowEnd(code) {
94 + if (code !== codes.eof && !markdownLineEnding(code)) {
95 + effects.consume(code)
96 + return rowEnd
97 + }
98 + effects.exit(types.data)
99 + return inspectRow(code)
100 + }
101 +
102 + function inspectRow(code) {
103 + // Inline parsing owns destinations, code, autolinks and tag attributes.
104 + const events = context.parser.text(row.start).write([
105 + ...context.sliceStream({start: row.start, end: context.now()}),
106 + codes.eof
107 + ])
108 + literalRanges = events.flatMap(([kind, token]) =>
109 + kind === 'enter' &&
110 + (token.type === 'resource' || token.type === 'codeText' ||
111 + token.type === 'autolink' || token.type === 'htmlText')
112 + ? [[token.start.offset, token.end.offset]]
113 + : []
114 + )
115 + literalRow = row.start.offset
116 + return acceptMath(code)
117 + }
118 +
119 + function acceptMath(code) {
120 + return literalRanges.some(([start, end]) => start <= mathStart && mathStart < end)
121 + ? nok(code)
122 + : ok(code)
123 + }
124 + }
125 +
126 + function mathData(code) {
127 + if (self.now().offset >= mathEnd) return afterMath(code)
128 + effects.consume(code)
129 + return mathData
130 + }
131 +
132 }
133
134 /** @type {Resolver} */
135 diff --git a/package.json b/package.json
136 --- a/package.json
137 +++ b/package.json
138 @@ -27,7 +27,7 @@
139 },
140 "exports": {
141 "development": "./dev/index.js",
142 - "default": "./index.js"
143 + "default": "./dev/index.js"
144 },
145 "files": [
146 "dev/",