mirror of
https://github.com/YGGverse/ggemtext.git
synced 2026-03-31 17:15:33 +00:00
remove middle-level code api, update comments
This commit is contained in:
parent
d739181a76
commit
84c72ae3a3
9 changed files with 13 additions and 57 deletions
|
|
@ -1,33 +1,5 @@
|
||||||
pub mod error;
|
|
||||||
pub mod inline;
|
pub mod inline;
|
||||||
pub mod multiline;
|
pub mod multiline;
|
||||||
|
|
||||||
pub use error::Error;
|
pub use inline::Inline;
|
||||||
use inline::Inline;
|
pub use multiline::Multiline;
|
||||||
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)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -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}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub struct Inline {
|
||||||
impl Inline {
|
impl Inline {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Parse `Self` from string
|
/// Parse `Self` from line 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(
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub struct Multiline {
|
||||||
impl Multiline {
|
impl Multiline {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Search in line for tag open,
|
/// Search in line string 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> {
|
||||||
if line.starts_with(TAG) {
|
if line.starts_with(TAG) {
|
||||||
|
|
@ -35,7 +35,7 @@ impl Multiline {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Continue preformatted buffer from line,
|
/// Continue preformatted buffer from line string,
|
||||||
/// set `completed` as True on close tag found
|
/// set `completed` as True on close tag found
|
||||||
pub fn continue_from(&mut self, line: &str) -> Result<(), Error> {
|
pub fn continue_from(&mut self, line: &str) -> Result<(), Error> {
|
||||||
// Make sure buffer not completed yet
|
// Make sure buffer not completed yet
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ pub struct Header {
|
||||||
impl Header {
|
impl Header {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Parse `Self` from string
|
/// Parse `Self` from line 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(
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ pub struct Link {
|
||||||
impl Link {
|
impl Link {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Parse `Self` from string
|
/// Parse `Self` from line 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;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub struct List {
|
||||||
impl List {
|
impl List {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Parse `Self` from string
|
/// Parse `Self` from line 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(
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ pub struct Quote {
|
||||||
impl Quote {
|
impl Quote {
|
||||||
// Constructors
|
// Constructors
|
||||||
|
|
||||||
/// Parse `Self` from string
|
/// Parse `Self` from line 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(
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use ggemtext::line::{
|
use ggemtext::line::{
|
||||||
code::{inline::Inline, multiline::Multiline, Code},
|
code::{inline::Inline, multiline::Multiline},
|
||||||
header::{Header, Level},
|
header::{Header, Level},
|
||||||
link::Link,
|
link::Link,
|
||||||
list::List,
|
list::List,
|
||||||
|
|
@ -36,7 +36,7 @@ fn gemtext() {
|
||||||
// Parse document by line
|
// Parse document by line
|
||||||
for line in gemtext.lines() {
|
for line in gemtext.lines() {
|
||||||
// Inline code
|
// Inline code
|
||||||
if let Some(result) = Code::inline_from(line) {
|
if let Some(result) = Inline::from(line) {
|
||||||
code_inline.push(result);
|
code_inline.push(result);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -44,13 +44,13 @@ fn gemtext() {
|
||||||
// Multiline code
|
// Multiline code
|
||||||
match code_multiline_buffer {
|
match code_multiline_buffer {
|
||||||
None => {
|
None => {
|
||||||
if let Some(code) = Code::multiline_begin_from(line) {
|
if let Some(code) = Multiline::begin_from(line) {
|
||||||
code_multiline_buffer = Some(code);
|
code_multiline_buffer = Some(code);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(ref mut result) => {
|
Some(ref mut result) => {
|
||||||
assert!(Code::multiline_continue_from(result, line).is_ok());
|
assert!(Multiline::continue_from(result, line).is_ok());
|
||||||
if result.completed {
|
if result.completed {
|
||||||
code_multiline.push(code_multiline_buffer.take().unwrap());
|
code_multiline.push(code_multiline_buffer.take().unwrap());
|
||||||
code_multiline_buffer = None;
|
code_multiline_buffer = None;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue