-- Leo's gemini proxy

-- Connecting to typed-hole.org:1965...

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

commit f27ff4292222a1e5dacc5afcbc38bcc063564b3b

Author: Julien Blanchard <julien@typed-hole.org>

Date: Fri Apr 17 15:14:49 2020 +0200


[gopher] re-highlight links in text files


diff --git a/src/gopher/link.rs b/src/gopher/link.rs

index 2e2a352..f7949be 100644

--- a/src/gopher/link.rs

+++ b/src/gopher/link.rs

@@ -54,6 +54,23 @@ impl FromStr for Link {

} else {

Err(ParseError)

}

+ } else if line.starts_with('[') {

+ let mut url = String::from(line);

+ let url = url.split_off(4);

+ let label = String::from(line);

+

+ match make_link(url, label) {

+ Some(link) => Ok(link),

+ None => Err(ParseError),

+ }

+ } else if line.contains("://") {

+ let url = String::from(line);

+ let label = String::from(line);

+

+ match make_link(url, label) {

+ Some(link) => Ok(link),

+ None => Err(ParseError),

+ }

} else if line.starts_with('h') {

let label = els.next();

let url = els.next();

@@ -74,22 +91,13 @@ impl FromStr for Link {

} else {

Err(ParseError)

}

- } else if line.starts_with('[') {

- let mut url = String::from(line);

- let url = url.split_off(4);

- let label = String::from(line);

-

- match make_link(url, label) {

- Some(link) => Ok(link),

- None => Err(ParseError),

- }

} else {

Err(ParseError)

}

}

}


-fn make_link(url: String, label: String) -> Option<Link> {

+pub fn make_link(url: String, label: String) -> Option<Link> {

match Url::parse(&url) {

Ok(url) => match url.scheme() {

"gemini" => Some(Link::Gemini(url, label)),

diff --git a/src/gopher/parser.rs b/src/gopher/parser.rs

index d2076ad..b316fda 100644

--- a/src/gopher/parser.rs

+++ b/src/gopher/parser.rs

@@ -19,6 +19,7 @@ impl FromStr for TextElement {

fn from_str(line: &str) -> Result<TextElement, ParseError> {

let els = line.split('\t');

if els.count() >= 2 {

+ // Gophermap line

if line.starts_with('0') || line.starts_with('1') {

Ok(TextElement::LinkItem(colors::cleanup(line)))

} else if line.starts_with('i') {

@@ -47,7 +48,14 @@ impl FromStr for TextElement {

Ok(TextElement::Text(colors::colorize(line)))

}

} else {

- Ok(TextElement::Text(colors::colorize(line)))

+ // Text line

+ if line.contains("gopher://") {

+ Ok(TextElement::LinkItem(String::from(line)))

+ } else if line.contains("http://") || line.contains("https://") {

+ Ok(TextElement::ExternalLinkItem(String::from(line)))

+ } else {

+ Ok(TextElement::Text(colors::colorize(line)))

+ }

}

}

}



---

Served by Pollux Gemini Server.

-- Response ended

-- Page fetched on Sun May 19 07:58:39 2024