Skip to content

Commit

Permalink
Simplify broken_link_callback doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite authored and kivikakk committed Nov 7, 2024
1 parent d0e9e7e commit 1983fa8
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,39 +644,27 @@ pub struct ParseOptions<'c> {
///
/// ```
/// # use std::{str, sync::{Arc, Mutex}};
/// # use comrak::{Arena, ResolvedReference, parse_document, format_html, Options, BrokenLinkReference, ParseOptions};
/// # use comrak::nodes::{AstNode, NodeValue};
/// #
/// # fn main() -> std::io::Result<()> {
/// let arena = Arena::new();
/// # use comrak::{markdown_to_html, BrokenLinkReference, Options, ResolvedReference};
/// let mut cb = |link_ref: BrokenLinkReference| match link_ref.normalized {
/// "foo" => Some(ResolvedReference {
/// url: "https://www.rust-lang.org/".to_string(),
/// title: "The Rust Language".to_string(),
/// }),
/// _ => None,
/// };
/// let options = Options {
/// parse: ParseOptions::builder()
/// .broken_link_callback(Arc::new(Mutex::new(&mut cb)))
/// .build(),
/// ..Default::default()
/// };
///
/// let mut options = Options::default();
/// options.parse.broken_link_callback = Some(Arc::new(Mutex::new(&mut cb)));
///
/// let root = parse_document(
/// &arena,
/// let output = markdown_to_html(
/// "# Cool input!\nWow look at this cool [link][foo]. A [broken link] renders as text.",
/// &options,
/// );
///
/// let mut output = Vec::new();
/// format_html(root, &Options::default(), &mut output)?;
/// assert_eq!(str::from_utf8(&output).unwrap(),
/// assert_eq!(output,
/// "<h1>Cool input!</h1>\n<p>Wow look at this cool \
/// <a href=\"https://www.rust-lang.org/\" title=\"The Rust Language\">link</a>. \
/// A [broken link] renders as text.</p>\n");
/// # Ok(())
/// # }
#[cfg_attr(feature = "arbitrary", arbitrary(default))]
pub broken_link_callback: Option<Arc<Mutex<BrokenLinkCallback<'c>>>>,
}
Expand Down

0 comments on commit 1983fa8

Please sign in to comment.