GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(shared): strip only ASCII space/tab and preserve quote tab residu… · pingdotgg/t3code@bddb24e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/shared/src
    • threadLinks.test.ts
    • threadLinks.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/shared/src/threadLinks.test.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/threadLinks.test.ts
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ describe("thread links", () => {
247247
["", "", ""],
248248
["", " ", ""],
249249
["> ", "> ", "> "],
250+
["> ", ">\t", "> "],
251+
["> ", ">\t ", "> "],
252+
[" > ", " >\t", " > "],
250253
...[1, 2, 3, 4].map((padding) => [
251254
`-${" ".repeat(padding)}`,
252255
" ".repeat(padding + 1),
@@ -283,9 +286,14 @@ describe("thread links", () => {
283286
"-_*",
284287
" ===",
285288
" <!-- comment -->",
289+
"\u00a0<!-- comment -->",
286290
"text <!-- comment -->",
287291
].map((line) => ["Use `example", line]),
288292
["> Use `example", "> <!-- comment -->"],
293+
["> Use `example", ">\u00a0<!-- comment -->"],
294+
["> Use `example", ">\t <!-- comment -->"],
295+
[" > Use `example", " >\t <!-- comment -->"],
296+
["> Use `example", ">\t > <!-- comment -->"],
289297
["> Use `example", "> ---"],
290298
["> Use `example", "==="],
291299
]) {
@@ -296,6 +304,11 @@ describe("thread links", () => {
296304
for (const source of [
297305
"<!-- ` -->\n`<t3-thread://v2/local/t1>`",
298306
"```html\n<!--\n```\n`<t3-thread://v2/local/t1>`",
307+
"```md\n\u00a0```\n<!--\n```\n`<t3-thread://v2/local/t1>`",
308+
"- <!--\n\u00a0\u00a0line\n `<t3-thread://v2/local/t1>`",
309+
"> ```md\n>\t ```\n> <!--\n> ```\n> `<t3-thread://v2/local/t1>`",
310+
"> - ```md\n>\tline\n> <!--\n> ```\n> `<t3-thread://v2/local/t1>`",
311+
"> Use `example\n>\t <!-- comment -->\n> <t3-thread://v2/local/t1> end`",
299312
"-\tNote `\n <!-- comment -->\n <t3-thread://v2/local/t1> `",
300313
"- Note `\n <!-- comment -->\n <t3-thread://v2/local/t1> `",
301314
"- - Note `\n <!-- comment -->\n <t3-thread://v2/local/t1> `",
Collapse file

‎packages/shared/src/threadLinks.ts‎

Copy file name to clipboardExpand all lines: packages/shared/src/threadLinks.ts
+33-17Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const SPAN_BREAK_LINE =
3939
/[ \t>]*(?:\r?$|#{1,6}(?:[ \t]|\r?$)|(?:[-*+]|\d{1,9}[.)])[ \t]|`{3,}[^`\r\n]*\r?$|~{3,})/my;
4040
const LINE_PREFIX = /([ \t]*)(>|(?:[-*+]|\d{1,9}[.)])[ \t]+)?/y;
4141
const QUOTE_CONTINUATION = /([ \t]*)>/y;
42+
const LEADING_SPACE = /^[ \t]*/;
4243
const THEMATIC_BREAK = /^(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})\r?$/;
4344
const SETEXT_UNDERLINE = /^(?:-+|=+)[ \t]*\r?$/;
4445
const FENCE_OPENER = /^(`{3,}(?=[^`\r\n]*\r?$)|~{3,})/;
@@ -84,24 +85,32 @@ function columnWidth(text: string, start = 0): number {
8485
function blockContinuation(line: string, block: ContainerBlock) {
8586
let offset = 0;
8687
let column = 0;
88+
let carriedIndent = 0;
8789
for (let d = 0; d < block.depth; d++) {
8890
QUOTE_CONTINUATION.lastIndex = offset;
8991
const match = QUOTE_CONTINUATION.exec(line);
9092
if (match === null) return null;
91-
const indent = columnWidth(match[1]!, column);
93+
const prefixIndent = columnWidth(match[1]!, column);
94+
const indent = carriedIndent + prefixIndent;
9295
const required = block.indents[d] ?? 0;
9396
if (indent < required || indent - required > 3) return null;
9497
offset = QUOTE_CONTINUATION.lastIndex;
95-
column += indent + 1;
98+
column += prefixIndent + 1;
99+
carriedIndent = 0;
96100
if (line[offset] === " " || line[offset] === "\t") {
97-
column += columnWidth(line[offset]!, column);
101+
const spaceWidth = columnWidth(line[offset]!, column);
102+
column += spaceWidth;
103+
carriedIndent = spaceWidth - 1;
98104
offset++;
99105
}
100106
}
101107
const rest = line.slice(offset);
102-
const text = rest.trimStart();
103-
const indent = columnWidth(rest.slice(0, rest.length - text.length), column);
104-
return text === "" || indent >= (block.indents[block.depth] ?? 0) ? { rest, indent } : null;
108+
const leading = LEADING_SPACE.exec(rest)![0];
109+
const text = rest.slice(leading.length);
110+
const indent = carriedIndent + columnWidth(leading, column);
111+
return text === "" || text === "\r" || indent >= (block.indents[block.depth] ?? 0)
112+
? { rest, text, indent }
113+
: null;
105114
}
106115

107116
function codeSpanLines(markdown: string) {
@@ -119,7 +128,7 @@ function codeSpanLines(markdown: string) {
119128
if (block !== undefined) {
120129
const continuation = blockContinuation(line, block);
121130
if (continuation !== null) {
122-
const { rest, indent } = continuation;
131+
const { rest, text, indent } = continuation;
123132
lines.push({
124133
start,
125134
depth: block.depth,
@@ -129,13 +138,12 @@ function codeSpanLines(markdown: string) {
129138
if (block.kind === "html") {
130139
if (block.closer.test(rest)) block = undefined;
131140
} else {
132-
const restText = rest.trimStart();
133141
const required = block.indents[block.depth] ?? 0;
134142
const closer = block.char === "`" ? BACKTICK_FENCE_CLOSER : TILDE_FENCE_CLOSER;
135143
if (
136144
indent - required <= 3 &&
137-
closer.test(restText) &&
138-
restText.startsWith(block.char.repeat(block.length))
145+
closer.test(text) &&
146+
text.startsWith(block.char.repeat(block.length))
139147
) {
140148
block = undefined;
141149
}
@@ -148,6 +156,7 @@ function codeSpanLines(markdown: string) {
148156
}
149157
let offset = 0;
150158
let column = 0;
159+
let carriedIndent = 0;
151160
let depth = 0;
152161
let hasList = false;
153162
let listOffset = 0;
@@ -156,12 +165,13 @@ function codeSpanLines(markdown: string) {
156165
LINE_PREFIX.lastIndex = offset;
157166
const prefix = LINE_PREFIX.exec(line);
158167
if (prefix === null) break;
159-
const indent = columnWidth(prefix[1]!, column);
168+
const prefixIndent = columnWidth(prefix[1]!, column);
169+
const indent = carriedIndent + prefixIndent;
160170
if (
161171
listOffset === 0 &&
162172
paragraphDepth === undefined &&
163173
indent < (listIndents[depth] ?? 0) &&
164-
line.trim()
174+
!/^[ \t]*\r?$/.test(line)
165175
) {
166176
listIndents.length = depth;
167177
}
@@ -175,21 +185,27 @@ function codeSpanLines(markdown: string) {
175185
depth++;
176186
listOffset = 0;
177187
listTailSpace = 0;
188+
carriedIndent = 0;
178189
if (line[offset] === " " || line[offset] === "\t") {
179-
column += columnWidth(line[offset]!, column);
190+
const spaceWidth = columnWidth(line[offset]!, column);
191+
column += spaceWidth;
192+
carriedIndent = spaceWidth - 1;
180193
offset++;
181194
}
182195
} else {
183-
listTailSpace = width - indent - prefix[2]!.trimEnd().length;
184-
listOffset += listTailSpace > 4 ? width - listTailSpace + 1 : width;
196+
const markerWidth = carriedIndent + width;
197+
listTailSpace = width - prefixIndent - prefix[2]!.trimEnd().length;
198+
listOffset += listTailSpace > 4 ? markerWidth - listTailSpace + 1 : markerWidth;
185199
listIndents[depth] = listOffset;
186200
hasList = true;
201+
carriedIndent = 0;
187202
if (listTailSpace > 4) break;
188203
}
189204
}
190205
const content = line.slice(offset);
191-
const text = content.trimStart();
192-
const indent = columnWidth(content.slice(0, content.length - text.length), column);
206+
const leading = LEADING_SPACE.exec(content)![0];
207+
const text = content.slice(leading.length);
208+
const indent = carriedIndent + columnWidth(leading, column);
193209
const containerIndent = hasList ? 0 : (listIndents[depth] ?? 0);
194210
const lazy = indent < containerIndent || depth < (paragraphDepth ?? 0);
195211
const nonCodeIndent =

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.