mirror of
https://github.com/YGGverse/ggemtext.git
synced 2026-04-01 01:25:34 +00:00
initial commit
This commit is contained in:
parent
c608e711c4
commit
7df3bfeb91
11 changed files with 334 additions and 0 deletions
29
ggemtext/src/line/code/inline.rs
Normal file
29
ggemtext/src/line/code/inline.rs
Normal 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()),
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue