mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
Use the terminal palette for ordered Markdown list markers (#48800)
## What changed Render ordered list markers in the TUI with the terminal's `LightBlue` color instead of `accent_color()`. ## Testing Add a snapshot covering ordered list markers alongside links and inline code. Update rendering expectations and nested-list streaming tests to assert `LightBlue`, including the incremental rendering snapshot. GitOrigin-RevId: dea0081737a5bbe8652c761582fb82b20964431a
This commit is contained in:
@@ -150,7 +150,7 @@ impl MarkdownStyles {
|
||||
emphasis: Style::new().italic(),
|
||||
strong: Style::new().bold(),
|
||||
strikethrough: Style::new().crossed_out(),
|
||||
ordered_list_marker: Style::new().fg(accent_color()),
|
||||
ordered_list_marker: Style::new().light_blue(),
|
||||
unordered_list_marker: Style::new(),
|
||||
link: Style::new().fg(accent_color()).underlined(),
|
||||
blockquote: Style::new().green(),
|
||||
|
||||
@@ -249,13 +249,13 @@ fn blockquote_with_ordered_list() {
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(vec![
|
||||
Span::from("> "),
|
||||
"1. ".fg(accent_color()),
|
||||
"1. ".light_blue(),
|
||||
Span::from("first"),
|
||||
])
|
||||
.green(),
|
||||
Line::from_iter(vec![
|
||||
Span::from("> "),
|
||||
"2. ".fg(accent_color()),
|
||||
"2. ".light_blue(),
|
||||
Span::from("second"),
|
||||
])
|
||||
.green(),
|
||||
@@ -584,8 +584,8 @@ fn list_unordered_multiple() {
|
||||
fn list_ordered() {
|
||||
let text = render_markdown_text("1. List item 1\n2. List item 2\n");
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "List item 1".into()]),
|
||||
Line::from_iter(["2. ".fg(accent_color()), "List item 2".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "List item 1".into()]),
|
||||
Line::from_iter(["2. ".light_blue(), "List item 2".into()]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
}
|
||||
@@ -607,12 +607,20 @@ fn list_nested() {
|
||||
assert_eq!(text, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ordered_list_markers_use_terminal_palette_snapshot() {
|
||||
let text = render_markdown_text(
|
||||
"1. plain [plain](https://example.com) `code` [`code`](https://example.com)",
|
||||
);
|
||||
assert_debug_snapshot!(text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_ordered_custom_start() {
|
||||
let text = render_markdown_text("3. First\n4. Second\n");
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["3. ".fg(accent_color()), "First".into()]),
|
||||
Line::from_iter(["4. ".fg(accent_color()), "Second".into()]),
|
||||
Line::from_iter(["3. ".light_blue(), "First".into()]),
|
||||
Line::from_iter(["4. ".light_blue(), "Second".into()]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
}
|
||||
@@ -622,11 +630,11 @@ fn nested_unordered_in_ordered() {
|
||||
let md = "1. Outer\n - Inner A\n - Inner B\n2. Next\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "Outer".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "Outer".into()]),
|
||||
Line::from_iter([" • ", "Inner A"]),
|
||||
Line::from_iter([" • ", "Inner B"]),
|
||||
Line::default(),
|
||||
Line::from_iter(["2. ".fg(accent_color()), "Next".into()]),
|
||||
Line::from_iter(["2. ".light_blue(), "Next".into()]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
}
|
||||
@@ -637,8 +645,8 @@ fn nested_ordered_in_unordered() {
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["• ", "Outer"]),
|
||||
Line::from_iter([" 1. ".fg(accent_color()), "One".into()]),
|
||||
Line::from_iter([" 2. ".fg(accent_color()), "Two".into()]),
|
||||
Line::from_iter([" 1. ".light_blue(), "One".into()]),
|
||||
Line::from_iter([" 2. ".light_blue(), "Two".into()]),
|
||||
Line::default(),
|
||||
Line::from_iter(["• ", "Last"]),
|
||||
]);
|
||||
@@ -650,11 +658,11 @@ fn loose_list_item_multiple_paragraphs() {
|
||||
let md = "1. First paragraph\n\n Second paragraph of same item\n\n2. Next item\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "First paragraph".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "First paragraph".into()]),
|
||||
Line::default(),
|
||||
Line::from_iter([" ", "Second paragraph of same item"]),
|
||||
Line::default(),
|
||||
Line::from_iter(["2. ".fg(accent_color()), "Next item".into()]),
|
||||
Line::from_iter(["2. ".light_blue(), "Next item".into()]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
}
|
||||
@@ -675,11 +683,11 @@ fn deeply_nested_mixed_three_levels() {
|
||||
let md = "1. A\n - B\n 1. C\n2. D\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "A".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "A".into()]),
|
||||
Line::from_iter([" • ", "B"]),
|
||||
Line::from_iter([" 1. ".fg(accent_color()), "C".into()]),
|
||||
Line::from_iter([" 1. ".light_blue(), "C".into()]),
|
||||
Line::default(),
|
||||
Line::from_iter(["2. ".fg(accent_color()), "D".into()]),
|
||||
Line::from_iter(["2. ".light_blue(), "D".into()]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
}
|
||||
@@ -689,8 +697,8 @@ fn loose_items_due_to_blank_line_between_items() {
|
||||
let md = "1. First\n\n2. Second\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "First".into()]),
|
||||
Line::from_iter(["2. ".fg(accent_color()), "Second".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "First".into()]),
|
||||
Line::from_iter(["2. ".light_blue(), "Second".into()]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
}
|
||||
@@ -700,8 +708,8 @@ fn mixed_tight_then_loose_in_one_list() {
|
||||
let md = "1. Tight\n\n2.\n Loose\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "Tight".into()]),
|
||||
Line::from_iter(["2. ".fg(accent_color()), "Loose".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "Tight".into()]),
|
||||
Line::from_iter(["2. ".light_blue(), "Loose".into()]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
}
|
||||
@@ -711,7 +719,7 @@ fn ordered_item_with_indented_continuation_is_tight() {
|
||||
let md = "1. Foo\n Bar\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "Foo".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "Foo".into()]),
|
||||
Line::from_iter([" ", "Bar"]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
@@ -1714,12 +1722,9 @@ fn nested_five_levels_mixed_lists() {
|
||||
let md = "1. First\n - Second level\n 1. Third level (ordered)\n - Fourth level (bullet)\n - Fifth level to test indent consistency\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "First".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "First".into()]),
|
||||
Line::from_iter([" • ", "Second level"]),
|
||||
Line::from_iter([
|
||||
" 1. ".fg(accent_color()),
|
||||
"Third level (ordered)".into(),
|
||||
]),
|
||||
Line::from_iter([" 1. ".light_blue(), "Third level (ordered)".into()]),
|
||||
Line::from_iter([" • ", "Fourth level (bullet)"]),
|
||||
Line::from_iter([
|
||||
" • ",
|
||||
@@ -1754,7 +1759,7 @@ fn html_in_tight_ordered_item_soft_breaks_with_space() {
|
||||
let md = "1. Foo\n <i>Bar</i>\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "Foo".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "Foo".into()]),
|
||||
Line::from_iter([" ", "<i>", "Bar", "</i>"]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
@@ -1802,7 +1807,7 @@ fn ordered_item_continuation_paragraph_is_indented() {
|
||||
let md = "1. Intro\n\n More details about intro\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "Intro".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "Intro".into()]),
|
||||
Line::default(),
|
||||
Line::from_iter([" ", "More details about intro"]),
|
||||
]);
|
||||
@@ -1814,12 +1819,12 @@ fn nested_item_continuation_paragraph_is_indented() {
|
||||
let md = "1. A\n - B\n\n Continuation for B\n2. C\n";
|
||||
let text = render_markdown_text(md);
|
||||
let expected = Text::from_iter([
|
||||
Line::from_iter(["1. ".fg(accent_color()), "A".into()]),
|
||||
Line::from_iter(["1. ".light_blue(), "A".into()]),
|
||||
Line::from_iter([" • ", "B"]),
|
||||
Line::default(),
|
||||
Line::from_iter([" ", "Continuation for B"]),
|
||||
Line::default(),
|
||||
Line::from_iter(["2. ".fg(accent_color()), "C".into()]),
|
||||
Line::from_iter(["2. ".light_blue(), "C".into()]),
|
||||
]);
|
||||
assert_eq!(text, expected);
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn e2e_stream_nested_mixed_lists_ordered_marker_uses_shared_accent() {
|
||||
async fn e2e_stream_nested_mixed_lists_ordered_marker_uses_terminal_palette() {
|
||||
let md = [
|
||||
"1. First\n",
|
||||
" - Second level\n",
|
||||
@@ -316,14 +316,14 @@ mod tests {
|
||||
});
|
||||
let idx = find_idx.expect("expected third-level ordered line");
|
||||
let line = &out[idx];
|
||||
// Expect at least one span on this line to be styled with the shared accent
|
||||
// Expect at least one span on this line to use the terminal's LightBlue color.
|
||||
let has_accent = line
|
||||
.spans
|
||||
.iter()
|
||||
.any(|s| s.style.fg == Some(crate::style::accent_color()));
|
||||
.any(|s| s.style.fg == Some(Color::LightBlue));
|
||||
assert!(
|
||||
has_accent,
|
||||
"expected an ordered-list marker span with the shared accent on: {line:?}"
|
||||
"expected an ordered-list marker span with LightBlue on: {line:?}"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -587,7 +587,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn e2e_stream_deep_nested_third_level_marker_uses_shared_accent() {
|
||||
async fn e2e_stream_deep_nested_third_level_marker_uses_terminal_palette() {
|
||||
let md = "1. First\n - Second level\n 1. Third level (ordered)\n - Fourth level (bullet)\n - Fifth level to test indent consistency\n";
|
||||
let streamed = super::simulate_stream_markdown_for_tests(&[md], /*finalize*/ true);
|
||||
let streamed_strs = lines_to_plain_strings(&streamed);
|
||||
@@ -607,7 +607,7 @@ mod tests {
|
||||
});
|
||||
|
||||
// The marker (including indent and "1.") is expected to be in the first span
|
||||
// and colored with the shared accent; following content should be default color.
|
||||
// and colored with LightBlue; following content should be default color.
|
||||
assert!(
|
||||
!line.spans.is_empty(),
|
||||
"expected non-empty spans for the third-level line"
|
||||
@@ -615,8 +615,8 @@ mod tests {
|
||||
let marker_span = &line.spans[0];
|
||||
assert_eq!(
|
||||
marker_span.style.fg,
|
||||
Some(crate::style::accent_color()),
|
||||
"expected shared-accent 3rd-level ordered marker, got {:?}",
|
||||
Some(Color::LightBlue),
|
||||
"expected LightBlue 3rd-level ordered marker, got {:?}",
|
||||
marker_span.style.fg
|
||||
);
|
||||
// Find the first non-empty non-space content span and verify it is default color.
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
---
|
||||
source: tui/src/markdown_render_tests.rs
|
||||
assertion_line: 608
|
||||
expression: text
|
||||
---
|
||||
Text::from(Line::from_iter([Span::from("1. ").light_blue(), Span::from("plain "), Span::from("plain").fg(Color::Reset).underlined(), Span::from(" ("), Span::from("https://example.com").fg(Color::Reset).underlined(), Span::from(")"), Span::from(" "), Span::from("code").fg(Color::Rgb(166, 227, 161)), Span::from(" "), Span::from("code").fg(Color::Reset).underlined(), Span::from(" ("), Span::from("https://example.com").fg(Color::Reset).underlined(), Span::from(")")]))
|
||||
+2
-2
@@ -53,14 +53,14 @@ expression: render.lines
|
||||
},
|
||||
HyperlinkLine {
|
||||
line: Line::from_iter([
|
||||
Span::from("1. ").fg(Color::Rgb(99, 168, 248)),
|
||||
Span::from("1. ").light_blue(),
|
||||
Span::from("First item"),
|
||||
]),
|
||||
hyperlinks: [],
|
||||
},
|
||||
HyperlinkLine {
|
||||
line: Line::from_iter([
|
||||
Span::from("2. ").fg(Color::Rgb(99, 168, 248)),
|
||||
Span::from("2. ").light_blue(),
|
||||
Span::from("Second item"),
|
||||
]),
|
||||
hyperlinks: [],
|
||||
|
||||
Reference in New Issue
Block a user