mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-28 20:14:13 +00:00
complete link parser
This commit is contained in:
parent
860f76ce49
commit
587f40bf32
@ -20,8 +20,8 @@ impl Link {
|
|||||||
// returns new Link struct or None
|
// returns new Link struct or None
|
||||||
pub fn from(line: &str, base: &Uri) -> Option<Link> {
|
pub fn from(line: &str, base: &Uri) -> Option<Link> {
|
||||||
// Init struct members
|
// Init struct members
|
||||||
let alt: Option<GString> = None;
|
let mut alt: Option<GString> = None;
|
||||||
let date: Option<GString> = None;
|
let mut date: Option<GString> = None;
|
||||||
let external: bool;
|
let external: bool;
|
||||||
let link: GString;
|
let link: GString;
|
||||||
let markup: GString;
|
let markup: GString;
|
||||||
@ -29,7 +29,7 @@ impl Link {
|
|||||||
|
|
||||||
// Parse line
|
// Parse line
|
||||||
let parsed = Regex::split_simple(
|
let parsed = Regex::split_simple(
|
||||||
r"^=>\s*([^\s]+)(\s(\d{4}-\d{2}-\d{2}))?(\s(.+))?$",
|
r"^=>\s*([^\s]+)\s+(\d{4}-\d{2}-\d{2})?\s*(.+)?$",
|
||||||
line,
|
line,
|
||||||
RegexCompileFlags::DEFAULT,
|
RegexCompileFlags::DEFAULT,
|
||||||
RegexMatchFlags::DEFAULT,
|
RegexMatchFlags::DEFAULT,
|
||||||
@ -48,7 +48,7 @@ impl Link {
|
|||||||
match Uri::parse(&resolved, UriFlags::NONE) {
|
match Uri::parse(&resolved, UriFlags::NONE) {
|
||||||
Ok(object) => {
|
Ok(object) => {
|
||||||
// Set external status
|
// Set external status
|
||||||
external = object.host() == base.host();
|
external = object.host() != base.host();
|
||||||
|
|
||||||
// Set struct URI
|
// Set struct URI
|
||||||
uri = object;
|
uri = object;
|
||||||
@ -62,14 +62,23 @@ impl Link {
|
|||||||
None => return None,
|
None => return None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create link name based on external status, date and alt values
|
||||||
|
let mut name = Vec::new();
|
||||||
|
|
||||||
|
if external {
|
||||||
|
name.push("⇖".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
// Date
|
// Date
|
||||||
if let Some(date) = parsed.get(2) {
|
if let Some(this) = parsed.get(2) {
|
||||||
// date = date.as_str();
|
date = Some(GString::from(this.to_string()));
|
||||||
|
name.push(this.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Alt
|
// Alt
|
||||||
if let Some(alt) = parsed.get(3) {
|
if let Some(this) = parsed.get(3) {
|
||||||
// alt = alt.as_str();
|
alt = Some(GString::from(this.to_string()));
|
||||||
|
name.push(this.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Markup
|
// Markup
|
||||||
@ -77,7 +86,7 @@ impl Link {
|
|||||||
"<a href=\"{}\" title=\"{}\"><span underline=\"none\">{}</span></a>\n",
|
"<a href=\"{}\" title=\"{}\"><span underline=\"none\">{}</span></a>\n",
|
||||||
markup_escape_text(&uri.to_str()), // use resolved address for href
|
markup_escape_text(&uri.to_str()), // use resolved address for href
|
||||||
markup_escape_text(&link), // show original address for title
|
markup_escape_text(&link), // show original address for title
|
||||||
markup_escape_text(&link), // @TODO
|
markup_escape_text(&name.join(" ")),
|
||||||
));
|
));
|
||||||
|
|
||||||
Some(Self {
|
Some(Self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user