mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-03-29 15:31:37 +00:00
Added optimization
This commit is contained in:
parent
02896e1ca2
commit
419c5a9d68
@ -205,6 +205,7 @@ public partial class ContentBlockComponent : MSGComponentBase
|
|||||||
var lines = normalizedWithUnixLineEndings.Split('\n');
|
var lines = normalizedWithUnixLineEndings.Split('\n');
|
||||||
var markdownBuilder = new StringBuilder();
|
var markdownBuilder = new StringBuilder();
|
||||||
var mathBuilder = new StringBuilder();
|
var mathBuilder = new StringBuilder();
|
||||||
|
|
||||||
var segments = new List<MarkdownRenderSegment>();
|
var segments = new List<MarkdownRenderSegment>();
|
||||||
string? activeCodeFenceMarker = null;
|
string? activeCodeFenceMarker = null;
|
||||||
var inMathBlock = false;
|
var inMathBlock = false;
|
||||||
@ -215,13 +216,13 @@ public partial class ContentBlockComponent : MSGComponentBase
|
|||||||
|
|
||||||
if (!inMathBlock && TryUpdateCodeFenceState(trimmedLine, ref activeCodeFenceMarker))
|
if (!inMathBlock && TryUpdateCodeFenceState(trimmedLine, ref activeCodeFenceMarker))
|
||||||
{
|
{
|
||||||
AppendLine(markdownBuilder, line);
|
markdownBuilder.AppendLine(line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeCodeFenceMarker is not null)
|
if (activeCodeFenceMarker is not null)
|
||||||
{
|
{
|
||||||
AppendLine(markdownBuilder, line);
|
markdownBuilder.AppendLine(line);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,7 +243,10 @@ public partial class ContentBlockComponent : MSGComponentBase
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppendLine(inMathBlock ? mathBuilder : markdownBuilder, line);
|
if (inMathBlock)
|
||||||
|
mathBuilder.AppendLine(line);
|
||||||
|
else
|
||||||
|
markdownBuilder.AppendLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inMathBlock)
|
if (inMathBlock)
|
||||||
@ -309,18 +313,13 @@ public partial class ContentBlockComponent : MSGComponentBase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AppendLine(StringBuilder builder, string line)
|
|
||||||
{
|
|
||||||
builder.AppendLine(line);
|
|
||||||
}
|
|
||||||
|
|
||||||
private enum MarkdownRenderSegmentType
|
private enum MarkdownRenderSegmentType
|
||||||
{
|
{
|
||||||
MARKDOWN,
|
MARKDOWN,
|
||||||
MATH_BLOCK,
|
MATH_BLOCK,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly record struct MarkdownRenderSegment(MarkdownRenderSegmentType Type, string Content);
|
private sealed record MarkdownRenderSegment(MarkdownRenderSegmentType Type, string Content);
|
||||||
|
|
||||||
private async Task RemoveBlock()
|
private async Task RemoveBlock()
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user