mirror of
https://github.com/openai/codex.git
synced 2026-04-30 17:36:40 +00:00
fix(tui): preserve trailing blank lines in fenced code blocks
trim_end_matches('\n') stripped all trailing newlines from the code
block buffer before highlighting, discarding intentional blank lines
authored inside fences. pulldown-cmark appends exactly one trailing
'\n' to the text content, and LinesWithEndings handles it correctly
as a line terminator, so no trimming is needed. Remove the trim to
preserve user-authored blank lines faithfully.
This commit is contained in:
@@ -434,10 +434,8 @@ where
|
||||
// If we buffered code for a known language, syntax-highlight it now.
|
||||
if let Some(lang) = self.code_block_lang.take() {
|
||||
let code = std::mem::take(&mut self.code_block_buffer);
|
||||
// Trim trailing newline to avoid a spurious empty line.
|
||||
let code = code.trim_end_matches('\n');
|
||||
if !code.is_empty() {
|
||||
let highlighted = highlight_code_to_lines(code, &lang);
|
||||
let highlighted = highlight_code_to_lines(&code, &lang);
|
||||
for hl_line in highlighted {
|
||||
self.push_line(Line::default());
|
||||
for span in hl_line.spans {
|
||||
|
||||
Reference in New Issue
Block a user