summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 0a5c405..8df262e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -6,6 +6,18 @@
//!
//! This crate aims to follow the WhatWG specification at
//! <https://html.spec.whatwg.org/>.
+//!
+//! # Example
+//!
+//! ~~~
+//! use html_page::{Element, Tag};
+//!
+//! let e = Element::new(Tag::P)
+//! .with_text("hello ")
+//! .with_child(Element::new(Tag::Strong).with_text("world"));
+//! assert_eq!(e.serialize(), "<P>hello <STRONG>world</STRONG></P>");
+//! assert_eq!(e.plain_text(), "hello world");
+//! ~~~
#![deny(missing_docs)]
@@ -641,9 +653,22 @@ pub trait Visitor {
}
/// A visitor to extract the text of an element and its children.
+///
+/// This does not include attributes or their values.
+///
+/// Note that you can call [`Element::plain_text`] for simplicity.
+///
+/// ~~~
+/// use html_page::{Element, Tag, TextVisitor, Visitor};
+/// let e = Element::new(Tag::P).with_text("hello, there");
+/// let mut tv = TextVisitor::default();
+/// tv.visit(&e);
+/// assert_eq!(tv.text, "hello, there");
+/// ~~~
#[derive(Debug, Default)]
pub struct TextVisitor {
- text: String,
+ /// The text collected by the visitor.
+ pub text: String,
}
impl Visitor for TextVisitor {