-- Leo's gemini proxy
-- Connecting to typed-hole.org:1965...
-- Connected
-- Sending request
-- Meta line: 20 text/gemini
commit c8675c834f32afb25b55d582aae17b955bfc5ad5
Author: Julien Blanchard <julien@typed-hole.org>
Date: Wed May 13 10:30:43 2020 +0200
Don't parse Gemini plain text files, bring colors back to gopher
diff --git a/Cargo.lock b/Cargo.lock
index 4427890..4b9c40f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -136,7 +136,7 @@ dependencies = [
[[package]]
name = "castor"
-version = "0.8.2"
+version = "0.8.3"
dependencies = [
"ansi-parser 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index 2fbd732..4055f85 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "castor"
-version = "0.8.2"
+version = "0.8.3"
authors = ["Julien Blanchard <julien@typed-hole.org>"]
edition = "2018"
diff --git a/src/draw.rs b/src/draw.rs
index 072b44c..68f712d 100644
--- a/src/draw.rs
+++ b/src/draw.rs
@@ -120,29 +120,20 @@ pub fn gemini_content(
buffer
}
-pub fn gemini_text_content(
- gui: &Arc<Gui>,
- content: Vec<Result<crate::gemini::parser::TextElement, crate::gemini::parser::ParseError>>,
-) -> TextBuffer {
+pub fn gemini_text_content(gui: &Arc<Gui>, content: std::str::Lines) -> TextBuffer {
let content_view = gui.content_view();
let buffer = content_view.get_buffer().unwrap();
- for el in content {
- match el {
- Ok(crate::gemini::parser::TextElement::Text(text)) => {
- let mut end_iter = buffer.get_end_iter();
- buffer.insert_markup(
- &mut end_iter,
- &format!(
- "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
- crate::settings::text_color(),
- escape_text(&text)
- ),
- );
- }
- Ok(_) => (),
- Err(_) => println!("Something failed."),
- }
+ for line in content {
+ let mut end_iter = buffer.get_end_iter();
+ buffer.insert_markup(
+ &mut end_iter,
+ &format!(
+ "<span foreground=\"{}\" font_family=\"monospace\">{}</span>\n",
+ crate::settings::text_color(),
+ escape_text(&line)
+ ),
+ );
}
buffer
}
@@ -164,13 +155,19 @@ pub fn gopher_content(
"font_family=\"serif\""
};
+ let text = if text.contains("<span") {
+ text
+ } else {
+ escape_text(&text)
+ };
+
buffer.insert_markup(
&mut end_iter,
&format!(
"<span foreground=\"{}\" {}>{}</span>\n",
crate::settings::text_color(),
font_family,
- escape_text(&text)
+ text
),
);
}
diff --git a/src/main.rs b/src/main.rs
index 5b77a4f..b88d0ca 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -204,13 +204,13 @@ pub fn visit_url<T: AbsoluteUrl + Protocol>(gui: &Arc<Gui>, url: T) {
let content_str =
String::from_utf8_lossy(&new_content).to_string();
- let parsed_content = gemini::parser::parse(content_str);
clear_buffer(&content_view);
if meta == "text/gemini" {
+ let parsed_content = gemini::parser::parse(content_str);
draw::gemini_content(&gui, parsed_content);
} else {
// just a text file
- draw::gemini_text_content(&gui, parsed_content);
+ draw::gemini_text_content(&gui, content_str.lines());
}
content_view.show_all();
---
Served by Pollux Gemini Server.
-- Response ended
-- Page fetched on Sun May 19 06:34:24 2024