fix sources location

This commit is contained in:
yggverse 2024-10-18 19:19:39 +03:00
parent 7df3bfeb91
commit d42af120ca
11 changed files with 1 additions and 1 deletions

29
src/line/code/inline.rs Normal file
View file

@ -0,0 +1,29 @@
use gtk::glib::{GString, Regex, RegexCompileFlags, RegexMatchFlags};
pub struct Inline {
pub value: GString,
}
impl Inline {
pub fn from(line: &str) -> Option<Self> {
// Parse line
let regex = Regex::split_simple(
r"^`{3}([^`]*)`{3}$",
line,
RegexCompileFlags::DEFAULT,
RegexMatchFlags::DEFAULT,
);
// Detect value
let value = regex.get(1)?;
if value.trim().is_empty() {
return None;
}
// Result
Some(Self {
value: GString::from(value.as_str()),
})
}
}

View file

@ -0,0 +1,46 @@
use gtk::glib::GString;
pub struct Multiline {
pub alt: Option<GString>,
pub buffer: Vec<GString>,
pub completed: bool,
}
impl Multiline {
// Search in line for tag open,
// return Self constructed on success or None
pub fn begin_from(line: &str) -> Option<Self> {
if line.starts_with("```") {
let alt = line.trim_start_matches("```");
return Some(Self {
alt: match alt.trim().is_empty() {
true => None,
false => Some(GString::from(alt)),
},
buffer: Vec::new(),
completed: false,
});
}
None
}
// Continue preformatted buffer from line,
// set `completed` as True on close tag found
pub fn continue_from(&mut self, line: &str) {
// Make sure buffer not completed yet
if self.completed {
panic!("Could not continue as completed") // @TODO handle
}
// Line contain close tag
if line.ends_with("```") {
self.completed = true;
}
// Append data to the buffer, trim close tag on exists
self.buffer
.push(GString::from(line.trim_end_matches("```")));
}
}