mirror of
https://github.com/YGGverse/ggemtext.git
synced 2026-03-31 17:15:33 +00:00
skip regex operations on tag mismatch subject
This commit is contained in:
parent
7345400172
commit
83ec663929
4 changed files with 18 additions and 1 deletions
|
|
@ -3,3 +3,5 @@ pub mod multiline;
|
||||||
|
|
||||||
pub use inline::Inline;
|
pub use inline::Inline;
|
||||||
pub use multiline::Multiline;
|
pub use multiline::Multiline;
|
||||||
|
|
||||||
|
pub const TAG: &str = "```";
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use super::TAG;
|
||||||
use glib::{Regex, RegexCompileFlags, RegexMatchFlags};
|
use glib::{Regex, RegexCompileFlags, RegexMatchFlags};
|
||||||
|
|
||||||
/// Inline [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
|
/// Inline [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
|
||||||
|
|
@ -10,6 +11,12 @@ impl Inline {
|
||||||
|
|
||||||
/// Parse `Self` from line string
|
/// Parse `Self` from line string
|
||||||
pub fn from(line: &str) -> Option<Self> {
|
pub fn from(line: &str) -> Option<Self> {
|
||||||
|
// Skip next operations on prefix and postfix mismatch `TAG`
|
||||||
|
// * replace regex implementation @TODO
|
||||||
|
if !line.starts_with(TAG) && !line.ends_with(TAG) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
// Parse line
|
// Parse line
|
||||||
let regex = Regex::split_simple(
|
let regex = Regex::split_simple(
|
||||||
r"^`{3}([^`]+)`{3}$",
|
r"^`{3}([^`]+)`{3}$",
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
|
use super::TAG;
|
||||||
|
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub use error::Error;
|
pub use error::Error;
|
||||||
|
|
||||||
// Shared defaults
|
// Shared defaults
|
||||||
|
|
||||||
pub const NEW_LINE: char = '\n';
|
pub const NEW_LINE: char = '\n';
|
||||||
pub const TAG: &str = "```";
|
|
||||||
|
|
||||||
/// Multi-line [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
|
/// Multi-line [preformatted](https://geminiprotocol.net/docs/gemtext-specification.gmi#in-pre-formatted-mode) entity holder
|
||||||
pub struct Multiline {
|
pub struct Multiline {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
use glib::{DateTime, Regex, RegexCompileFlags, RegexMatchFlags, TimeZone, Uri, UriFlags};
|
use glib::{DateTime, Regex, RegexCompileFlags, RegexMatchFlags, TimeZone, Uri, UriFlags};
|
||||||
|
|
||||||
|
pub const TAG: &str = "=>";
|
||||||
|
|
||||||
/// [Link](https://geminiprotocol.net/docs/gemtext-specification.gmi#link-lines) entity holder
|
/// [Link](https://geminiprotocol.net/docs/gemtext-specification.gmi#link-lines) entity holder
|
||||||
pub struct Link {
|
pub struct Link {
|
||||||
pub alt: Option<String>, // [optional] alternative link description
|
pub alt: Option<String>, // [optional] alternative link description
|
||||||
|
|
@ -12,6 +14,11 @@ impl Link {
|
||||||
|
|
||||||
/// Parse `Self` from line 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> {
|
||||||
|
// Skip next operations on prefix mismatch
|
||||||
|
// * replace regex implementation @TODO
|
||||||
|
if !line.starts_with(TAG) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
// Define initial values
|
// Define initial values
|
||||||
let mut alt = None;
|
let mut alt = None;
|
||||||
let mut timestamp = None;
|
let mut timestamp = None;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue