/// Remove all links in markdown documentation.
Remove all links in markdown documentation.
Remove all links in markdown documentation .
pub(crate) fn remove_links(markdown: &str) -> String {
    let mut drop_link = false;
    let mut opts = Options::empty();
    opts.insert(Options::ENABLE_FOOTNOTES);
    let mut cb = |_: BrokenLink| {
        let empty = InlineStr::try_from("").unwrap();
        Some((CowStr::Inlined(empty.clone()), CowStr::Inlined(empty)))
    };
    let doc = Parser::new_with_broken_link_callback(markdown, opts, Some(&mut cb));
    let doc = doc.filter_map(move |evt| match evt {
        Event::Start(Tag::Link(link_type, ref target, ref title)) => {
            if link_type == LinkType::Inline && target.contains("://") {
                Some(Event::Start(Tag::Link(link_type, target.clone(), title.clone())))
            } else {
                drop_link = true;
                None
            }
        }
        Event::End(_) if drop_link => {
            drop_link = false;
            None
        }
        _ => Some(evt),
    });
    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 remove_links ( markdown : & str ) -> String { let mut drop_link = false ; let mut opts = Options :: empty ( ) ; opts . insert ( Options :: ENABLE_FOOTNOTES ) ; let mut cb = | _ : BrokenLink | { let empty = InlineStr :: try_from ( " " ) . unwrap ( ) ; Some ( ( CowStr :: Inlined ( empty . clone ( ) ) , CowStr :: Inlined ( empty ) ) ) } ; let doc = Parser :: new_with_broken_link_callback ( markdown , opts , Some ( & mut cb ) ) ; let doc = doc . filter_map ( move | evt | match evt { Event :: Start ( Tag :: Link ( link_type , ref target , ref title ) ) => { if link_type == LinkType :: Inline && target . contains ( " " ) { Some ( Event :: Start ( Tag :: Link ( link_type , target . clone ( ) , title . clone ( ) ) ) ) } else { drop_link = true ; None } } Event :: End ( _ ) if drop_link => { drop_link = false ; None } _ => Some ( evt ) , } ) ; 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 }
Remove all links in markdown documentation.
Remove all links in markdown documentation .
markdown
&str