Skip to content

Commit

Permalink
Merge pull request #500 from Sharktheone/fix-document-writer
Browse files Browse the repository at this point in the history
fix broken document-writer bin
  • Loading branch information
Sharktheone authored Jun 25, 2024
2 parents 85cfc6a + f3b9370 commit f640879
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/bin/document-writer.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::fs;
use std::process::exit;
use std::str::FromStr;

use anyhow::bail;
use url::Url;

use gosub_html5::node::NodeId;
use gosub_html5::parser::document::{Document, DocumentBuilder};
use gosub_html5::parser::Html5Parser;
use gosub_shared::bytes::{CharIterator, Confidence, Encoding};
use gosub_shared::byte_stream::{ByteStream, Confidence, Encoding};
use gosub_shared::timing::Scale;
use gosub_shared::timing_display;
use gosub_shared::types::Result;
use std::fs;
use std::process::exit;
use std::str::FromStr;
use url::Url;

fn bail(message: &str) -> ! {
println!("{message}");
Expand Down Expand Up @@ -51,20 +53,21 @@ fn main() -> Result<()> {
bail("Invalid url scheme");
};

let mut chars = CharIterator::new();
chars.read_from_str(&html, Some(Encoding::UTF8));
chars.set_confidence(Confidence::Certain);
let mut stream = ByteStream::new();
stream.read_from_str(&html, Some(Encoding::UTF8));
stream.set_confidence(Confidence::Certain);
stream.close();

// If the encoding confidence is not Confidence::Certain, we should detect the encoding.
if !chars.is_certain_encoding() {
chars.detect_encoding();
if !stream.is_certain_encoding() {
stream.detect_encoding();
}

// SimpleLogger::new().init().unwrap();

// Create a new document that will be filled in by the parser
let handle = DocumentBuilder::new_document(Some(url));
let parse_errors = Html5Parser::parse_document(&mut chars, Document::clone(&handle), None)?;
let parse_errors = Html5Parser::parse_document(&mut stream, Document::clone(&handle), None)?;

println!("Found {} stylesheets", handle.get().stylesheets.len());
for sheet in &handle.get().stylesheets {
Expand Down

0 comments on commit f640879

Please sign in to comment.