mv push/write examples from html to Render trait

They apply more to the Render trait now than the implementation in the
html module
This commit is contained in:
Noah Hellman 2023-03-19 13:54:44 +01:00
parent 8eafdf073b
commit e506fffed8
2 changed files with 23 additions and 22 deletions

View file

@ -1,26 +1,4 @@
//! An HTML renderer that takes an iterator of [`Event`]s and emits HTML. //! An HTML renderer that takes an iterator of [`Event`]s and emits HTML.
//!
//! The HTML can be written to either a [`std::fmt::Write`] or a [`std::io::Write`] object.
//!
//! # Examples
//!
//! Push to a [`String`] (implements [`std::fmt::Write`]):
//!
//! ```
//! # use jotdown::Render;
//! # let events = std::iter::empty();
//! let mut html = String::new();
//! jotdown::html::Renderer.push(events, &mut html);
//! ```
//!
//! Write to standard output with buffering ([`std::io::Stdout`] implements [`std::io::Write`]):
//!
//! ```
//! # use jotdown::Render;
//! # let events = std::iter::empty();
//! let mut out = std::io::BufWriter::new(std::io::stdout());
//! jotdown::html::Renderer.write(events, &mut out).unwrap();
//! ```
use crate::Alignment; use crate::Alignment;
use crate::Container; use crate::Container;

View file

@ -67,6 +67,29 @@ pub use attr::{AttributeValue, AttributeValueParts, Attributes};
type CowStr<'s> = std::borrow::Cow<'s, str>; type CowStr<'s> = std::borrow::Cow<'s, str>;
/// A trait for rendering [`Event`]s to an output format.
///
/// The output can be written to either a [`std::fmt::Write`] or a [`std::io::Write`] object.
///
/// # Examples
///
/// Push to a [`String`] (implements [`std::fmt::Write`]):
///
/// ```
/// # use jotdown::Render;
/// # let events = std::iter::empty();
/// let mut output = String::new();
/// jotdown::html::Renderer.push(events, &mut output);
/// ```
///
/// Write to standard output with buffering ([`std::io::Stdout`] implements [`std::io::Write`]):
///
/// ```
/// # use jotdown::Render;
/// # let events = std::iter::empty();
/// let mut out = std::io::BufWriter::new(std::io::stdout());
/// jotdown::html::Renderer.write(events, &mut out).unwrap();
/// ```
pub trait Render { pub trait Render {
/// Push [`Event`]s to a unicode-accepting buffer or stream. /// Push [`Event`]s to a unicode-accepting buffer or stream.
fn push<'s, I: Iterator<Item = Event<'s>>, W: fmt::Write>( fn push<'s, I: Iterator<Item = Event<'s>>, W: fmt::Write>(