diff --git a/README.md b/README.md
index fa803f99158582d982ef3a01d6b87471fb27f0cb..9aa989fe358ecccd9b984b1aff0df97c6c2ceec0 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ - s command to directly search in geminispace (via geminispace.info)
- k command to remove the bookmark for the current page
- e[N] command to open a link in default external program (requires `xdg-open`)
- t[N] command to download the content behind a link to a temporary file
-- b & f commands to navigate history can jump multiple entries at once
+- a command to switch between display of preformatted blocks and alt text (if available)
The actual colors used depend on your terminal palette:
- heading 1: light red
diff --git a/src/gmnlm.c b/src/gmnlm.c
index 8cafaea17de972c240031b0fe6ab88e3621bd871..77d03cb16e1e27c440ecb1c5b7d154db50659dc6 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -44,7 +44,7 @@ struct history *prev, *next;
};
struct browser {
- bool pagination, unicode;
+ bool pagination, unicode, alttext;
int max_width;
struct gemini_options opts;
struct gemini_tofu tofu;
@@ -103,6 +103,7 @@ "n\t\tjump to next search match\n"
"d <path>\tDownload page to <path>\n"
"|<prog>\t\tPipe page into program\n"
"[N]|<prog>\tPipe content of Nth link into program\n"
+ "a\t\ttoggle usage of alt text instead of preformatted text\n"
"q\t\tQuit\n"
"\n"
;
@@ -636,6 +637,11 @@ if (in[1]) break;
set_url(browser, "gemini://geminispace.info/search", &browser->history);
result = PROMPT_ANSWERED;
goto exit;
+ case 'a':
+ browser->alttext = !browser->alttext;
+ fprintf(browser->tty, "Alttext instead of preformatted block is now %s\n", browser->alttext ? "ENABLED" : "DISABLED");
+ result = PROMPT_AGAIN;
+ goto exit;
case 'b':
if (in[1]) historyhops =(int)strtol(in+1, &endptr, 10);
while (historyhops > 0) {
@@ -939,6 +945,7 @@
fprintf(out, "\n");
char *text = NULL;
int row = 0, col = 0;
+ bool no_alttext;
struct gemini_token tok;
struct link **next = &browser->links;
while (text != NULL || gemini_parser_next(&p, &tok) == 0) {
@@ -962,13 +969,21 @@ col += fprintf(out, " ");
}
break;
case GEMINI_PREFORMATTED_BEGIN:
- gemini_token_finish(&tok);
+ if (text == NULL && browser->alttext) {
+ if (tok.preformatted == NULL) {
+ no_alttext = true;
+ } else {
+ fprintf(out, " A %s", ANSI_COLOR_GRAY);
+ text = tok.preformatted;
+ }
+ }
+ break;
/* fallthrough */
case GEMINI_PREFORMATTED_END:
continue; // Not used
case GEMINI_PREFORMATTED_TEXT:
- if (text == NULL) {
- fprintf(out, " %s", ANSI_COLOR_GRAY);
+ if (text == NULL && (!browser->alttext || no_alttext)) {
+ fprintf(out, " P %s", ANSI_COLOR_GRAY);
text = tok.preformatted;
}
break;
@@ -1241,6 +1256,7 @@ main(int argc, char *argv[])
{
struct browser browser = {
.pagination = true,
+ .alttext = false,
.tofu_mode = TOFU_ASK,
.unicode = true,
.url = curl_url(),