mirror of
https://github.com/YGGverse/ggemtext.git
synced 2026-03-31 17:15:33 +00:00
Handle the case where links are delimited from alts by a tab
This commit is contained in:
parent
2a51b67387
commit
a358bcbd61
1 changed files with 14 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
use glib::{DateTime, TimeZone, Uri, UriFlags};
|
use glib::{DateTime, TimeZone, Uri, UriFlags};
|
||||||
|
const SEP: [char; 2] = [' ', '\t'];
|
||||||
const S: char = ' ';
|
const S: char = ' ';
|
||||||
|
|
||||||
pub const TAG: &str = "=>";
|
pub const TAG: &str = "=>";
|
||||||
|
|
@ -18,8 +19,8 @@ impl Link {
|
||||||
|
|
||||||
/// Parse `Self` from line string
|
/// Parse `Self` from line string
|
||||||
pub fn parse(line: &str) -> Option<Self> {
|
pub fn parse(line: &str) -> Option<Self> {
|
||||||
let l = line.strip_prefix(TAG)?.trim();
|
let l = line.strip_prefix(TAG)?.trim_matches(&SEP);
|
||||||
let u = l.find(S).map_or(l, |i| &l[..i]);
|
let u = l.find(|c: char| SEP.contains(&c)).map_or(l, |i| &l[..i]);
|
||||||
if u.is_empty() {
|
if u.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
@ -117,3 +118,14 @@ fn test() {
|
||||||
|
|
||||||
assert_eq!(link.to_source(), SOURCE);
|
assert_eq!(link.to_source(), SOURCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_tab() {
|
||||||
|
use crate::line::Link;
|
||||||
|
|
||||||
|
const SOURCE: &str = "=> gemlog/\tMy gemlog - verbose ramblings";
|
||||||
|
|
||||||
|
let link = Link::parse(SOURCE).unwrap();
|
||||||
|
assert_eq!(link.alt, Some("My gemlog - verbose ramblings".to_string()));
|
||||||
|
assert_eq!(link.url, "gemlog/");
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue