Skip to content

Commit 5b3237e

Browse files
committed
Add pretty printing wrapper.
1 parent 35c7be0 commit 5b3237e

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

html-node-core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
1010

1111
mod http;
12+
#[allow(missing_docs)]
13+
pub mod pretty;
1214

1315
#[allow(missing_docs)]
1416
#[cfg(feature = "typed")]

html-node-core/src/pretty.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use std::fmt::{self, Display, Formatter};
2+
3+
use crate::Node;
4+
5+
/// A wrapper around [`Node`] that is always pretty printed.
6+
#[derive(Debug, Default)]
7+
pub struct Pretty(pub Node);
8+
9+
impl Display for Pretty {
10+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
11+
write!(f, "{:#}", self.0)
12+
}
13+
}
14+
15+
impl<N> From<N> for Pretty
16+
where
17+
N: Into<Node>,
18+
{
19+
fn from(node: N) -> Self {
20+
Self(node.into())
21+
}
22+
}

html-node/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ mod macros;
118118
#[cfg(feature = "typed")]
119119
pub mod typed;
120120

121-
pub use html_node_core::{Comment, Doctype, Element, Fragment, Node, Text, UnsafeText};
121+
pub use html_node_core::{pretty, Comment, Doctype, Element, Fragment, Node, Text, UnsafeText};
122122
/// The HTML to [`Node`] macro.
123123
///
124124
/// See the [crate-level documentation](crate) for more information.

0 commit comments

Comments
 (0)