Skip to content

Commit

Permalink
remove middle-level code api, update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yggverse committed Dec 3, 2024
1 parent d739181 commit 84c72ae
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 57 deletions.
32 changes: 2 additions & 30 deletions src/line/code.rs
Original file line number Diff line number Diff line change
@@ -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;
16 changes: 0 additions & 16 deletions src/line/code/error.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/line/code/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/line/code/multiline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/line/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/line/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/line/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/line/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions tests/integration.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -36,21 +36,21 @@ 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;
}

// 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;
Expand Down

0 comments on commit 84c72ae

Please sign in to comment.