7 releases

new 0.3.0 Dec 5, 2024
0.2.1 Nov 12, 2024
0.2.0 Oct 20, 2024
0.1.3 Oct 20, 2024

#384 in Value formatting

Download history 378/week @ 2024-10-18 16/week @ 2024-10-25 7/week @ 2024-11-01 113/week @ 2024-11-08 25/week @ 2024-11-15 10/week @ 2024-11-22 117/week @ 2024-11-29

270 downloads per month
Used in yoda

MIT license

14KB
212 lines

ggemtext

Glib-oriented Gemtext API

Install

cargo add ggemtext

Usage

Line

Line parser, useful for TextTag operations in TextBuffer context.

Connect dependencies

use ggemtext::line::{
    code::{Inline, Multiline},
    header::{Header, Level},
    link::Link,
    list::List,
    quote::Quote,
};

Prepare document

Iterate Gemtext lines to continue with Line API:

for line in gemtext.lines() {
    // ..
}

Code

Inline
match Inline::from("```inline```") {
    Some(inline) => assert_eq!(inline.value, "inline"),
    None => assert!(false),
};
Multiline
match Multiline::begin_from("```alt") {
    Some(mut multiline) => {
        assert!(Multiline::continue_from(&mut multiline, "line 1").is_ok());
        assert!(Multiline::continue_from(&mut multiline, "line 2").is_ok());
        assert!(Multiline::continue_from(&mut multiline, "```").is_ok()); // complete

        assert!(multiline.completed);
        assert_eq!(multiline.alt, Some("alt".into()));
        assert_eq!(multiline.buffer.len(), 3);
    }
    None => assert!(false),
};

Header

match Header::from("# H1") {
    Some(h1) => {
        assert_eq!(h1.level as i8, Level::H1 as i8);
        assert_eq!(h1.value, "H1");
    }
    None => assert!(false),
}; // H1, H2, H3
match Link::from(
    "=> gemini://geminiprotocol.net 1965-01-19 Gemini",
    None, // absolute path given, base not wanted
    Some(&glib::TimeZone::local()),
) {
    Some(link) => {
        // Alt
        assert_eq!(link.alt, Some("Gemini".into()));

        // Date
        match link.timestamp {
            Some(timestamp) => {
                assert_eq!(timestamp.year(), 1965);
                assert_eq!(timestamp.month(), 01);
                assert_eq!(timestamp.day_of_month(), 19);
            }
            None => assert!(false),
        }

        // URI
        assert_eq!(link.uri.to_string(), "gemini://geminiprotocol.net");
    }
    None => assert!(false),
};

List

match List::from("* Item") {
    Some(list) => assert_eq!(list.value, "Item"),
    None => assert!(false),
};

Quote

match Quote::from("> Quote") {
    Some(quote) => assert_eq!(quote.value, "Quote"),
    None => assert!(false),
};

Integrations

  • Yoda - Browser for Gemini Protocol

See also

  • ggemini - Glib-oriented client for Gemini Protocol

Dependencies

~5.5MB
~119K SLoC