}
}
+impl std::ops::Add<ColouredStringSlice<'_>> for ColouredString {
+ type Output = ColouredString;
+ fn add(self, rhs: ColouredStringSlice<'_>) -> ColouredString {
+ ColouredString {
+ text: self.text.to_string() + &rhs.text,
+ colour: self.colour.to_string() + &rhs.colour,
+ }
+ }
+}
+
impl std::ops::Add<ColouredString> for &str {
type Output = ColouredString;
fn add(self, rhs: ColouredString) -> ColouredString {
}
pub trait Receiver {
- fn start_tag(&mut self, tag: &QualName, attrs: &HashMap<QualName, String>);
- fn end_tag(&mut self, tag: &QualName, attrs: &HashMap<QualName, String>);
+ fn start_tag(&mut self, tag: &str, attrs: &HashMap<String, String>);
+ fn end_tag(&mut self, tag: &str, attrs: &HashMap<String, String>);
fn text(&mut self, text: &str);
}
+fn qualname_to_string(qn: &QualName) -> String {
+ if qn.ns == ns!(html) || qn.ns == ns!() {
+ qn.local.to_string()
+ } else {
+ dbg!(&qn);
+ format!("{}:{}", qn.ns.to_string(), qn.local.to_string())
+ }
+}
+
impl Tree {
fn new_node(&mut self, contents: TreeNodeContents) -> Handle {
let handle = self.nodes.len();
TreeNodeContents::Element { name, attrs, children } => {
let mut attrmap = HashMap::new();
for attr in attrs {
- attrmap.insert(attr.name.clone(),
+ attrmap.insert(qualname_to_string(&attr.name),
attr.value.to_string());
}
- receiver.start_tag(&name, &attrmap);
+ let tagname = qualname_to_string(&name);
+ receiver.start_tag(&tagname, &attrmap);
for child in children {
self.walk_recurse(*child, receiver);
}
- receiver.end_tag(&name, &attrmap);
+ receiver.end_tag(&tagname, &attrmap);
},
_ => (),
};
use mastodonochrome::types::*;
use mastodonochrome::OurError;
use mastodonochrome::auth::AuthConfig;
-use mastodonochrome::html::{render, QualName};
+use mastodonochrome::html::{render};
use mastodonochrome::html;
use std::collections::HashMap;
use std::io::Read;
struct TestReceiver {}
impl html::Receiver for TestReceiver {
- fn start_tag(&mut self, tag: &QualName, attrs: &HashMap<QualName, String>) {
+ fn start_tag(&mut self, tag: &str, attrs: &HashMap<String, String>) {
dbg!("start", tag, attrs);
}
- fn end_tag(&mut self, tag: &QualName, attrs: &HashMap<QualName, String>) {
+ fn end_tag(&mut self, tag: &str, attrs: &HashMap<String, String>) {
dbg!("end", tag, attrs);
}
fn text(&mut self, text: &str) {