add comments

This commit is contained in:
yggverse 2024-12-03 18:43:34 +02:00
parent 2e0a1ae3ef
commit 155247a2ea
7 changed files with 30 additions and 3 deletions

View file

@ -11,16 +11,19 @@ pub struct Code {
} }
impl Code { impl Code {
// Inline // Constructors
/// Parse inline `Self` from string
pub fn inline_from(line: &str) -> Option<Inline> { pub fn inline_from(line: &str) -> Option<Inline> {
Inline::from(line) Inline::from(line)
} }
// Multiline /// Begin multi-line parse `Self` from string
pub fn multiline_begin_from(line: &str) -> Option<Multiline> { pub fn multiline_begin_from(line: &str) -> Option<Multiline> {
Multiline::begin_from(line) Multiline::begin_from(line)
} }
/// Continue multi-line parse `Self` from string
pub fn multiline_continue_from(this: &mut Multiline, line: &str) -> Result<(), Error> { pub fn multiline_continue_from(this: &mut Multiline, line: &str) -> Result<(), Error> {
match Multiline::continue_from(this, line) { match Multiline::continue_from(this, line) {
Ok(()) => Ok(()), Ok(()) => Ok(()),

View file

@ -1,10 +1,14 @@
use glib::{Regex, RegexCompileFlags, RegexMatchFlags}; use glib::{Regex, RegexCompileFlags, RegexMatchFlags};
/// Inline [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
pub struct Inline { pub struct Inline {
pub value: String, pub value: String,
} }
impl Inline { impl Inline {
// Constructors
/// Parse `Self` from string
pub fn from(line: &str) -> Option<Self> { pub fn from(line: &str) -> Option<Self> {
// Parse line // Parse line
let regex = Regex::split_simple( let regex = Regex::split_simple(

View file

@ -1,9 +1,12 @@
pub mod error; pub mod error;
pub use error::Error; pub use error::Error;
// Shared defaults
pub const NEW_LINE: char = '\n'; pub const NEW_LINE: char = '\n';
pub const TAG: &str = "```"; pub const TAG: &str = "```";
/// Multi-line [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
pub struct Multiline { pub struct Multiline {
pub alt: Option<String>, pub alt: Option<String>,
pub value: String, pub value: String,
@ -11,6 +14,8 @@ pub struct Multiline {
} }
impl Multiline { impl Multiline {
// Constructors
/// Search in line for tag open, /// Search in line for tag open,
/// return Self constructed on success or None /// return Self constructed on success or None
pub fn begin_from(line: &str) -> Option<Self> { pub fn begin_from(line: &str) -> Option<Self> {

View file

@ -1,17 +1,22 @@
use glib::{GString, Regex, RegexCompileFlags, RegexMatchFlags}; use glib::{GString, Regex, RegexCompileFlags, RegexMatchFlags};
/// [Header](https://geminiprotocol.net/docs/gemtext-specification.gmi#heading-lines) type holder
pub enum Level { pub enum Level {
H1, H1,
H2, H2,
H3, H3,
} }
/// [Header](https://geminiprotocol.net/docs/gemtext-specification.gmi#heading-lines) entity holder
pub struct Header { pub struct Header {
pub value: GString, pub value: GString,
pub level: Level, pub level: Level,
} }
impl Header { impl Header {
// Constructors
/// Parse `Self` from string
pub fn from(line: &str) -> Option<Self> { pub fn from(line: &str) -> Option<Self> {
// Parse line // Parse line
let regex = Regex::split_simple( let regex = Regex::split_simple(

View file

@ -1,5 +1,6 @@
use glib::{DateTime, Regex, RegexCompileFlags, RegexMatchFlags, TimeZone, Uri, UriFlags}; use glib::{DateTime, Regex, RegexCompileFlags, RegexMatchFlags, TimeZone, Uri, UriFlags};
/// [Link](https://geminiprotocol.net/docs/gemtext-specification.gmi#link-lines) entity holder
pub struct Link { pub struct Link {
pub alt: Option<String>, // [optional] alternative link description pub alt: Option<String>, // [optional] alternative link description
pub is_external: Option<bool>, // [optional] external link indication, on base option provided pub is_external: Option<bool>, // [optional] external link indication, on base option provided
@ -8,6 +9,9 @@ pub struct Link {
} }
impl Link { impl Link {
// Constructors
/// Parse `Self` from string
pub fn from(line: &str, base: Option<&Uri>, timezone: Option<&TimeZone>) -> Option<Self> { pub fn from(line: &str, base: Option<&Uri>, timezone: Option<&TimeZone>) -> Option<Self> {
// Define initial values // Define initial values
let mut alt = None; let mut alt = None;

View file

@ -1,11 +1,13 @@
use glib::{Regex, RegexCompileFlags, RegexMatchFlags}; use glib::{Regex, RegexCompileFlags, RegexMatchFlags};
/// [List item](https://geminiprotocol.net/docs/gemtext-specification.gmi#list-items) /// [List](https://geminiprotocol.net/docs/gemtext-specification.gmi#list-items) entity holder
pub struct List { pub struct List {
pub value: String, pub value: String,
} }
impl List { impl List {
// Constructors
/// Parse `Self` from string /// Parse `Self` from string
pub fn from(line: &str) -> Option<Self> { pub fn from(line: &str) -> Option<Self> {
// Parse line // Parse line

View file

@ -1,10 +1,14 @@
use glib::{Regex, RegexCompileFlags, RegexMatchFlags}; use glib::{Regex, RegexCompileFlags, RegexMatchFlags};
/// [Quote](https://geminiprotocol.net/docs/gemtext-specification.gmi#quote-lines) entity holder
pub struct Quote { pub struct Quote {
pub value: String, pub value: String,
} }
impl Quote { impl Quote {
// Constructors
/// Parse `Self` from string
pub fn from(line: &str) -> Option<Self> { pub fn from(line: &str) -> Option<Self> {
// Parse line // Parse line
let regex = Regex::split_simple( let regex = Regex::split_simple(