serialize to html instead of text [CI SKIP]

This commit is contained in:
Drone CI
2019-03-25 14:12:08 +01:00
parent f07983db53
commit 5b1c58c659
3 changed files with 15 additions and 0 deletions

View File

@@ -4,6 +4,9 @@ use structopt::StructOpt;
mod opts;
use html5ever::serialize::{serialize, SerializeOpts};
use kuchiki::NodeRef;
use markup5ever::serialize::Serialize as MSerialize;
use opts::Opts;
use std::error::Error;
use std::fs::File;
@@ -20,6 +23,13 @@ fn read_html<I: Read>(source: &mut I) -> io::Result<String> {
Ok(html)
}
fn serialize_node<N: MSerialize>(node: &N) -> Result<String, Box<dyn Error>> {
let mut bytes = Vec::new();
serialize(&mut bytes, node, SerializeOpts::default())?;
let s = String::from_utf8(bytes)?;
Ok(s)
}
fn main() -> Result<(), Box<Error>> {
let stdin = stdin();
let opt = Opts::from_args();
@@ -58,6 +68,7 @@ fn main() -> Result<(), Box<Error>> {
//let text = text_node.as_text().unwrap().borrow();
if let Some(child) = as_node.first_child() {
dbg!(serialize_node(&child));
//TODO: Convert Nodes to String, as this only works for Nodes containing plain text
if let Some(text) = child.as_text() {
// Prints: