MCPcopy Create free account
hub / github.com/RtlZeroMemory/Rezi / parseInlines

Function parseInlines

packages/core/src/widgets/markdown/parse.ts:368–478  ·  view source on GitHub ↗
(input: string, depth: number, ctx: InlineCtx)

Source from the content-addressed store, hash-verified

366}
367
368function parseInlines(input: string, depth: number, ctx: InlineCtx): MarkdownInline[] {
369 const out: MarkdownInline[] = [];
370 if (depth > MAX_INLINE_DEPTH) {
371 pushText(out, decodeEntities(input));
372 return out;
373 }
374 let plain = "";
375 let i = 0;
376 const flush = (): void => {
377 if (plain.length > 0) {
378 pushText(out, decodeEntities(plain));
379 plain = "";
380 }
381 };
382 while (i < input.length) {
383 const ch = input[i];
384 if (ch === undefined) break;
385 if (ctx.budget-- <= 0) {
386 plain += input.slice(i);
387 break;
388 }
389 if (ch === "\\" && i + 1 < input.length) {
390 const next = input[i + 1];
391 if (next !== undefined && ASCII_PUNCT.has(next)) {
392 plain += next;
393 i += 2;
394 continue;
395 }
396 }
397 if (ch === "`") {
398 const run = scanRun(input, i, "`");
399 const close = findBacktickClose(input, i + run, run, ctx);
400 if (close >= 0) {
401 flush();
402 let content = input.slice(i + run, close).replace(/\n/g, " ");
403 if (
404 content.length >= 2 &&
405 content.startsWith(" ") &&
406 content.endsWith(" ") &&
407 content.trim().length > 0
408 ) {
409 content = content.slice(1, -1);
410 }
411 out.push({ kind: "code", text: content });
412 i = close + run;
413 continue;
414 }
415 plain += input.slice(i, i + run);
416 i += run;
417 continue;
418 }
419 if (ch === "<") {
420 const m = /^<(https?:\/\/[^\s<>]+)>/.exec(input.slice(i));
421 const href = m?.[1];
422 if (m !== null && href !== undefined) {
423 flush();
424 out.push({ kind: "link", href, children: [{ kind: "text", text: href }] });
425 i += m[0].length;

Callers 4

tryParseEmphasisFunction · 0.85
tryParseDelFunction · 0.85
tryParseLinkFunction · 0.85
parseInlineRunFunction · 0.85

Calls 12

pushTextFunction · 0.85
decodeEntitiesFunction · 0.85
scanRunFunction · 0.85
findBacktickCloseFunction · 0.85
tryParseLinkFunction · 0.85
tryParseEmphasisFunction · 0.85
tryParseDelFunction · 0.85
tryParseBareUrlFunction · 0.85
replaceMethod · 0.80
flushFunction · 0.70
hasMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected