serialize to html instead of text [CI SKIP]
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -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:
|
||||
|
Reference in New Issue
Block a user