From 357e58aae16d798fe9b0bd0dec0c8b4386ffc398 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Mon, 26 Apr 2021 12:35:01 -0300 Subject: [PATCH] Found a problem where but wrote how to fix it --- html5test/src/main.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/html5test/src/main.rs b/html5test/src/main.rs index a676559..c2f6ea6 100644 --- a/html5test/src/main.rs +++ b/html5test/src/main.rs @@ -6,8 +6,36 @@ use markup5ever_rcdom::RcDom; use std::borrow::Borrow; use std::default::Default; use textwrap::fill; +use textwrap::NoHyphenation; use textwrap::Options; +// This go_children/walk is stupid, but I shot myself in the foot by adding +// things after the children, link on links. +// +// So, I'm rethinking this, and I'll, basically redo the same thing Tendril is +// doing by building a tree of elements. +// +// So, say, if we have +// +//

Text textthe linkother text, for italics,

is for code
+//

+// +// That would build +// root +// / | |\Code(is for code) +// Text(Text text) | Italic(for italics) +// Link(the link, link) +// +// Tree things to do, then: +// 1. Walk the DOM tree and build the text tree. +// 2. Tree elements could return if the DOM three should continue processing or +// ignore incoming children (that would cut the "invisible span" processing, +// for example). +// 3. Build a walker for the new tree, to produce the final text. And, on that, +// we could work on the text wrap, 'cause there are elements that can't be +// wrapped (for example, Links) + fn go_children(input: &Handle, result: &mut String) { for child in input.children.borrow().iter() { walk(child.borrow(), result); @@ -45,7 +73,7 @@ fn walk(input: &Handle, result: &mut String) { if let Some(class) = classes { let classes = class.value.to_string(); if !classes.contains("invisible") { - go_children(input, result); + go_children(input, result); // bollocks! if classes.contains("ellipsis") { result.push_str("..."); } @@ -106,6 +134,7 @@ fn main() { println!("---------------------------------"); let options = Options::new(70) .initial_indent(" ") - .subsequent_indent(" "); + .subsequent_indent(" ") + .splitter(NoHyphenation); println!("{}", fill(&result.trim(), &options)); }