styling: added preliminary styling application

This commit is contained in:
2017-08-25 17:58:25 +02:00
parent 02f5aee141
commit e4966a6536
4 changed files with 113 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::collections::{HashMap,HashSet};
use std;
use css;
@@ -7,17 +7,30 @@ pub struct Attr {
attrs: HashMap<String, String>,
}
struct EData {
name: String,
attr: Attr,
pub struct EData {
pub name: String,
pub attr: Attr,
}
struct SData {
impl EData {
pub fn id(&self) -> Option<&String> {
self.attr.attrs.get("id")
}
pub fn classes(&self) -> HashSet<&str> {
match self.attr.attrs.get("class") {
Some(classlist) => classlist.split(' ').collect(),
None => HashSet::new()
}
}
}
pub struct SData {
attr: Attr,
content: css::Stylesheet,
}
enum NType {
pub enum NType {
Text(String),
Comment(String),
Element(EData),
@@ -25,8 +38,8 @@ enum NType {
}
pub struct Node {
children: Vec<Node>,
ntype: NType,
pub children: Vec<Node>,
pub ntype: NType,
}
pub fn text(d: String) -> Node {