mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-16 17:11:04 -07:00
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:
@@ -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
|
||||
|
||||
@@ -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*?) *$/;
|
||||
|
||||
Reference in New Issue
Block a user