gemini: add document builder
This commit is contained in:
parent
8495c5ab0d
commit
851d7925c5
|
@ -2,6 +2,58 @@
|
|||
/// here: https://gemini.circumlunar.space/docs/specification.html
|
||||
use std::io::Write;
|
||||
|
||||
/// Build a gemini document up from a series of nodes.
|
||||
#[derive(Default)]
|
||||
pub struct Builder {
|
||||
nodes: Vec<Node>,
|
||||
}
|
||||
|
||||
impl Builder {
|
||||
pub fn new() -> Builder {
|
||||
Builder::default()
|
||||
}
|
||||
|
||||
pub fn text<T: Into<String>>(mut self, data: T) -> Builder {
|
||||
self.nodes.push(Node::Text(data.into()));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn link<T: Into<String>>(mut self, to: T, name: Option<String>) -> Builder {
|
||||
self.nodes.push(Node::Link {
|
||||
to: to.into(),
|
||||
name: name,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
pub fn preformatted<T: Into<String>>(mut self, data: T) -> Builder {
|
||||
self.nodes.push(Node::Preformatted(data.into()));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn heading<T: Into<String>>(mut self, level: u8, body: T) -> Builder {
|
||||
self.nodes.push(Node::Heading {
|
||||
level: level,
|
||||
body: body.into(),
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
pub fn list_item<T: Into<String>>(mut self, item: T) -> Builder {
|
||||
self.nodes.push(Node::ListItem(item.into()));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn quote<T: Into<String>>(mut self, body: T) -> Builder {
|
||||
self.nodes.push(Node::Quote(body.into()));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Vec<Node> {
|
||||
self.nodes
|
||||
}
|
||||
}
|
||||
|
||||
/// Individual nodes of the document. Each node correlates to a line in the file.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum Node {
|
||||
|
|
Loading…
Reference in New Issue