remove middle-level code api, update comments

This commit is contained in:
yggverse 2024-12-03 18:55:44 +02:00
parent d739181a76
commit 84c72ae3a3
9 changed files with 13 additions and 57 deletions

View file

@ -1,33 +1,5 @@
pub mod error;
pub mod inline;
pub mod multiline;
pub use error::Error;
use inline::Inline;
use multiline::Multiline;
pub struct Code {
// nothing yet..
}
impl Code {
// Constructors
/// Parse inline `Self` from string
pub fn inline_from(line: &str) -> Option<Inline> {
Inline::from(line)
}
/// Begin multi-line parse `Self` from string
pub fn multiline_begin_from(line: &str) -> Option<Multiline> {
Multiline::begin_from(line)
}
/// Continue multi-line parse `Self` from string
pub fn multiline_continue_from(this: &mut Multiline, line: &str) -> Result<(), Error> {
match Multiline::continue_from(this, line) {
Ok(()) => Ok(()),
Err(e) => Err(Error::Multiline(e)),
}
}
}
pub use inline::Inline;
pub use multiline::Multiline;

View file

@ -1,16 +0,0 @@
use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
pub enum Error {
Multiline(crate::line::code::multiline::Error),
}
impl Display for Error {
fn fmt(&self, f: &mut Formatter) -> Result {
match self {
Self::Multiline(e) => {
write!(f, "Multiline error: {e}")
}
}
}
}

View file

@ -8,7 +8,7 @@ pub struct Inline {
impl Inline {
// Constructors
/// Parse `Self` from string
/// Parse `Self` from line string
pub fn from(line: &str) -> Option<Self> {
// Parse line
let regex = Regex::split_simple(

View file

@ -16,7 +16,7 @@ pub struct Multiline {
impl Multiline {
// Constructors
/// Search in line for tag open,
/// Search in line string for tag open,
/// return Self constructed on success or None
pub fn begin_from(line: &str) -> Option<Self> {
if line.starts_with(TAG) {
@ -35,7 +35,7 @@ impl Multiline {
None
}
/// Continue preformatted buffer from line,
/// Continue preformatted buffer from line string,
/// set `completed` as True on close tag found
pub fn continue_from(&mut self, line: &str) -> Result<(), Error> {
// Make sure buffer not completed yet

View file

@ -16,7 +16,7 @@ pub struct Header {
impl Header {
// Constructors
/// Parse `Self` from string
/// Parse `Self` from line string
pub fn from(line: &str) -> Option<Self> {
// Parse line
let regex = Regex::split_simple(

View file

@ -11,7 +11,7 @@ pub struct Link {
impl Link {
// Constructors
/// Parse `Self` from string
/// Parse `Self` from line string
pub fn from(line: &str, base: Option<&Uri>, timezone: Option<&TimeZone>) -> Option<Self> {
// Define initial values
let mut alt = None;

View file

@ -8,7 +8,7 @@ pub struct List {
impl List {
// Constructors
/// Parse `Self` from string
/// Parse `Self` from line string
pub fn from(line: &str) -> Option<Self> {
// Parse line
let regex = Regex::split_simple(

View file

@ -8,7 +8,7 @@ pub struct Quote {
impl Quote {
// Constructors
/// Parse `Self` from string
/// Parse `Self` from line string
pub fn from(line: &str) -> Option<Self> {
// Parse line
let regex = Regex::split_simple(

View file

@ -1,5 +1,5 @@
use ggemtext::line::{
code::{inline::Inline, multiline::Multiline, Code},
code::{inline::Inline, multiline::Multiline},
header::{Header, Level},
link::Link,
list::List,
@ -36,7 +36,7 @@ fn gemtext() {
// Parse document by line
for line in gemtext.lines() {
// Inline code
if let Some(result) = Code::inline_from(line) {
if let Some(result) = Inline::from(line) {
code_inline.push(result);
continue;
}
@ -44,13 +44,13 @@ fn gemtext() {
// Multiline code
match code_multiline_buffer {
None => {
if let Some(code) = Code::multiline_begin_from(line) {
if let Some(code) = Multiline::begin_from(line) {
code_multiline_buffer = Some(code);
continue;
}
}
Some(ref mut result) => {
assert!(Code::multiline_continue_from(result, line).is_ok());
assert!(Multiline::continue_from(result, line).is_ok());
if result.completed {
code_multiline.push(code_multiline_buffer.take().unwrap());
code_multiline_buffer = None;