commit 5821d041342e44ae655a5ba1de73a7671f7455d9
parent 9e691b8df377fa6f938c10c92a9f7eb704920614
Author: hhvn <dev@hhvn.uk>
Date: Wed, 9 Feb 2022 17:44:51 +0000
Experimental hilighting of markdown headers
Diffstat:
4 files changed, 49 insertions(+), 12 deletions(-)
diff --git a/.config.hhvn.h b/.config.hhvn.h
@@ -4,6 +4,7 @@ static int parallelplumb = 1;
static int stimeout = 5;
static int regexflags = REG_ICASE|REG_EXTENDED;
static int autotls = 1;
+static int mdhilight = 1;
static short bar_pair[2] = {-1, 0};
static short uri_pair[2] = {0, 7};
@@ -33,8 +34,16 @@ static Scheme scheme[] = {
{'d', "Doc ", 15 },
{'3', "ERR ", 8 },
- /* DNE! These values are actually used:
- * -1 = default foregrounds
- * 0 = default colour pair */
- {'\0', "????", 8 },
+ /* Experimental markdown header hilighting.
+ * mdhilight must be set for this to show.
+ * Unlike other elements of scheme, the fore-
+ * ground is used for the text itself, not
+ * the name. */
+ {MDH1, " ", 7 },
+ {MDH2, " ", 6 },
+ {MDH3, " ", 5 },
+ {MDH4, " ", 4 },
+
+ /* must be last, see getscheme() */
+ {DEFL, "????", 8 },
};
diff --git a/config.def.h b/config.def.h
@@ -3,8 +3,8 @@ static char *yanker = "xclip";
static int parallelplumb = 0;
static int stimeout = 5;
static int regexflags = REG_ICASE|REG_EXTENDED;
-static int autotls = 0; /* automatically try to
- establish TLS connections? */
+static int mdhilight = 0; /* attempt to hilight markdown headers */
+static int autotls = 0; /* automatically try to establish TLS connections */
static short bar_pair[2] = {-1, 0};
static short uri_pair[2] = {0, 7};
@@ -34,8 +34,16 @@ static Scheme scheme[] = {
{'d', "Doc ", 8 },
{'3', "ERR ", 1 },
- /* DNE! These values are actually used:
- * -1 = default foregrounds
- * 0 = default colour pair */
- {'\0', "????", 1 },
+ /* Experimental markdown header hilighting.
+ * mdhilight must be set for this to show.
+ * Unlike other elements of scheme, the fore-
+ * ground is used for the text itself, not
+ * the name. */
+ {MDH1, " ", 6 },
+ {MDH2, " ", 5 },
+ {MDH3, " ", 4 },
+ {MDH4, " ", 3 },
+
+ /* must be last, see getscheme() */
+ {DEFL, "????", 8 },
};
diff --git a/zygo.c b/zygo.c
@@ -601,8 +601,21 @@ getscheme(Elem *e) {
if (type == 'h' && strstr(e->selector, "URL:"))
type = EXTR;
+ /* Try to get scheme from markdown header */
+ if (type == 'i' && mdhilight) {
+ /* 4+ matches MDH4 */
+ if (strncmp(e->desc, "####", 4) == 0)
+ type = MDH4;
+ else if (strncmp(e->desc, "###", 3) == 0)
+ type = MDH3;
+ else if (strncmp(e->desc, "##", 2) == 0)
+ type = MDH2;
+ else if (strncmp(e->desc, "#", 1) == 0)
+ type = MDH1;
+ }
+
for (i = 0; ; i++)
- if (scheme[i].type == type || scheme[i].type == '\0')
+ if (scheme[i].type == type || scheme[i].type == DEFL)
return &scheme[i];
}
@@ -681,6 +694,12 @@ draw_line(Elem *e, int nwidth) {
if (ui.search && regexec(&ui.regex, e->desc, 0, NULL, 0) == 0)
attron(A_REVERSE);
+ if (mdhilight && strncmp(e->desc, "#", 1) == 0) {
+ attron(A_BOLD);
+ attron(COLOR_PAIR(getscheme(e)->pair));
+ attroff(A_BOLD);
+ }
+
len = mbstowcs(NULL, e->desc, 0) + 1;
mbdesc = emalloc(len * sizeof(wchar_t*));
mbstowcs(mbdesc, e->desc, len);
diff --git a/zygo.h b/zygo.h
@@ -40,7 +40,8 @@ struct List {
size_t lastid;
};
-enum { EXTR = 1 };
+enum { DEFL, EXTR,
+ MDH1, MDH2, MDH3, MDH4 };
typedef struct Scheme Scheme;
struct Scheme {
char type;