Browse Source

Textwrap, but it is breaking long links

master
Julio Biason 3 years ago
parent
commit
5c88a7faee
  1. 23
      html5test/Cargo.lock
  2. 1
      html5test/Cargo.toml
  3. 13
      html5test/src/main.rs

23
html5test/Cargo.lock generated

@ -47,6 +47,7 @@ version = "0.1.0"
dependencies = [
"html5ever",
"markup5ever_rcdom",
"textwrap",
]
[[package]]
@ -239,6 +240,12 @@ version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbce6d4507c7e4a3962091436e56e95290cb71fa302d0d270e32130b75fbff27"
[[package]]
name = "smawk"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f67ad224767faa3c7d8b6d91985b78e70a1324408abcb1cfcc2be4c06bc06043"
[[package]]
name = "string_cache"
version = "0.8.1"
@ -286,6 +293,16 @@ dependencies = [
"utf-8",
]
[[package]]
name = "textwrap"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd05616119e612a8041ef58f2b578906cc2531a6069047ae092cfb86a325d835"
dependencies = [
"smawk",
"unicode-width",
]
[[package]]
name = "time"
version = "0.1.44"
@ -297,6 +314,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "unicode-xid"
version = "0.2.1"

1
html5test/Cargo.toml

@ -9,3 +9,4 @@ edition = "2018"
[dependencies]
html5ever = "0.25"
markup5ever_rcdom = "0.1"
textwrap = "0.13"

13
html5test/src/main.rs

@ -5,6 +5,8 @@ use markup5ever_rcdom::NodeData;
use markup5ever_rcdom::RcDom;
use std::borrow::Borrow;
use std::default::Default;
use textwrap::fill;
use textwrap::Options;
fn go_children(input: &Handle, result: &mut String) {
for child in input.children.borrow().iter() {
@ -41,8 +43,12 @@ fn walk(input: &Handle, result: &mut String) {
.iter()
.find(|attr| attr.name.local.to_string() == "class");
if let Some(class) = classes {
if !class.value.to_string().contains("invisible") {
let classes = class.value.to_string();
if !classes.contains("invisible") {
go_children(input, result);
if classes.contains("ellipsis") {
result.push_str("...");
}
}
} else {
go_children(input, result);
@ -98,5 +104,8 @@ fn main() {
let mut result = String::new();
walk(&dom.document, &mut result);
println!("---------------------------------");
println!("{}", result);
let options = Options::new(70)
.initial_indent(" ")
.subsequent_indent(" ");
println!("{}", fill(&result.trim(), &options));
}

Loading…
Cancel
Save