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