diff --git a/cursive-core/Cargo.toml b/cursive-core/Cargo.toml index 29e1a243..985323ca 100644 --- a/cursive-core/Cargo.toml +++ b/cursive-core/Cargo.toml @@ -57,7 +57,7 @@ version = "0.4" [dependencies.pulldown-cmark] default-features = false optional = true -version = "0.12" +version = "0.13" [features] default = [] diff --git a/cursive-core/src/utils/markup/markdown.rs b/cursive-core/src/utils/markup/markdown.rs index 22169584..677badf8 100644 --- a/cursive-core/src/utils/markup/markdown.rs +++ b/cursive-core/src/utils/markup/markdown.rs @@ -1,8 +1,32 @@ +#![cfg(feature = "markdown")] +#![cfg_attr(feature = "doc-cfg", doc(cfg(feature = "markdown")))] //! Parse markdown text. //! //! Needs the `markdown` feature to be enabled. -#![cfg(feature = "markdown")] -#![cfg_attr(feature = "doc-cfg", doc(cfg(feature = "markdown")))] +//! +//! ### Examples +//! +//! ```rust,ignore +//! use cursive::utils::markup::markdown::parse; +//! use cursive::views::TextView; +//! use cursive::Cursive; +//! +//! let mut siv = Cursive::default(); +//! +//! let content = parse( +//! r#"# Example Markdown +//! Hello, *world*! +//! +//! ## Header 2 +//! +//! * List item 1 +//! * List item 2 +//! "#, +//! ); +//! +//! siv.add_layer(TextView::new(content)); +//! siv.run(); +//! ``` use std::borrow::Cow; @@ -10,10 +34,16 @@ use crate::style::{Effect, Style}; use crate::utils::markup::{StyledIndexedSpan, StyledString}; use crate::utils::span::IndexedCow; -use pulldown_cmark::{self, CowStr, Event, Tag, TagEnd}; +use pulldown_cmark::{self, CowStr, Event, LinkType, Tag, TagEnd}; use unicode_width::UnicodeWidthStr; -/// Parses the given string as markdown text. +/// Parses the given string as Markdown text. +/// +/// # Arguments +/// * `input` - The markdown text to parse. +/// +/// # Returns +/// A `StyledString` containing the parsed text. pub fn parse(input: S) -> StyledString where S: Into, @@ -35,7 +65,7 @@ fn cowvert(cow: CowStr) -> Cow { } } -/// Iterator that parse a markdown text and outputs styled spans. +/// Iterator that parses a Markdown text and outputs styled spans. pub struct Parser<'a> { /// Did we process the first item already? /// @@ -44,6 +74,10 @@ pub struct Parser<'a> { stack: Vec