pub(crate) fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String {
    let mut cb = |link: BrokenLink| {
        Some((
            /*url*/ link.reference.to_owned().into(),
            /*title*/ link.reference.to_owned().into(),
        ))
    };
    let doc = Parser::new_with_broken_link_callback(markdown, Options::empty(), Some(&mut cb));

    let doc = map_links(doc, |target, title: &str| {
        // This check is imperfect, there's some overlap between valid intra-doc links
        // and valid URLs so we choose to be too eager to try to resolve what might be
        // a URL.
        if target.contains("://") {
            (target.to_string(), title.to_string())
        } else {
            // Two posibilities:
            // * path-based links: `../../module/struct.MyStruct.html`
            // * module-based links (AKA intra-doc links): `super::super::module::MyStruct`
            if let Some(rewritten) = rewrite_intra_doc_link(db, *definition, target, title) {
                return rewritten;
            }
            if let Definition::ModuleDef(def) = *definition {
                if let Some(target) = rewrite_url_link(db, def, target) {
                    return (target, title.to_string());
                }
            }

            (target.to_string(), title.to_string())
        }
    });
    let mut out = String::new();
    let mut options = CmarkOptions::default();
    options.code_block_backticks = 3;
    cmark_with_options(doc, &mut out, None, options).ok();
    out
}
/// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs)
Rewrite documentation links in markdown to point to an online host
Rewrite documentation links in markdown to point to an online host
pub(crate) fn rewrite_links(db: &RootDatabase, markdown: &str, definition: &Definition) -> String {
    let mut cb = |link: BrokenLink| {
        Some((
            /*url*/ link.reference.to_owned().into(),
            /*title*/ link.reference.to_owned().into(),
        ))
    };
    let doc = Parser::new_with_broken_link_callback(markdown, Options::empty(), Some(&mut cb));
    let doc = map_links(doc, |target, title: &str| {
        // This check is imperfect, there's some overlap between valid intra-doc links
        // and valid URLs so we choose to be too eager to try to resolve what might be
        // a URL.
        if target.contains("://") {
            (target.to_string(), title.to_string())
        } else {
            // Two posibilities:
            // * path-based links: `../../module/struct.MyStruct.html`
            // * module-based links (AKA intra-doc links): `super::super::module::MyStruct`
            if let Some(rewritten) = rewrite_intra_doc_link(db, *definition, target, title) {
                return rewritten;
            }
            if let Definition::ModuleDef(def) = *definition {
                if let Some(target) = rewrite_url_link(db, def, target) {
                    return (target, title.to_string());
                }
            }
            (target.to_string(), title.to_string())
        }
    });
    let mut out = String::new();
    let mut options = CmarkOptions::default();
    options.code_block_backticks = 3;
    cmark_with_options(doc, &mut out, None, options).ok();
    out
}
pub ( crate ) fn rewrite_links ( db : & RootDatabase , markdown : & str , definition : & Definition ) -> String { let mut cb = | link : BrokenLink | { Some ( ( /*url*/ link . reference . to_owned ( ) . into ( ) , /*title*/ link . reference . to_owned ( ) . into ( ) , ) ) } ; let doc = Parser :: new_with_broken_link_callback ( markdown , Options :: empty ( ) , Some ( & mut cb ) ) ; let doc = map_links ( doc , | target , title : & str | { // This check is imperfect, there's some overlap between valid intra-doc links // and valid URLs so we choose to be too eager to try to resolve what might be // a URL. if target . contains ( " " ) { ( target . to_string ( ) , title . to_string ( ) ) } else { // Two posibilities: // * path-based links: `../../module/struct.MyStruct.html` // * module-based links (AKA intra-doc links): `super::super::module::MyStruct` if let Some ( rewritten ) = rewrite_intra_doc_link ( db , * definition , target , title ) { return rewritten ; } if let Definition :: ModuleDef ( def ) = * definition { if let Some ( target ) = rewrite_url_link ( db , def , target ) { return ( target , title . to_string ( ) ) ; } } ( target . to_string ( ) , title . to_string ( ) ) } } ) ; let mut out = String :: new ( ) ; let mut options = CmarkOptions :: default ( ) ; options . code_block_backticks = 3 ; cmark_with_options ( doc , & mut out , None , options ) . ok ( ) ; out }
Rewrite documentation links in markdown to point to an online host (e.g.
Rewrite documentation links in markdown to point to an online host ( e . g .
db
&RootDatabase
markdown
&str
definition
&Definition
db
&RootDatabase
markdown
&str
definition
&Definition