pub struct Document { /* private fields */ }Expand description
Represents a Gemini document.
Provides convenient methods for programatically creation of Gemini documents.
Implementations§
Source§impl Document
impl Document
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty Gemini Document.
§Examples
let document = kochab::Document::new();
assert_eq!(document.to_string(), "");Sourcepub fn add_blank_line(&mut self) -> &mut Self
pub fn add_blank_line(&mut self) -> &mut Self
Adds a blank line to the document.
§Examples
let mut document = kochab::Document::new();
document.add_blank_line();
assert_eq!(document.to_string(), "\n");Sourcepub fn add_text(&mut self, text: impl AsRef<str>) -> &mut Self
pub fn add_text(&mut self, text: impl AsRef<str>) -> &mut Self
Adds plain text to the document.
This function allows adding multiple lines at once.
It inserts a whitespace at the beginning of a line if it starts with a character sequence that would make it a non-plain text line (e.g. link, heading etc).
§Examples
let mut document = kochab::Document::new();
document.add_text("hello\n* world!");
assert_eq!(document.to_string(), "hello\n * world!\n");Sourcepub fn add_link<'a, U>(&mut self, uri: U, label: impl Cowy<str>) -> &mut Selfwhere
U: TryInto<URIReference<'a>>,
pub fn add_link<'a, U>(&mut self, uri: U, label: impl Cowy<str>) -> &mut Selfwhere
U: TryInto<URIReference<'a>>,
Adds a link to the document.
uris that fail to parse are substituted with ..
Consecutive newlines in label will be replaced
with a single whitespace.
§Examples
let mut document = kochab::Document::new();
document.add_link("https://wikipedia.org", "Wiki\n\nWiki");
assert_eq!(document.to_string(), "=> https://wikipedia.org/ Wiki Wiki\n");Sourcepub fn add_link_without_label<'a, U>(&mut self, uri: U) -> &mut Selfwhere
U: TryInto<URIReference<'a>>,
pub fn add_link_without_label<'a, U>(&mut self, uri: U) -> &mut Selfwhere
U: TryInto<URIReference<'a>>,
Adds a link to the document, but without a label.
See add_link for details.
§Examples
let mut document = kochab::Document::new();
document.add_link_without_label("https://wikipedia.org");
assert_eq!(document.to_string(), "=> https://wikipedia.org/\n");Sourcepub fn add_preformatted(
&mut self,
preformatted_text: impl AsRef<str>,
) -> &mut Self
pub fn add_preformatted( &mut self, preformatted_text: impl AsRef<str>, ) -> &mut Self
Adds a block of preformatted text.
Lines that start with ``` will be prependend with a whitespace.
§Examples
let mut document = kochab::Document::new();
document.add_preformatted("a\n b\n c");
assert_eq!(document.to_string(), "```\na\n b\n c\n```\n");Sourcepub fn add_preformatted_with_alt(
&mut self,
alt: impl AsRef<str>,
preformatted_text: impl AsRef<str>,
) -> &mut Self
pub fn add_preformatted_with_alt( &mut self, alt: impl AsRef<str>, preformatted_text: impl AsRef<str>, ) -> &mut Self
Adds a block of preformatted text with an alt text.
Consecutive newlines in alt will be replaced
with a single whitespace.
preformatted_text lines that start with ```
will be prependend with a whitespace.
§Examples
let mut document = kochab::Document::new();
document.add_preformatted_with_alt("rust", "fn main() {\n}\n");
assert_eq!(document.to_string(), "```rust\nfn main() {\n}\n```\n");Sourcepub fn add_heading(
&mut self,
level: HeadingLevel,
text: impl Cowy<str>,
) -> &mut Self
pub fn add_heading( &mut self, level: HeadingLevel, text: impl Cowy<str>, ) -> &mut Self
Adds a heading.
Consecutive newlines in text will be replaced
with a single whitespace.
§Examples
use kochab::document::HeadingLevel::H1;
let mut document = kochab::Document::new();
document.add_heading(H1, "Welcome!");
assert_eq!(document.to_string(), "# Welcome!\n");Sourcepub fn add_unordered_list_item(&mut self, text: impl AsRef<str>) -> &mut Self
pub fn add_unordered_list_item(&mut self, text: impl AsRef<str>) -> &mut Self
Adds an unordered list item.
Consecutive newlines in text will be replaced
with a single whitespace.
§Examples
let mut document = kochab::Document::new();
document.add_unordered_list_item("milk");
document.add_unordered_list_item("eggs");
assert_eq!(document.to_string(), "* milk\n* eggs\n");Sourcepub fn add_quote(&mut self, text: impl AsRef<str>) -> &mut Self
pub fn add_quote(&mut self, text: impl AsRef<str>) -> &mut Self
Adds a quote.
This function allows adding multiple quote lines at once.
§Examples
let mut document = kochab::Document::new();
document.add_quote("I think,\ntherefore I am");
assert_eq!(document.to_string(), "> I think,\n> therefore I am\n");Trait Implementations§
Source§impl From<&Document> for Handler
impl From<&Document> for Handler
Source§fn from(doc: &Document) -> Self
fn from(doc: &Document) -> Self
Serve an unchanging response, shorthand for From
This document will be sent in response to any requests that arrive at this
handler. As with all documents, this will be a successful response with a
text/gemini MIME.
This will create a StaticHandler