Commit Diff


commit - 77dd24f44c127286214d10f3059827f1453f0783
commit + b1379f345850aa5255db83fda24b6da1ab1ea039
blob - ba855645329bd01fe12bd6e919fb067429cabd90
blob + 07d02524af70521bc867069f48f05aaa65037760
--- ChangeLog
+++ ChangeLog
@@ -1,5 +1,8 @@
 2021-07-05  Omar Polo  <op@omarpolo.com>
 
+	* defaults.c (config_setvari): add hide-pre-context: if nonzero hide the start and end line of a pre block (i.e. ```).  Defaults to zero.
+	(config_setvari): add hide-pre-blocks: if nonzero hide by default the body of a pre block; push-button can be used to toggle visibility per-block.  Defaults to zero.
+
 	* cmd.c (cmd_push_button): push-button: toggle prefermatted blocks if invoked with the point on the header
 
 2021-06-26  Omar Polo  <op@omarpolo.com>
blob - 2a6c422f071c5fdd28478fad96d77b06174b1f08
blob + d5cfd832c0f1835bf65e74aedd3343937b491f8d
--- defaults.c
+++ defaults.c
@@ -26,6 +26,8 @@ char *new_tab_url = NULL;
 int fill_column = 80;
 int olivetti_mode = 1;
 int enable_colors = 1;
+int hide_pre_context = 0;
+int hide_pre_blocks = 0;
 
 struct lineprefix line_prefixes[] = {
 	[LINE_TEXT] =		{ "",		"" },
@@ -356,6 +358,10 @@ config_setvari(const char *var, int val)
 		olivetti_mode = !!val;
 	} else if (!strcmp(var, "enable-colors")) {
 		enable_colors = !!val;
+	} else if (!strcmp(var, "hide-pre-context")) {
+		hide_pre_context = !!val;
+	} else if (!strcmp(var, "hide-pre-blocks")) {
+		hide_pre_blocks = !!val;
 	} else {
 		return 0;
 	}
blob - d6d6ce91cf6bab7e58c5dbc5c73809f280ecab26
blob + 75fbbfd2af004a74260964309e270c81b3519b15
--- gemtext.c
+++ gemtext.c
@@ -79,6 +79,21 @@ emit_line(struct parser *p, enum line_type type, char 
 	l->line = line;
 	l->alt = alt;
 
+	switch (l->type) {
+	case LINE_PRE_START:
+	case LINE_PRE_END:
+		if (hide_pre_context)
+			l->flags = L_HIDDEN;
+		break;
+	case LINE_PRE_CONTENT:
+		if (hide_pre_blocks)
+			l->flags = L_HIDDEN;
+		break;
+	default:
+		l->flags = 0;
+		break;
+	}
+
 	if (TAILQ_EMPTY(&p->head))
 		TAILQ_INSERT_HEAD(&p->head, l, lines);
 	else
blob - 7e2a6403a870a6e40cd74d62f55ddc7ea8ad0303
blob + 765bdf3ae5c7fd22f4062b8044ba702ad7b9d1d8
--- telescope.1
+++ telescope.1
@@ -533,6 +533,14 @@ is not set, 0 otherwise.
 If greater than zero, lines of text will be formatted in a way that
 don't exceed the given number of columns.
 By default is 80.
+.It hide-pre-blocks
+If nonzero, hide by default the body of the preformatted blocks.
+.Ic push-button
+can be used to toggle the visibility per-block.
+.It hide-pre-context
+If nonzero, hide the start and end line of the preformatted blocks.
+If both hide-pre-context and hide-pre-blocks are nonzero, preformatted
+blocks are irremediably hidden.
 .It new-tab-url
 .Pq string
 URL for the new tab page.
blob - a0dbf4f90b84429cbab4831b9dcc486a410fdcaa
blob + 0fa19093d9bea18e148c18178e4e1df77a2d3600
--- telescope.h
+++ telescope.h
@@ -63,6 +63,8 @@ extern char	*new_tab_url;
 extern int	 fill_column;
 extern int	 olivetti_mode;
 extern int	 enable_colors;
+extern int	 hide_pre_context;
+extern int	 hide_pre_blocks;
 
 struct lineprefix {
 	const char	*prfx1;