fn parse_comment_helper(text: String, style: Style, s: &mut StyledString, links: &mut Vec<String>) {
    debug!("parse comment: {}", text);

    let mut curr_pos = 0;

    // This variable indicates whether we have parsed the first paragraph of the current text.
    // It is used to add a break between 2 consecutive paragraphs.
    let mut seen_first_paragraph = false;

    for caps in COMMENT_RE.captures_iter(&text) {
        // the part that doesn't match any patterns is rendered in the default style
        let whole_match = caps.get(0).unwrap();
        if curr_pos < whole_match.start() {
            s.append_styled(&text[curr_pos..whole_match.start()], style);
        }
        curr_pos = whole_match.end();

        let component_style = &config::get_config_theme().component_style;

        if let (Some(m_quote), Some(m_text)) = (caps.name("quote"), caps.name("text")) {
            if seen_first_paragraph {
                s.append_plain("\n");
            } else {
                seen_first_paragraph = true;
            }

            // render quote character `>` as indentation character
            s.append_styled(
                "▎"
                    .to_string()
                    .repeat(m_quote.as_str().matches('>').count()),
                style,
            );
            parse_comment_helper(
                m_text.as_str().to_string(),
                component_style.quote.into(),
                s,
                links,
            );

            s.append_plain("\n");
        } else if let Some(m) = caps.name("paragraph") {
            if seen_first_paragraph {
                s.append_plain("\n");
            } else {
                seen_first_paragraph = true;
            }

            parse_comment_helper(m.as_str().to_string(), style, s, links);

            s.append_plain("\n");
        } else if let Some(m) = caps.name("link") {
            links.push(m.as_str().to_string());

            s.append_styled(
                utils::shorten_url(m.as_str()),
                style.combine(component_style.link),
            );
            s.append_styled(" ", style);
            s.append_styled(
                format!("[{}]", links.len()),
                style.combine(component_style.link_id),
            );
        } else if let Some(m) = caps.name("multiline_code") {
            s.append_styled(
                m.as_str(),
                style.combine(component_style.multiline_code_block),
            );
            s.append_plain("\n");
        } else if let Some(m) = caps.name("code") {
            s.append_styled(m.as_str(), style.combine(component_style.single_code_block));
        } else if let Some(m) = caps.name("italic") {
            s.append_styled(m.as_str(), style.combine(component_style.italic));
        }
    }

    if curr_pos < text.len() {
        s.append_styled(&text[curr_pos..text.len()], style);
    }
}
/// A helper function for parsing comment text that allows recursively parsing sub-elements of the text.
A helper function for parsing comment text that allows recursively parsing sub-elements of the text.
A helper function for parsing comment text that allows recursively parsing sub - elements of the text .
fn parse_comment_helper(text: String, style: Style, s: &mut StyledString, links: &mut Vec<String>) {
    debug!("parse comment: {}", text);
    let mut curr_pos = 0;
    // This variable indicates whether we have parsed the first paragraph of the current text.
    // It is used to add a break between 2 consecutive paragraphs.
    let mut seen_first_paragraph = false;
    for caps in COMMENT_RE.captures_iter(&text) {
        // the part that doesn't match any patterns is rendered in the default style
        let whole_match = caps.get(0).unwrap();
        if curr_pos < whole_match.start() {
            s.append_styled(&text[curr_pos..whole_match.start()], style);
        }
        curr_pos = whole_match.end();
        let component_style = &config::get_config_theme().component_style;
        if let (Some(m_quote), Some(m_text)) = (caps.name("quote"), caps.name("text")) {
            if seen_first_paragraph {
                s.append_plain("\n");
            } else {
                seen_first_paragraph = true;
            }
            // render quote character `>` as indentation character
            s.append_styled(
                "▎"
                    .to_string()
                    .repeat(m_quote.as_str().matches('>').count()),
                style,
            );
            parse_comment_helper(
                m_text.as_str().to_string(),
                component_style.quote.into(),
                s,
                links,
            );
            s.append_plain("\n");
        } else if let Some(m) = caps.name("paragraph") {
            if seen_first_paragraph {
                s.append_plain("\n");
            } else {
                seen_first_paragraph = true;
            }
            parse_comment_helper(m.as_str().to_string(), style, s, links);
            s.append_plain("\n");
        } else if let Some(m) = caps.name("link") {
            links.push(m.as_str().to_string());
            s.append_styled(
                utils::shorten_url(m.as_str()),
                style.combine(component_style.link),
            );
            s.append_styled(" ", style);
            s.append_styled(
                format!("[{}]", links.len()),
                style.combine(component_style.link_id),
            );
        } else if let Some(m) = caps.name("multiline_code") {
            s.append_styled(
                m.as_str(),
                style.combine(component_style.multiline_code_block),
            );
            s.append_plain("\n");
        } else if let Some(m) = caps.name("code") {
            s.append_styled(m.as_str(), style.combine(component_style.single_code_block));
        } else if let Some(m) = caps.name("italic") {
            s.append_styled(m.as_str(), style.combine(component_style.italic));
        }
    }
    if curr_pos < text.len() {
        s.append_styled(&text[curr_pos..text.len()], style);
    }
}
fn parse_comment_helper ( text : String , style : Style , s : & mut StyledString , links : & mut Vec < String > ) { debug ! ( " " text ) ; let mut curr_pos = 0 ; // This variable indicates whether we have parsed the first paragraph of the current text. // It is used to add a break between 2 consecutive paragraphs. let mut seen_first_paragraph = false ; for caps in COMMENT_RE . captures_iter ( & text ) { // the part that doesn't match any patterns is rendered in the default style let whole_match = caps . get ( 0 ) . unwrap ( ) ; if curr_pos < whole_match . start ( ) { s . append_styled ( & text [ curr_pos .. whole_match . start ( ) ] , style ) ; } curr_pos = whole_match . end ( ) ; let component_style = & config :: get_config_theme ( ) . component_style ; if let ( Some ( m_quote ) , Some ( m_text ) ) = ( caps . name ( " " ) , caps . name ( " " ) ) { if seen_first_paragraph { s . append_plain ( " \n " ) ; } else { seen_first_paragraph = true ; } // render quote character `>` as indentation character s . append_styled ( " . to_string ( ) . repeat ( m_quote . as_str ( ) . matches ( '>' ) . count ( ) ) , style , ) ; parse_comment_helper ( m_text . as_str ( ) . to_string ( ) , component_style . quote . into ( ) , s , links , ) ; s . append_plain ( " \n " ) ; } else if let Some ( m ) = caps . name ( " " ) { if seen_first_paragraph { s . append_plain ( " \n " ) ; } else { seen_first_paragraph = true ; } parse_comment_helper ( m . as_str ( ) . to_string ( ) , style , s , links ) ; s . append_plain ( " \n " ) ; } else if let Some ( m ) = caps . name ( " " ) { links . push ( m . as_str ( ) . to_string ( ) ) ; s . append_styled ( utils :: shorten_url ( m . as_str ( ) ) , style . combine ( component_style . link ) , ) ; s . append_styled ( " " , style ) ; s . append_styled ( format ! ( " " links len ( ) ) , style . combine ( component_style . link_id ) , ) ; } else if let Some ( m ) = caps . name ( " " ) { s . append_styled ( m . as_str ( ) , style . combine ( component_style . multiline_code_block ) , ) ; s . append_plain ( " \n " ) ; } else if let Some ( m ) = caps . name ( " " ) { s . append_styled ( m . as_str ( ) , style . combine ( component_style . single_code_block ) ) ; } else if let Some ( m ) = caps . name ( " " ) { s . append_styled ( m . as_str ( ) , style . combine ( component_style . italic ) ) ; } } if curr_pos < text . len ( ) { s . append_styled ( & text [ curr_pos .. text . len ( ) ] , style ) ; } }
A helper function for parsing comment text that allows recursively parsing sub-elements of the text.
A helper function for parsing comment text that allows recursively parsing sub - elements of the text .
text
String
style
Style
s
&mut StyledString
links
&mut Vec<String>