~sotirisp/qute-gemini

cf969b939f3fcbf19111d56a4db5a258cd754eea — Sotiris Papatheodorou 9 months ago bb14bb3
Add way to use custom CSS
2 files changed, 32 insertions(+), 7 deletions(-)

M README.md
M qute-gemini
M README.md => README.md +8 -2
@@ 1,8 1,8 @@
# qute-gemini

A [qutebrowser](https://qutebrowser.org) userscript that allows viewing
[Gemini](https://gemini.circumlunar.space) pages. The pages are converted to
HTML by the script and then displayed in qutebrowser.
[Gemini](https://gemini.circumlunar.space) pages by pressing a custom key. The
pages are converted to HTML by the script and then displayed in qutebrowser.

The script borrows code from [gcat](https://github.com/aaronjanse/gcat), many
thanks to its authors!


@@ 33,6 33,12 @@ is supported but the default directory paths are used for simplicity.
   [Gemini spec homepage](gemini://gemini.circumlunar.space)
   to ensure that everything works.

### Custom CSS

You can create a CSS file
`~/.local/share/qutebrowser/userscripts/qute-gemini.css` and qute-gemini will
use it to style Gemini pages shown in qutebrowser.



## Known issues

M qute-gemini => qute-gemini +24 -5
@@ 19,11 19,6 @@ import urllib.parse
from typing import Tuple


def script_dir() -> str:
    """The directory this script is located in."""
    return os.path.dirname(os.path.realpath(__file__))


def qute_url() -> str:
    """Get the URL passed to the script by qutebrowser."""
    return os.environ["QUTE_URL"]


@@ 34,6 29,15 @@ def qute_fifo() -> str:
    return os.environ["QUTE_FIFO"]


def qute_gemini_css_path() -> str:
    """Return the path where the custom CSS file is expected to be."""
    try:
        base_dir = os.environ["XDG_DATA_HOME"]
    except KeyError:
        base_dir = os.path.join(os.environ["HOME"], ".local/share")
    return os.path.join(base_dir, "qutebrowser/userscripts/qute-gemini.css")


def gemini_absolutise_url(base: str, relative: str) -> str:
    """Absolutise relative gemini URLs.



@@ 114,6 118,9 @@ def gemtext_to_html(gemtext: str, title: str, url: str) -> str:
            '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">',
            "\t<head>",
            "\t\t<title>" + title + "</title>",
            "\t\t<style>",
            get_css(),
            "\t\t</style>",
            "\t</head>",
            "\t<body>"]
    in_pre = False


@@ 174,6 181,18 @@ def gemtext_to_html(gemtext: str, title: str, url: str) -> str:
    return "\n".join(lines)


def get_css() -> str:
    # Search for qute-gemini.css in the directory this script is located in
    css_file = qute_gemini_css_path()
    if os.path.isfile(css_file):
        # Return the file contents
        with open(css_file, "r") as f:
            return f.read().strip()
    else:
        # Use no CSS
        return ""


def open_gemini(url: str, open_args: str) -> None:
    """Open Gemini URL in qutebrowser."""
    # Get the Gemini content