diff options
author | June McEnroe <june@causal.agency> | 2020-04-29 17:07:39 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-04-29 17:07:39 -0400 |
commit | 1a1d36f59624cdd0be6b131d4e9fb56bc772e3b5 (patch) | |
tree | ebad2fb7a0b81059b511792f1e5e2756fc9e9bfc | |
parent | Turn URLs into HTML links (diff) | |
download | bubger-1a1d36f59624cdd0be6b131d4e9fb56bc772e3b5.tar.gz bubger-1a1d36f59624cdd0be6b131d4e9fb56bc772e3b5.zip |
Highlight diff/index/---/+++ lines of patches as well
Diffstat (limited to '')
-rw-r--r-- | html.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/html.c b/html.c index 850e070..ee9e966 100644 --- a/html.c +++ b/html.c @@ -14,8 +14,9 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include <regex.h> +#include <assert.h> #include <err.h> +#include <regex.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -225,11 +226,7 @@ static int htmlMarkupURLs(FILE *file, char *buf) { static regex_t regex; if (!regex.re_nsub) { int error = regcomp(®ex, Pattern, REG_EXTENDED); - if (error) { - char buf[256]; - regerror(error, ®ex, buf, sizeof(buf)); - errx(EX_SOFTWARE, "%s: %s", buf, Pattern); - } + assert(!error); } int error; @@ -281,15 +278,21 @@ static int htmlMarkup(FILE *file, const char *content) { patch = false; } - if (patch && !strncmp(buf, "@@", 2)) { + static const char *Pattern = "^(diff|index|---|[+]{3}|@@) "; + static regex_t regex; + if (!regex.re_nsub) { + error = regcomp(®ex, Pattern, REG_EXTENDED); + assert(!error); + } + if (patch && !regexec(®ex, buf, 0, NULL, 0)) { error = templateRender( file, TEMPLATE(<b>[line]</b>), vars, escapeXML ); - } else if (patch && buf[0] == '-' && strncmp(buf, "---", 3)) { + } else if (patch && buf[0] == '-' && strcmp(buf, "---")) { error = templateRender( file, TEMPLATE(<del>[line]</del>), vars, escapeXML ); - } else if (patch && buf[0] == '+' && strncmp(buf, "+++", 3)) { + } else if (patch && buf[0] == '+') { error = templateRender( file, TEMPLATE(<ins>[line]</ins>), vars, escapeXML ); |