html5ever 0.18.0

High-performance browser-grade HTML5 parser
// Copyright 2014-2017 The html5ever Project Developers. See the
// COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
//> or the MIT license
// <LICENSE-MIT or>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! Parse and re-serialize a HTML5 document.
//! This is meant to produce the exact same output (ignoring stderr) as
//!   java -classpath htmlparser-1.4.jar
//! where htmlparser-1.4.jar comes from

extern crate html5ever;

use std::io::{self, Write};
use std::default::Default;

use html5ever::{parse_document, serialize};
use html5ever::driver::ParseOpts;
use html5ever::rcdom::RcDom;
use html5ever::tendril::TendrilSink;
use html5ever::tree_builder::TreeBuilderOpts;

fn main() {
    let opts = ParseOpts {
        tree_builder: TreeBuilderOpts {
            drop_doctype: true,
    let stdin = io::stdin();
    let dom = parse_document(RcDom::default(), opts)
        .read_from(&mut stdin.lock())

    // The HTML2HTML always prints a doctype at the very beginning.
    io::stdout().write_all(b"<!DOCTYPE html>\n")
        .ok().expect("writing DOCTYPE failed");
    serialize(&mut io::stdout(), &dom.document, Default::default())
        .ok().expect("serialization failed");