summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--html.c21
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(&regex, Pattern, REG_EXTENDED);
-		if (error) {
-			char buf[256];
-			regerror(error, &regex, 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(&regex, Pattern, REG_EXTENDED);
+			assert(!error);
+		}
+		if (patch && !regexec(&regex, 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
 			);