@opentui/core 0.1.84 → 0.1.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/3d.js +1 -1
- package/{index-qr7b6cvh.js → index-2yz42vd4.js} +47 -5
- package/{index-qr7b6cvh.js.map → index-2yz42vd4.js.map} +5 -4
- package/index.js +220 -150
- package/index.js.map +5 -5
- package/lib/detect-links.d.ts +6 -0
- package/lib/index.d.ts +1 -0
- package/package.json +7 -7
- package/renderables/Code.d.ts +11 -1
- package/renderables/Markdown.d.ts +27 -8
- package/testing.js +1 -1
package/index.js
CHANGED
|
@@ -78,6 +78,7 @@ import {
|
|
|
78
78
|
cyan,
|
|
79
79
|
defaultKeyAliases,
|
|
80
80
|
delegate,
|
|
81
|
+
detectLinks,
|
|
81
82
|
dim,
|
|
82
83
|
env,
|
|
83
84
|
envRegistry,
|
|
@@ -153,7 +154,7 @@ import {
|
|
|
153
154
|
white,
|
|
154
155
|
wrapWithDelegates,
|
|
155
156
|
yellow
|
|
156
|
-
} from "./index-
|
|
157
|
+
} from "./index-2yz42vd4.js";
|
|
157
158
|
// src/text-buffer-view.ts
|
|
158
159
|
class TextBufferView {
|
|
159
160
|
lib;
|
|
@@ -3115,6 +3116,7 @@ class CodeRenderable extends TextBufferRenderable {
|
|
|
3115
3116
|
_hadInitialContent = false;
|
|
3116
3117
|
_lastHighlights = [];
|
|
3117
3118
|
_onHighlight;
|
|
3119
|
+
_onChunks;
|
|
3118
3120
|
_contentDefaultOptions = {
|
|
3119
3121
|
content: "",
|
|
3120
3122
|
conceal: true,
|
|
@@ -3131,6 +3133,7 @@ class CodeRenderable extends TextBufferRenderable {
|
|
|
3131
3133
|
this._drawUnstyledText = options.drawUnstyledText ?? this._contentDefaultOptions.drawUnstyledText;
|
|
3132
3134
|
this._streaming = options.streaming ?? this._contentDefaultOptions.streaming;
|
|
3133
3135
|
this._onHighlight = options.onHighlight;
|
|
3136
|
+
this._onChunks = options.onChunks;
|
|
3134
3137
|
if (this._content.length > 0) {
|
|
3135
3138
|
this.textBuffer.setText(this._content);
|
|
3136
3139
|
this.updateTextInfo();
|
|
@@ -3218,9 +3221,24 @@ class CodeRenderable extends TextBufferRenderable {
|
|
|
3218
3221
|
this._highlightsDirty = true;
|
|
3219
3222
|
}
|
|
3220
3223
|
}
|
|
3224
|
+
get onChunks() {
|
|
3225
|
+
return this._onChunks;
|
|
3226
|
+
}
|
|
3227
|
+
set onChunks(value) {
|
|
3228
|
+
if (this._onChunks !== value) {
|
|
3229
|
+
this._onChunks = value;
|
|
3230
|
+
this._highlightsDirty = true;
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3221
3233
|
get isHighlighting() {
|
|
3222
3234
|
return this._isHighlighting;
|
|
3223
3235
|
}
|
|
3236
|
+
async transformChunks(chunks, context) {
|
|
3237
|
+
if (!this._onChunks)
|
|
3238
|
+
return chunks;
|
|
3239
|
+
const modified = await this._onChunks(chunks, context);
|
|
3240
|
+
return modified ?? chunks;
|
|
3241
|
+
}
|
|
3224
3242
|
ensureVisibleTextBeforeHighlight() {
|
|
3225
3243
|
if (this.isDestroyed)
|
|
3226
3244
|
return;
|
|
@@ -3279,9 +3297,23 @@ class CodeRenderable extends TextBufferRenderable {
|
|
|
3279
3297
|
if (this._streaming) {
|
|
3280
3298
|
this._lastHighlights = highlights;
|
|
3281
3299
|
}
|
|
3282
|
-
|
|
3300
|
+
}
|
|
3301
|
+
if (highlights.length > 0 || this._onChunks) {
|
|
3302
|
+
const context = {
|
|
3303
|
+
content,
|
|
3304
|
+
filetype,
|
|
3305
|
+
syntaxStyle: this._syntaxStyle,
|
|
3306
|
+
highlights
|
|
3307
|
+
};
|
|
3308
|
+
let chunks = treeSitterToTextChunks(content, highlights, this._syntaxStyle, {
|
|
3283
3309
|
enabled: this._conceal
|
|
3284
3310
|
});
|
|
3311
|
+
chunks = await this.transformChunks(chunks, context);
|
|
3312
|
+
if (snapshotId !== this._highlightSnapshotId) {
|
|
3313
|
+
return;
|
|
3314
|
+
}
|
|
3315
|
+
if (this.isDestroyed)
|
|
3316
|
+
return;
|
|
3285
3317
|
const styledText = new StyledText(chunks);
|
|
3286
3318
|
this.textBuffer.setStyledText(styledText);
|
|
3287
3319
|
} else {
|
|
@@ -8852,15 +8884,23 @@ function parseMarkdownIncremental(newContent, prevState, trailingUnstable = 2) {
|
|
|
8852
8884
|
const newTokens = x.lex(remainingContent, { gfm: true });
|
|
8853
8885
|
return { content: newContent, tokens: [...stableTokens, ...newTokens] };
|
|
8854
8886
|
} catch {
|
|
8855
|
-
|
|
8887
|
+
try {
|
|
8888
|
+
const fullTokens = x.lex(newContent, { gfm: true });
|
|
8889
|
+
return { content: newContent, tokens: fullTokens };
|
|
8890
|
+
} catch {
|
|
8891
|
+
return { content: newContent, tokens: [] };
|
|
8892
|
+
}
|
|
8856
8893
|
}
|
|
8857
8894
|
}
|
|
8858
8895
|
|
|
8859
8896
|
// src/renderables/Markdown.ts
|
|
8897
|
+
var TRAILING_MARKDOWN_BLOCK_BREAKS_RE = /(?:\r?\n){2,}$/;
|
|
8898
|
+
|
|
8860
8899
|
class MarkdownRenderable extends Renderable {
|
|
8861
8900
|
_content = "";
|
|
8862
8901
|
_syntaxStyle;
|
|
8863
8902
|
_conceal;
|
|
8903
|
+
_concealCode;
|
|
8864
8904
|
_treeSitterClient;
|
|
8865
8905
|
_tableOptions;
|
|
8866
8906
|
_renderNode;
|
|
@@ -8868,9 +8908,14 @@ class MarkdownRenderable extends Renderable {
|
|
|
8868
8908
|
_streaming = false;
|
|
8869
8909
|
_blockStates = [];
|
|
8870
8910
|
_styleDirty = false;
|
|
8911
|
+
_linkifyMarkdownChunks = (chunks, context) => detectLinks(chunks, {
|
|
8912
|
+
content: context.content,
|
|
8913
|
+
highlights: context.highlights
|
|
8914
|
+
});
|
|
8871
8915
|
_contentDefaultOptions = {
|
|
8872
8916
|
content: "",
|
|
8873
8917
|
conceal: true,
|
|
8918
|
+
concealCode: false,
|
|
8874
8919
|
streaming: false
|
|
8875
8920
|
};
|
|
8876
8921
|
constructor(ctx, options) {
|
|
@@ -8881,6 +8926,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
8881
8926
|
});
|
|
8882
8927
|
this._syntaxStyle = options.syntaxStyle;
|
|
8883
8928
|
this._conceal = options.conceal ?? this._contentDefaultOptions.conceal;
|
|
8929
|
+
this._concealCode = options.concealCode ?? this._contentDefaultOptions.concealCode;
|
|
8884
8930
|
this._content = options.content ?? this._contentDefaultOptions.content;
|
|
8885
8931
|
this._treeSitterClient = options.treeSitterClient;
|
|
8886
8932
|
this._tableOptions = options.tableOptions;
|
|
@@ -8892,6 +8938,8 @@ class MarkdownRenderable extends Renderable {
|
|
|
8892
8938
|
return this._content;
|
|
8893
8939
|
}
|
|
8894
8940
|
set content(value) {
|
|
8941
|
+
if (this.isDestroyed)
|
|
8942
|
+
return;
|
|
8895
8943
|
if (this._content !== value) {
|
|
8896
8944
|
this._content = value;
|
|
8897
8945
|
this.updateBlocks();
|
|
@@ -8916,13 +8964,24 @@ class MarkdownRenderable extends Renderable {
|
|
|
8916
8964
|
this._styleDirty = true;
|
|
8917
8965
|
}
|
|
8918
8966
|
}
|
|
8967
|
+
get concealCode() {
|
|
8968
|
+
return this._concealCode;
|
|
8969
|
+
}
|
|
8970
|
+
set concealCode(value) {
|
|
8971
|
+
if (this._concealCode !== value) {
|
|
8972
|
+
this._concealCode = value;
|
|
8973
|
+
this._styleDirty = true;
|
|
8974
|
+
}
|
|
8975
|
+
}
|
|
8919
8976
|
get streaming() {
|
|
8920
8977
|
return this._streaming;
|
|
8921
8978
|
}
|
|
8922
8979
|
set streaming(value) {
|
|
8980
|
+
if (this.isDestroyed)
|
|
8981
|
+
return;
|
|
8923
8982
|
if (this._streaming !== value) {
|
|
8924
8983
|
this._streaming = value;
|
|
8925
|
-
this.
|
|
8984
|
+
this.updateBlocks(true);
|
|
8926
8985
|
}
|
|
8927
8986
|
}
|
|
8928
8987
|
get tableOptions() {
|
|
@@ -9084,92 +9143,17 @@ class MarkdownRenderable extends Renderable {
|
|
|
9084
9143
|
break;
|
|
9085
9144
|
}
|
|
9086
9145
|
}
|
|
9087
|
-
|
|
9088
|
-
|
|
9089
|
-
const group = `markup.heading.${token.depth}`;
|
|
9090
|
-
const marker = "#".repeat(token.depth) + " ";
|
|
9091
|
-
if (!this._conceal) {
|
|
9092
|
-
chunks.push(this.createChunk(marker, group));
|
|
9093
|
-
}
|
|
9094
|
-
for (const child of token.tokens) {
|
|
9095
|
-
this.renderInlineTokenWithStyle(child, chunks, group);
|
|
9096
|
-
}
|
|
9097
|
-
return chunks;
|
|
9098
|
-
}
|
|
9099
|
-
renderParagraphChunks(token) {
|
|
9100
|
-
const chunks = [];
|
|
9101
|
-
this.renderInlineContent(token.tokens, chunks);
|
|
9102
|
-
return chunks;
|
|
9103
|
-
}
|
|
9104
|
-
renderBlockquoteChunks(token) {
|
|
9105
|
-
const chunks = [];
|
|
9106
|
-
for (const child of token.tokens) {
|
|
9107
|
-
chunks.push(this.createChunk("> ", "punctuation.special"));
|
|
9108
|
-
const childChunks = this.renderTokenToChunks(child);
|
|
9109
|
-
chunks.push(...childChunks);
|
|
9110
|
-
chunks.push(this.createDefaultChunk(`
|
|
9111
|
-
`));
|
|
9112
|
-
}
|
|
9113
|
-
return chunks;
|
|
9114
|
-
}
|
|
9115
|
-
renderListChunks(token) {
|
|
9116
|
-
const chunks = [];
|
|
9117
|
-
let index = typeof token.start === "number" ? token.start : 1;
|
|
9118
|
-
for (const item of token.items) {
|
|
9119
|
-
if (token.ordered) {
|
|
9120
|
-
chunks.push(this.createChunk(`${index}. `, "markup.list"));
|
|
9121
|
-
index++;
|
|
9122
|
-
} else {
|
|
9123
|
-
chunks.push(this.createChunk("- ", "markup.list"));
|
|
9124
|
-
}
|
|
9125
|
-
for (let i = 0;i < item.tokens.length; i++) {
|
|
9126
|
-
const child = item.tokens[i];
|
|
9127
|
-
if (child.type === "text" && i === 0 && "tokens" in child && child.tokens) {
|
|
9128
|
-
this.renderInlineContent(child.tokens, chunks);
|
|
9129
|
-
chunks.push(this.createDefaultChunk(`
|
|
9130
|
-
`));
|
|
9131
|
-
} else if (child.type === "paragraph" && i === 0) {
|
|
9132
|
-
this.renderInlineContent(child.tokens, chunks);
|
|
9133
|
-
chunks.push(this.createDefaultChunk(`
|
|
9134
|
-
`));
|
|
9135
|
-
} else {
|
|
9136
|
-
const childChunks = this.renderTokenToChunks(child);
|
|
9137
|
-
chunks.push(...childChunks);
|
|
9138
|
-
chunks.push(this.createDefaultChunk(`
|
|
9139
|
-
`));
|
|
9140
|
-
}
|
|
9141
|
-
}
|
|
9142
|
-
}
|
|
9143
|
-
return chunks;
|
|
9144
|
-
}
|
|
9145
|
-
renderThematicBreakChunks() {
|
|
9146
|
-
return [this.createChunk("---", "punctuation.special")];
|
|
9147
|
-
}
|
|
9148
|
-
renderTokenToChunks(token) {
|
|
9149
|
-
switch (token.type) {
|
|
9150
|
-
case "heading":
|
|
9151
|
-
return this.renderHeadingChunks(token);
|
|
9152
|
-
case "paragraph":
|
|
9153
|
-
return this.renderParagraphChunks(token);
|
|
9154
|
-
case "blockquote":
|
|
9155
|
-
return this.renderBlockquoteChunks(token);
|
|
9156
|
-
case "list":
|
|
9157
|
-
return this.renderListChunks(token);
|
|
9158
|
-
case "hr":
|
|
9159
|
-
return this.renderThematicBreakChunks();
|
|
9160
|
-
case "space":
|
|
9161
|
-
return [];
|
|
9162
|
-
default:
|
|
9163
|
-
if ("raw" in token && token.raw) {
|
|
9164
|
-
return [this.createDefaultChunk(token.raw)];
|
|
9165
|
-
}
|
|
9166
|
-
return [];
|
|
9167
|
-
}
|
|
9168
|
-
}
|
|
9169
|
-
createTextRenderable(chunks, id, marginBottom = 0) {
|
|
9170
|
-
return new TextRenderable(this.ctx, {
|
|
9146
|
+
createMarkdownCodeRenderable(content, id, marginBottom = 0) {
|
|
9147
|
+
return new CodeRenderable(this.ctx, {
|
|
9171
9148
|
id,
|
|
9172
|
-
content
|
|
9149
|
+
content,
|
|
9150
|
+
filetype: "markdown",
|
|
9151
|
+
syntaxStyle: this._syntaxStyle,
|
|
9152
|
+
conceal: this._conceal,
|
|
9153
|
+
drawUnstyledText: false,
|
|
9154
|
+
streaming: true,
|
|
9155
|
+
onChunks: this._linkifyMarkdownChunks,
|
|
9156
|
+
treeSitterClient: this._treeSitterClient,
|
|
9173
9157
|
width: "100%",
|
|
9174
9158
|
marginBottom
|
|
9175
9159
|
});
|
|
@@ -9180,14 +9164,95 @@ class MarkdownRenderable extends Renderable {
|
|
|
9180
9164
|
content: token.text,
|
|
9181
9165
|
filetype: token.lang || undefined,
|
|
9182
9166
|
syntaxStyle: this._syntaxStyle,
|
|
9183
|
-
conceal: this.
|
|
9167
|
+
conceal: this._concealCode,
|
|
9168
|
+
drawUnstyledText: !(this._streaming && this._concealCode),
|
|
9169
|
+
streaming: this._streaming,
|
|
9184
9170
|
treeSitterClient: this._treeSitterClient,
|
|
9185
9171
|
width: "100%",
|
|
9186
9172
|
marginBottom
|
|
9187
9173
|
});
|
|
9188
9174
|
}
|
|
9175
|
+
applyMarkdownCodeRenderable(renderable, content, marginBottom) {
|
|
9176
|
+
renderable.content = content;
|
|
9177
|
+
renderable.filetype = "markdown";
|
|
9178
|
+
renderable.syntaxStyle = this._syntaxStyle;
|
|
9179
|
+
renderable.conceal = this._conceal;
|
|
9180
|
+
renderable.drawUnstyledText = false;
|
|
9181
|
+
renderable.streaming = true;
|
|
9182
|
+
renderable.marginBottom = marginBottom;
|
|
9183
|
+
}
|
|
9184
|
+
applyCodeBlockRenderable(renderable, token, marginBottom) {
|
|
9185
|
+
renderable.content = token.text;
|
|
9186
|
+
renderable.filetype = token.lang || undefined;
|
|
9187
|
+
renderable.syntaxStyle = this._syntaxStyle;
|
|
9188
|
+
renderable.conceal = this._concealCode;
|
|
9189
|
+
renderable.drawUnstyledText = !(this._streaming && this._concealCode);
|
|
9190
|
+
renderable.streaming = this._streaming;
|
|
9191
|
+
renderable.marginBottom = marginBottom;
|
|
9192
|
+
}
|
|
9193
|
+
shouldRenderSeparately(token) {
|
|
9194
|
+
return token.type === "code" || token.type === "table" || token.type === "blockquote";
|
|
9195
|
+
}
|
|
9196
|
+
getInterBlockMargin(token, hasNextToken) {
|
|
9197
|
+
if (!hasNextToken)
|
|
9198
|
+
return 0;
|
|
9199
|
+
return this.shouldRenderSeparately(token) ? 1 : 0;
|
|
9200
|
+
}
|
|
9201
|
+
createMarkdownBlockToken(raw) {
|
|
9202
|
+
return {
|
|
9203
|
+
type: "paragraph",
|
|
9204
|
+
raw,
|
|
9205
|
+
text: raw,
|
|
9206
|
+
tokens: []
|
|
9207
|
+
};
|
|
9208
|
+
}
|
|
9209
|
+
normalizeMarkdownBlockRaw(raw) {
|
|
9210
|
+
return raw.replace(TRAILING_MARKDOWN_BLOCK_BREAKS_RE, `
|
|
9211
|
+
`);
|
|
9212
|
+
}
|
|
9213
|
+
buildRenderableTokens(tokens) {
|
|
9214
|
+
if (this._renderNode) {
|
|
9215
|
+
return tokens.filter((token) => token.type !== "space");
|
|
9216
|
+
}
|
|
9217
|
+
const renderTokens = [];
|
|
9218
|
+
let markdownRaw = "";
|
|
9219
|
+
const flushMarkdownRaw = () => {
|
|
9220
|
+
if (markdownRaw.length === 0)
|
|
9221
|
+
return;
|
|
9222
|
+
const normalizedRaw = this.normalizeMarkdownBlockRaw(markdownRaw);
|
|
9223
|
+
if (normalizedRaw.length > 0) {
|
|
9224
|
+
renderTokens.push(this.createMarkdownBlockToken(normalizedRaw));
|
|
9225
|
+
}
|
|
9226
|
+
markdownRaw = "";
|
|
9227
|
+
};
|
|
9228
|
+
for (let i = 0;i < tokens.length; i += 1) {
|
|
9229
|
+
const token = tokens[i];
|
|
9230
|
+
if (token.type === "space") {
|
|
9231
|
+
if (markdownRaw.length === 0) {
|
|
9232
|
+
continue;
|
|
9233
|
+
}
|
|
9234
|
+
let nextIndex = i + 1;
|
|
9235
|
+
while (nextIndex < tokens.length && tokens[nextIndex].type === "space") {
|
|
9236
|
+
nextIndex += 1;
|
|
9237
|
+
}
|
|
9238
|
+
const nextToken = tokens[nextIndex];
|
|
9239
|
+
if (nextToken && !this.shouldRenderSeparately(nextToken)) {
|
|
9240
|
+
markdownRaw += token.raw;
|
|
9241
|
+
}
|
|
9242
|
+
continue;
|
|
9243
|
+
}
|
|
9244
|
+
if (this.shouldRenderSeparately(token)) {
|
|
9245
|
+
flushMarkdownRaw();
|
|
9246
|
+
renderTokens.push(token);
|
|
9247
|
+
continue;
|
|
9248
|
+
}
|
|
9249
|
+
markdownRaw += token.raw;
|
|
9250
|
+
}
|
|
9251
|
+
flushMarkdownRaw();
|
|
9252
|
+
return renderTokens;
|
|
9253
|
+
}
|
|
9189
9254
|
getTableRowsToRender(table) {
|
|
9190
|
-
return
|
|
9255
|
+
return table.rows;
|
|
9191
9256
|
}
|
|
9192
9257
|
hashString(value, seed) {
|
|
9193
9258
|
let hash = seed >>> 0;
|
|
@@ -9370,7 +9435,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9370
9435
|
const { cache } = this.buildTableContentCache(table, previousCache, forceRegenerate);
|
|
9371
9436
|
if (!cache) {
|
|
9372
9437
|
return {
|
|
9373
|
-
renderable: this.
|
|
9438
|
+
renderable: this.createMarkdownCodeRenderable(table.raw, id, marginBottom)
|
|
9374
9439
|
};
|
|
9375
9440
|
}
|
|
9376
9441
|
return {
|
|
@@ -9380,7 +9445,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9380
9445
|
}
|
|
9381
9446
|
createDefaultRenderable(token, index, hasNextToken = false) {
|
|
9382
9447
|
const id = `${this.id}-block-${index}`;
|
|
9383
|
-
const marginBottom = hasNextToken
|
|
9448
|
+
const marginBottom = this.getInterBlockMargin(token, hasNextToken);
|
|
9384
9449
|
if (token.type === "code") {
|
|
9385
9450
|
return this.createCodeRenderable(token, id, marginBottom);
|
|
9386
9451
|
}
|
|
@@ -9390,39 +9455,28 @@ class MarkdownRenderable extends Renderable {
|
|
|
9390
9455
|
if (token.type === "space") {
|
|
9391
9456
|
return null;
|
|
9392
9457
|
}
|
|
9393
|
-
|
|
9394
|
-
if (chunks.length === 0) {
|
|
9458
|
+
if (!token.raw) {
|
|
9395
9459
|
return null;
|
|
9396
9460
|
}
|
|
9397
|
-
return this.
|
|
9461
|
+
return this.createMarkdownCodeRenderable(token.raw, id, marginBottom);
|
|
9398
9462
|
}
|
|
9399
9463
|
updateBlockRenderable(state, token, index, hasNextToken) {
|
|
9400
|
-
const marginBottom = hasNextToken
|
|
9464
|
+
const marginBottom = this.getInterBlockMargin(token, hasNextToken);
|
|
9401
9465
|
if (token.type === "code") {
|
|
9402
|
-
|
|
9403
|
-
const codeToken = token;
|
|
9404
|
-
codeRenderable.content = codeToken.text;
|
|
9405
|
-
if (codeToken.lang) {
|
|
9406
|
-
codeRenderable.filetype = codeToken.lang;
|
|
9407
|
-
}
|
|
9408
|
-
codeRenderable.marginBottom = marginBottom;
|
|
9466
|
+
this.applyCodeBlockRenderable(state.renderable, token, marginBottom);
|
|
9409
9467
|
return;
|
|
9410
9468
|
}
|
|
9411
9469
|
if (token.type === "table") {
|
|
9412
9470
|
const tableToken = token;
|
|
9413
9471
|
const { cache, changed } = this.buildTableContentCache(tableToken, state.tableContentCache);
|
|
9414
9472
|
if (!cache) {
|
|
9415
|
-
|
|
9416
|
-
|
|
9417
|
-
if (state.tokenRaw !== tableToken.raw) {
|
|
9418
|
-
state.renderable.content = new StyledText(fallbackChunks);
|
|
9419
|
-
}
|
|
9420
|
-
state.renderable.marginBottom = marginBottom;
|
|
9473
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
9474
|
+
this.applyMarkdownCodeRenderable(state.renderable, tableToken.raw, marginBottom);
|
|
9421
9475
|
state.tableContentCache = undefined;
|
|
9422
9476
|
return;
|
|
9423
9477
|
}
|
|
9424
9478
|
state.renderable.destroyRecursively();
|
|
9425
|
-
const fallbackRenderable = this.
|
|
9479
|
+
const fallbackRenderable = this.createMarkdownCodeRenderable(tableToken.raw, `${this.id}-block-${index}`, marginBottom);
|
|
9426
9480
|
this.add(fallbackRenderable);
|
|
9427
9481
|
state.renderable = fallbackRenderable;
|
|
9428
9482
|
state.tableContentCache = undefined;
|
|
@@ -9444,12 +9498,18 @@ class MarkdownRenderable extends Renderable {
|
|
|
9444
9498
|
state.tableContentCache = cache;
|
|
9445
9499
|
return;
|
|
9446
9500
|
}
|
|
9447
|
-
|
|
9448
|
-
|
|
9449
|
-
|
|
9450
|
-
|
|
9501
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
9502
|
+
this.applyMarkdownCodeRenderable(state.renderable, token.raw, marginBottom);
|
|
9503
|
+
return;
|
|
9504
|
+
}
|
|
9505
|
+
state.renderable.destroyRecursively();
|
|
9506
|
+
const markdownRenderable = this.createMarkdownCodeRenderable(token.raw, `${this.id}-block-${index}`, marginBottom);
|
|
9507
|
+
this.add(markdownRenderable);
|
|
9508
|
+
state.renderable = markdownRenderable;
|
|
9451
9509
|
}
|
|
9452
|
-
updateBlocks() {
|
|
9510
|
+
updateBlocks(forceTableRefresh = false) {
|
|
9511
|
+
if (this.isDestroyed)
|
|
9512
|
+
return;
|
|
9453
9513
|
if (!this._content) {
|
|
9454
9514
|
this.clearBlockStates();
|
|
9455
9515
|
this._parseState = null;
|
|
@@ -9460,35 +9520,39 @@ class MarkdownRenderable extends Renderable {
|
|
|
9460
9520
|
const tokens = this._parseState.tokens;
|
|
9461
9521
|
if (tokens.length === 0 && this._content.length > 0) {
|
|
9462
9522
|
this.clearBlockStates();
|
|
9463
|
-
const
|
|
9464
|
-
this.add(
|
|
9523
|
+
const fallback = this.createMarkdownCodeRenderable(this._content, `${this.id}-fallback`);
|
|
9524
|
+
this.add(fallback);
|
|
9465
9525
|
this._blockStates = [
|
|
9466
9526
|
{
|
|
9467
9527
|
token: { type: "text", raw: this._content, text: this._content },
|
|
9468
9528
|
tokenRaw: this._content,
|
|
9469
|
-
renderable:
|
|
9529
|
+
renderable: fallback
|
|
9470
9530
|
}
|
|
9471
9531
|
];
|
|
9472
9532
|
return;
|
|
9473
9533
|
}
|
|
9474
|
-
const blockTokens =
|
|
9475
|
-
for (let i = 0;i < tokens.length; i++) {
|
|
9476
|
-
if (tokens[i].type !== "space") {
|
|
9477
|
-
blockTokens.push({ token: tokens[i], originalIndex: i });
|
|
9478
|
-
}
|
|
9479
|
-
}
|
|
9534
|
+
const blockTokens = this.buildRenderableTokens(tokens);
|
|
9480
9535
|
const lastBlockIndex = blockTokens.length - 1;
|
|
9481
9536
|
let blockIndex = 0;
|
|
9482
9537
|
for (let i = 0;i < blockTokens.length; i++) {
|
|
9483
|
-
const
|
|
9538
|
+
const token = blockTokens[i];
|
|
9484
9539
|
const hasNextToken = i < lastBlockIndex;
|
|
9485
9540
|
const existing = this._blockStates[blockIndex];
|
|
9541
|
+
const shouldForceRefresh = forceTableRefresh;
|
|
9486
9542
|
if (existing && existing.token === token) {
|
|
9543
|
+
if (shouldForceRefresh) {
|
|
9544
|
+
this.updateBlockRenderable(existing, token, blockIndex, hasNextToken);
|
|
9545
|
+
existing.tokenRaw = token.raw;
|
|
9546
|
+
}
|
|
9487
9547
|
blockIndex++;
|
|
9488
9548
|
continue;
|
|
9489
9549
|
}
|
|
9490
9550
|
if (existing && existing.tokenRaw === token.raw && existing.token.type === token.type) {
|
|
9491
9551
|
existing.token = token;
|
|
9552
|
+
if (shouldForceRefresh) {
|
|
9553
|
+
this.updateBlockRenderable(existing, token, blockIndex, hasNextToken);
|
|
9554
|
+
existing.tokenRaw = token.raw;
|
|
9555
|
+
}
|
|
9492
9556
|
blockIndex++;
|
|
9493
9557
|
continue;
|
|
9494
9558
|
}
|
|
@@ -9508,6 +9572,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9508
9572
|
const context = {
|
|
9509
9573
|
syntaxStyle: this._syntaxStyle,
|
|
9510
9574
|
conceal: this._conceal,
|
|
9575
|
+
concealCode: this._concealCode,
|
|
9511
9576
|
treeSitterClient: this._treeSitterClient,
|
|
9512
9577
|
defaultRender: () => this.createDefaultRenderable(token, blockIndex, hasNextToken)
|
|
9513
9578
|
};
|
|
@@ -9518,7 +9583,7 @@ class MarkdownRenderable extends Renderable {
|
|
|
9518
9583
|
}
|
|
9519
9584
|
if (!renderable) {
|
|
9520
9585
|
if (token.type === "table") {
|
|
9521
|
-
const tableBlock = this.createTableBlock(token, `${this.id}-block-${blockIndex}`, hasNextToken
|
|
9586
|
+
const tableBlock = this.createTableBlock(token, `${this.id}-block-${blockIndex}`, this.getInterBlockMargin(token, hasNextToken));
|
|
9522
9587
|
renderable = tableBlock.renderable;
|
|
9523
9588
|
tableContentCache = tableBlock.tableContentCache;
|
|
9524
9589
|
} else {
|
|
@@ -9555,44 +9620,48 @@ class MarkdownRenderable extends Renderable {
|
|
|
9555
9620
|
for (let i = 0;i < this._blockStates.length; i++) {
|
|
9556
9621
|
const state = this._blockStates[i];
|
|
9557
9622
|
const hasNextToken = i < this._blockStates.length - 1;
|
|
9623
|
+
const marginBottom = this.getInterBlockMargin(state.token, hasNextToken);
|
|
9558
9624
|
if (state.token.type === "code") {
|
|
9559
|
-
|
|
9560
|
-
|
|
9561
|
-
|
|
9562
|
-
|
|
9625
|
+
this.applyCodeBlockRenderable(state.renderable, state.token, marginBottom);
|
|
9626
|
+
continue;
|
|
9627
|
+
}
|
|
9628
|
+
if (state.token.type === "table") {
|
|
9563
9629
|
const tableToken = state.token;
|
|
9564
|
-
const marginBottom = hasNextToken ? 1 : 0;
|
|
9565
9630
|
const { cache } = this.buildTableContentCache(tableToken, state.tableContentCache, true);
|
|
9566
9631
|
if (!cache) {
|
|
9567
|
-
if (state.renderable instanceof
|
|
9568
|
-
state.renderable
|
|
9569
|
-
state.renderable.marginBottom = marginBottom;
|
|
9632
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
9633
|
+
this.applyMarkdownCodeRenderable(state.renderable, tableToken.raw, marginBottom);
|
|
9570
9634
|
} else {
|
|
9571
9635
|
state.renderable.destroyRecursively();
|
|
9572
|
-
const fallbackRenderable = this.
|
|
9636
|
+
const fallbackRenderable = this.createMarkdownCodeRenderable(tableToken.raw, `${this.id}-block-${i}`, marginBottom);
|
|
9573
9637
|
this.add(fallbackRenderable);
|
|
9574
9638
|
state.renderable = fallbackRenderable;
|
|
9575
9639
|
}
|
|
9576
9640
|
state.tableContentCache = undefined;
|
|
9577
|
-
|
|
9641
|
+
continue;
|
|
9642
|
+
}
|
|
9643
|
+
if (state.renderable instanceof TextTableRenderable) {
|
|
9578
9644
|
state.renderable.content = cache.content;
|
|
9579
9645
|
this.applyTableRenderableOptions(state.renderable, this.resolveTableRenderableOptions());
|
|
9580
9646
|
state.renderable.marginBottom = marginBottom;
|
|
9581
9647
|
state.tableContentCache = cache;
|
|
9582
|
-
|
|
9583
|
-
state.renderable.destroyRecursively();
|
|
9584
|
-
const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${i}`, marginBottom);
|
|
9585
|
-
this.add(tableRenderable);
|
|
9586
|
-
state.renderable = tableRenderable;
|
|
9587
|
-
state.tableContentCache = cache;
|
|
9588
|
-
}
|
|
9589
|
-
} else {
|
|
9590
|
-
const textRenderable = state.renderable;
|
|
9591
|
-
const chunks = this.renderTokenToChunks(state.token);
|
|
9592
|
-
if (chunks.length > 0) {
|
|
9593
|
-
textRenderable.content = new StyledText(chunks);
|
|
9648
|
+
continue;
|
|
9594
9649
|
}
|
|
9650
|
+
state.renderable.destroyRecursively();
|
|
9651
|
+
const tableRenderable = this.createTextTableRenderable(cache.content, `${this.id}-block-${i}`, marginBottom);
|
|
9652
|
+
this.add(tableRenderable);
|
|
9653
|
+
state.renderable = tableRenderable;
|
|
9654
|
+
state.tableContentCache = cache;
|
|
9655
|
+
continue;
|
|
9595
9656
|
}
|
|
9657
|
+
if (state.renderable instanceof CodeRenderable) {
|
|
9658
|
+
this.applyMarkdownCodeRenderable(state.renderable, state.token.raw, marginBottom);
|
|
9659
|
+
continue;
|
|
9660
|
+
}
|
|
9661
|
+
state.renderable.destroyRecursively();
|
|
9662
|
+
const markdownRenderable = this.createMarkdownCodeRenderable(state.token.raw, `${this.id}-block-${i}`, marginBottom);
|
|
9663
|
+
this.add(markdownRenderable);
|
|
9664
|
+
state.renderable = markdownRenderable;
|
|
9596
9665
|
}
|
|
9597
9666
|
}
|
|
9598
9667
|
clearCache() {
|
|
@@ -11634,6 +11703,7 @@ export {
|
|
|
11634
11703
|
env,
|
|
11635
11704
|
engine,
|
|
11636
11705
|
dim,
|
|
11706
|
+
detectLinks,
|
|
11637
11707
|
delegate,
|
|
11638
11708
|
cyan,
|
|
11639
11709
|
createTimeline,
|
|
@@ -11763,5 +11833,5 @@ export {
|
|
|
11763
11833
|
ASCIIFont
|
|
11764
11834
|
};
|
|
11765
11835
|
|
|
11766
|
-
//# debugId=
|
|
11836
|
+
//# debugId=D4980C658617B6F964756E2164756E21
|
|
11767
11837
|
//# sourceMappingURL=index.js.map
|