feat: Add markdown toggle (alt+m) to switch between rendered and raw… (#10383)

Co-authored-by: Jacob Richman <jacob314@gmail.com>
This commit is contained in:
Srivats Jayaram
2025-10-16 11:23:36 -07:00
committed by GitHub
parent 05930d5e25
commit 6ded45e5d2
19 changed files with 245 additions and 7 deletions

View File

@@ -132,10 +132,13 @@ export function colorizeCode(
maxWidth?: number,
theme?: Theme,
settings?: LoadedSettings,
hideLineNumbers?: boolean,
): React.ReactNode {
const codeToHighlight = code.replace(/\n$/, '');
const activeTheme = theme || themeManager.getActiveTheme();
const showLineNumbers = settings?.merged.ui?.showLineNumbers ?? true;
const showLineNumbers = hideLineNumbers
? false
: (settings?.merged.ui?.showLineNumbers ?? true);
try {
// Render the HAST tree using the adapted theme

View File

@@ -17,6 +17,7 @@ interface MarkdownDisplayProps {
isPending: boolean;
availableTerminalHeight?: number;
terminalWidth: number;
renderMarkdown?: boolean;
}
// Constants for Markdown parsing and rendering
@@ -31,9 +32,31 @@ const MarkdownDisplayInternal: React.FC<MarkdownDisplayProps> = ({
isPending,
availableTerminalHeight,
terminalWidth,
renderMarkdown = true,
}) => {
const settings = useSettings();
if (!text) return <></>;
// Raw markdown mode - display syntax-highlighted markdown without rendering
if (!renderMarkdown) {
// Hide line numbers in raw markdown mode as they are confusing due to chunked output
const colorizedMarkdown = colorizeCode(
text,
'markdown',
availableTerminalHeight,
terminalWidth - CODE_BLOCK_PREFIX_PADDING,
undefined,
settings,
true, // hideLineNumbers
);
return (
<Box paddingLeft={CODE_BLOCK_PREFIX_PADDING} flexDirection="column">
{colorizedMarkdown}
</Box>
);
}
const lines = text.split(/\r?\n/);
const headerRegex = /^ *(#{1,4}) +(.*)/;
const codeFenceRegex = /^ *(`{3,}|~{3,}) *(\w*?) *$/;