-- Leo's gemini proxy

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

-- Connected

-- Sending request

-- Meta line: 20 text/gemini

commit 260bcbf63e2a56253dc15ad1272180f9a0d144b1

Author: Julien Blanchard <julien@sideburns.eu>

Date: Sun Apr 19 16:13:25 2020 +0200


Implement pre-formatting toggles


Text is monospaced but still reflowed if the window i too small.


diff --git a/src/castor.glade b/src/castor.glade

index e98f385..079ec19 100644

--- a/src/castor.glade

+++ b/src/castor.glade

@@ -1,5 +1,5 @@

<?xml version="1.0" encoding="UTF-8"?>

-<!-- Generated with glade 3.22.1 -->

+<!-- Generated with glade 3.22.2 -->

<interface>

<requires lib="gtk+" version="3.16"/>

<object class="GtkTextBuffer"/>

@@ -138,6 +138,10 @@

<property name="can_focus">True</property>

<property name="editable">False</property>

<property name="wrap_mode">word</property>

+ <property name="left_margin">10</property>

+ <property name="right_margin">10</property>

+ <property name="top_margin">5</property>

+ <property name="bottom_margin">5</property>

<property name="indent">15</property>

<property name="cursor_visible">False</property>

<property name="monospace">True</property>

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

index af20d20..9f16ae7 100644

--- a/src/gemini/parser.rs

+++ b/src/gemini/parser.rs

@@ -13,6 +13,7 @@ pub enum TextElement {

ListItem(String),

LinkItem(String),

Text(String),

+ MonoText(String),

}


Clone, Copy, PartialEq, Eq, Hash)]

@@ -21,7 +22,7 @@ pub struct ParseError;

const H1_REGEX: &str = r"^#\s+(.*)$";

const H2_REGEX: &str = r"^##\s+(.*)$";

const H3_REGEX: &str = r"^###\s+(.*)$";

-const LIST_ITEM_REGEX: &str = r"^\s*\*\s+([^*]*)$";

+const LIST_ITEM_REGEX: &str = r"^\*\s+([^*]*)$";

const LINK_ITEM_REGEX: &str = r"^=>\s*(\S*)\s*(.*)?$";


impl FromStr for TextElement {

@@ -53,6 +54,8 @@ impl FromStr for TextElement {

Ok(TextElement::ListItem(String::from(header)))

} else if link_item_regexp.is_match(&line) {

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

+ } else if line == "```" {

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

} else {

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

}

diff --git a/src/main.rs b/src/main.rs

index 394ded3..db6c8ca 100644

--- a/src/main.rs

+++ b/src/main.rs

@@ -288,6 +288,8 @@ fn draw_gemini_content(

let content_view = gui.content_view();

let buffer = content_view.get_buffer().unwrap();


+ let mut mono_toggle = false;

+

for el in content {

match el {

Ok(gemini::parser::TextElement::H1(header)) => {

@@ -327,9 +329,22 @@ fn draw_gemini_content(

&format!("<span foreground=\"green\">■ {}</span>\n", item),

);

}

+ Ok(gemini::parser::TextElement::MonoText(_text)) => {

+ mono_toggle = !mono_toggle;

+ }

Ok(gemini::parser::TextElement::Text(text)) => {

let mut end_iter = buffer.get_end_iter();

- buffer.insert_markup(&mut end_iter, &format!("{}\n", text));

+ match mono_toggle {

+ true => {

+ buffer.insert_markup(

+ &mut end_iter,

+ &format!("<span font_family=\"monospace\">{}</span>\n", text),

+ );

+ },

+ false => {

+ buffer.insert_markup(&mut end_iter, &format!("{}\n", text));

+ }

+ }

}

Ok(gemini::parser::TextElement::LinkItem(link_item)) => {

draw_gemini_link(&gui, link_item);



---

Served by Pollux Gemini Server.

-- Response ended

-- Page fetched on Mon May 27 20:30:06 2024