Merge branch 'xhtml-public' into 'main'

Made a few structs public relating to xhtml-im and added docs comments.

See merge request xmpp-rs/xmpp-rs!284
This commit is contained in:
Werner Kroneman 2024-04-17 14:54:27 +00:00
commit bedda17dd3
1 changed files with 58 additions and 10 deletions

View File

@ -104,13 +104,17 @@ impl From<XhtmlIm> for Element {
}
}
/// A child node of a <body> element.
#[derive(Debug, Clone)]
enum Child {
pub enum Child {
/// An XHTML-IM tag.
Tag(Tag),
/// A text node.
Text(String),
}
impl Child {
/// Convert into an HTML string.
fn into_html(self) -> String {
match self {
Child::Tag(tag) => tag.into_html(),
@ -119,13 +123,17 @@ impl Child {
}
}
/// A CSS property.
#[derive(Debug, Clone)]
struct Property {
key: String,
value: String,
pub struct Property {
/// The name of the property.
pub key: String,
/// The value of the property.
pub value: String,
}
type Css = Vec<Property>;
/// A CSS style attribute value, as a list of properties.
pub type Css = Vec<Property>;
fn get_style_string(style: Css) -> Option<String> {
let mut result = vec![];
@ -138,11 +146,15 @@ fn get_style_string(style: Css) -> Option<String> {
Some(result.join("; "))
}
/// An html body (as part of an XMPP message, under a <html> element).
#[derive(Debug, Clone)]
struct Body {
style: Css,
xml_lang: Option<String>,
children: Vec<Child>,
pub struct Body {
/// The CSS style of the body.
pub style: Css,
/// The language of the body.
pub xml_lang: Option<String>,
/// The children of this body.
pub children: Vec<Child>,
}
impl TryFrom<Element> for Body {
@ -175,53 +187,89 @@ impl From<Body> for Element {
}
}
/// An xhtml tag.
#[derive(Debug, Clone)]
enum Tag {
pub enum Tag {
/// An <a> (link/anchor) tag.
A {
/// The link target.
href: Option<String>,
/// The CSS style of the link.
style: Css,
/// The media type of the linked resource.
type_: Option<String>,
/// The children of this tag.
children: Vec<Child>,
},
/// A <blockquote> tag.
Blockquote {
/// The CSS style of the blockquote.
style: Css,
/// The children of this tag.
children: Vec<Child>,
},
/// A <br> (line break) tag.
Br,
/// A <cite> (citation) tag.
Cite {
/// The CSS style of the citation.
style: Css,
/// The children of this tag.
children: Vec<Child>,
},
/// An <em> (emphasis) tag.
Em {
/// The children of this tag.
children: Vec<Child>,
},
/// An <img> (image) tag.
Img {
/// The source of the image.
src: Option<String>,
/// The alt text (for accessibility).
alt: Option<String>,
}, // TODO: height, width, style
/// An <li> (list item) tag.
Li {
/// The CSS style of the list item.
style: Css,
/// The children of this tag.
children: Vec<Child>,
},
/// An <ol> (ordered list) tag.
Ol {
/// The CSS style of the ordered list.
style: Css,
/// The children of this tag.
children: Vec<Child>,
},
/// A <p> (paragraph) tag.
P {
/// The CSS style of the paragraph.
style: Css,
/// The children of this tag.
children: Vec<Child>,
},
/// A <span> tag.
Span {
/// The CSS style of the span.
style: Css,
/// The children of this tag.
children: Vec<Child>,
},
/// A <strong> (strong emphasis) tag.
Strong {
/// The children of this tag.
children: Vec<Child>,
},
/// A <ul> (unordered list) tag.
Ul {
/// The CSS style of the unordered list.
style: Css,
/// The children of this tag.
children: Vec<Child>,
},
/// An unknown tag, with its children.
Unknown(Vec<Child>),
}