Repository: openai/codex
File: codex-rs/tui/src/markdown_render.rs (Rust)

Code before:
fn hidden_local_link_location_suffix(dest_url: &str) -> Option<String> {
    if !is_local_path_like_link(dest_url) {
        return None;
    }

    parse_hash_location_suffix(dest_url)
        .and_then(normalize_hash_location_suffix)
        .or_else(|| parse_colon_location_suffix(dest_url).map(std::string::ToString::to_string))
}

fn extract_location_suffix(text: &str) -> Option<&str> {
    parse_hash_location_suffix(text).or_else(|| parse_colon_location_suffix(text))
}

fn parse_hash_location_suffix(text: &str) -> Option<&str> {
    let (_, fragment) = text.rsplit_once('#')?;
    HASH_LOCATION_SUFFIX_RE
        .is_match(fragment)
        .then_some(text.get(text.len() - fragment.len() - 1..)?)
}

fn parse_colon_location_suffix(text: &str) -> Option<&str> {
    COLON_LOCATION_SUFFIX_RE.find(text).map(|m| m.as_str())
}

fn normalize_hash_location_suffix(suffix: &str) -> Option<String> {
    let fragment = suffix.strip_prefix('#')?;
    let (start, end) = match fragment.split_once('-') {
        Some((start, end)) => (start, Some(end)),
        None => (fragment, None),
    };
    let (start_line, start_column) = parse_hash_location_point(start)?;
    let mut normalized = String::from(":");
    normalized.push_str(start_line);
    if let Some(column) = start_column {
        normalized.push(':');
        normalized.push_str(column);
    }
    if let Some(end) = end {
        let (end_line, end_column) = parse_hash_location_point(end)?;
        normalized.push('-');
        normalized.push_str(end_line);
        if let Some(column) = end_column {
            normalized.push(':');
            normalized.push_str(column);
        }
    }
    Some(normalized)
}

fn parse_hash_location_point(point: &str) -> Option<(&str, Option<&str>)> {

Review comment (suggestion):
I think this code might be useful for others so this would be relevant to put it somewhere in `codex-utils-$`

Code after:
}

struct Writer<'a, I>
where
    I: Iterator<Item = Event<'a>>,
{
    iter: I,
    text: Text<'static>,
    styles: MarkdownStyles,
    inline_styles: Vec<Style>,
    indent_stack: Vec<IndentContext>,
    list_indices: Vec<Option<u64>>,
    link: Option<LinkState>,
    needs_newline: bool,
    pending_marker_line: bool,
    in_paragraph: bool,
    in_code_block: bool,
    code_block_lang: Option<String>,
    code_block_buffer: String,
    wrap_width: Option<usize>,
    current_line_content: Option<Line<'static>>,
    current_initial_indent: Vec<Span<'static>>,
    current_subsequent_indent: Vec<Span<'static>>,
    current_line_style: Style,
    current_line_in_code_block: bool,
}

impl<'a, I> Writer<'a, I>
where
    I: Iterator<Item = Event<'a>>,
{
    fn new(iter: I, wrap_width: Option<usize>) -> Self {
        Self {
            iter,
            text: Text::default(),
            styles: MarkdownStyles::default(),
            inline_styles: Vec::new(),
            indent_stack: Vec::new(),
            list_indices: Vec::new(),
            link: None,
            needs_newline: false,
            pending_marker_line: false,
            in_paragraph: false,
            in_code_block: false,
            code_block_lang: None,
            code_block_buffer: String::new(),
            wrap_width,
            current_line_content: None,
            current_initial_indent: Vec::new(),
            current_subsequent_indent: Vec::new(),
            current_line_style: Style::default(),