diff --git a/content/src/lib.rs b/content/src/lib.rs index 40211d7..cea2471 100644 --- a/content/src/lib.rs +++ b/content/src/lib.rs @@ -54,6 +54,8 @@ fn attribute_filter<'u>(element: &str, attribute: &str, value: &'u str) -> Optio | ("a", "rel") | ("a", "title") | ("a", "href") + | ("a", "class") + | ("img", "align") | ("img", "src") | ("img", "title") | ("img", "alt") => Some(Cow::Borrowed(value)), @@ -85,6 +87,10 @@ static AMMONIA_CONFIG: Lazy = Lazy::new(|| { pre_hs.insert("codeblock"); pre_hs.insert("toolkit-code--pre"); + let a_hs = classes.entry("a").or_insert(HashSet::new()); + a_hs.insert("icon"); + a_hs.insert("icontext"); + let mut schemes = HashSet::new(); schemes.insert("http"); schemes.insert("https"); diff --git a/content/src/render.rs b/content/src/render.rs index 36bfce3..143b176 100644 --- a/content/src/render.rs +++ b/content/src/render.rs @@ -230,14 +230,20 @@ fn render_nodes(nodes: Vec) -> String { img, href, } => { - format!("", href) - + &format!( - "\"@{handle}@{domain}\"", - img, - handle = handle, - domain = domain - ) + &format!("@{}@{}", handle, domain) - + &format!("") + format!( + "", + href + ) + &format!( + "\"@{handle}@{domain}\"", + img, + handle = handle, + domain = domain + ) + " " + &format!( + "", + href + ) + + &format!("@{}@{}", handle, domain) + + "" } RenderNode::Icon { handle, @@ -245,9 +251,11 @@ fn render_nodes(nodes: Vec) -> String { img, href, } => { - format!("", href) - + &format!( - "\"@{handle}@{domain}\"", + format!( + "", + href + ) + &format!( + "\"@{handle}@{domain}\"", img, handle = handle, domain = domain @@ -364,14 +372,56 @@ where tag, attr, children, - } => to_render( - (f)(NodeView::Tag { - tag, - attr: attr.as_deref().map(Cow::Borrowed), - }), - Some(children), - f, - ), + } => match tag { + Tag::IconText => match children.get(0) { + Some(Node::Handle { handle, domain }) => to_render( + (f)(NodeView::IconText { + handle: Cow::Borrowed(&handle), + domain: Cow::Borrowed(&domain), + href: None, + img: None, + }), + None, + f, + ), + _ => to_render( + (f)(NodeView::Tag { + tag, + attr: attr.as_deref().map(Cow::Borrowed), + }), + Some(children), + f, + ), + }, + Tag::Icon => match children.get(0) { + Some(Node::Handle { handle, domain }) => to_render( + (f)(NodeView::Icon { + handle: Cow::Borrowed(&handle), + domain: Cow::Borrowed(&domain), + href: None, + img: None, + }), + None, + f, + ), + _ => to_render( + (f)(NodeView::Tag { + tag, + attr: attr.as_deref().map(Cow::Borrowed), + }), + Some(children), + f, + ), + }, + tag => to_render( + (f)(NodeView::Tag { + tag, + attr: attr.as_deref().map(Cow::Borrowed), + }), + Some(children), + f, + ), + }, Node::Url { href } => to_render( (f)(NodeView::Url { href: Cow::Borrowed(&href),