Write documentation for markdown::Content
This commit is contained in:
parent
8cac532cd9
commit
952c47bc8a
1 changed files with 10 additions and 1 deletions
|
|
@ -47,7 +47,6 @@
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
#![allow(missing_docs)]
|
|
||||||
use crate::core::border;
|
use crate::core::border;
|
||||||
use crate::core::font::{self, Font};
|
use crate::core::font::{self, Font};
|
||||||
use crate::core::padding;
|
use crate::core::padding;
|
||||||
|
|
@ -66,6 +65,7 @@ pub use core::text::Highlight;
|
||||||
pub use pulldown_cmark::HeadingLevel;
|
pub use pulldown_cmark::HeadingLevel;
|
||||||
pub use url::Url;
|
pub use url::Url;
|
||||||
|
|
||||||
|
/// A bunch of Markdown that has been parsed.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Content {
|
pub struct Content {
|
||||||
items: Vec<Item>,
|
items: Vec<Item>,
|
||||||
|
|
@ -73,10 +73,12 @@ pub struct Content {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Content {
|
impl Content {
|
||||||
|
/// Creates a new empty [`Content`].
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates some new [`Content`] by parsing the given Markdown.
|
||||||
pub fn parse(markdown: &str) -> Self {
|
pub fn parse(markdown: &str) -> Self {
|
||||||
let mut state = State::default();
|
let mut state = State::default();
|
||||||
let items = parse_with(&mut state, markdown).collect();
|
let items = parse_with(&mut state, markdown).collect();
|
||||||
|
|
@ -84,6 +86,10 @@ impl Content {
|
||||||
Self { items, state }
|
Self { items, state }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Pushes more Markdown into the [`Content`]; parsing incrementally!
|
||||||
|
///
|
||||||
|
/// This is specially useful when you have long streams of Markdown; like
|
||||||
|
/// big files or potentially long replies.
|
||||||
pub fn push_str(&mut self, markdown: &str) {
|
pub fn push_str(&mut self, markdown: &str) {
|
||||||
if markdown.is_empty() {
|
if markdown.is_empty() {
|
||||||
return;
|
return;
|
||||||
|
|
@ -101,6 +107,9 @@ impl Content {
|
||||||
self.items.extend(new_items);
|
self.items.extend(new_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the Markdown items, ready to be rendered.
|
||||||
|
///
|
||||||
|
/// You can use [`view`] to turn them into an [`Element`].
|
||||||
pub fn items(&self) -> &[Item] {
|
pub fn items(&self) -> &[Item] {
|
||||||
&self.items
|
&self.items
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue