From 174e77a637e1ab24dd8d96b8afabf1033e884bbd Mon Sep 17 00:00:00 2001 From: Nate Choe Date: Mon, 6 Jun 2022 16:42:15 -0500 Subject: [PATCH] Minification exclusion --- README.md | 18 +++++++++++++++++- src/include/config.h | 1 + src/parse.c | 10 +++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dd294cb..6dc8351 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Please not that ncdg minifies HTML so these examples aren't really correct. ## Usage -There are only 3 features in ncdg: +There are only 4 features in ncdg: ### Include statements @@ -108,3 +108,19 @@ Result: Note that text inside of escaped sections are not minified. + +### Excluding minification + +``` +%& +& +% +``` + +Result: + +``` +& +``` + +Used for legacy web pages on my site that I don't want to update diff --git a/src/include/config.h b/src/include/config.h index 0c0a610..6dfd872 100644 --- a/src/include/config.h +++ b/src/include/config.h @@ -3,5 +3,6 @@ #define VAR_CHAR '!' #define SET_CHAR '=' #define AUTOESCAPE_CHAR '\\' +#define NOMINIFY_CHAR '&' #define MAX_INCLUDE_DEPTH 10 diff --git a/src/parse.c b/src/parse.c index dfcb4d8..ed286ef 100644 --- a/src/parse.c +++ b/src/parse.c @@ -105,8 +105,7 @@ static int writefile(struct expandfile *file, FILE *out) { } case AUTOESCAPE_CHAR: for (++i; data->data[i] != ESCAPE_CHAR && - i < data->len; - ++i) { + i < data->len; ++i) { switch (data->data[i]) { case '&': fputs("&", out); @@ -125,6 +124,11 @@ static int writefile(struct expandfile *file, FILE *out) { } } break; + case NOMINIFY_CHAR: + for (++i; data->data[i] != ESCAPE_CHAR && + i < data->len; ++i) + fputc(data->data[i], out); + break; } } else @@ -161,7 +165,7 @@ static int expandfile(struct expandfile *ret, char *filename, int level) { if (appendchar(ret->data, ESCAPE_CHAR)) goto error; break; - case VAR_CHAR: case AUTOESCAPE_CHAR: + case VAR_CHAR: case AUTOESCAPE_CHAR: case NOMINIFY_CHAR: if (appendchar(ret->data, ESCAPE_CHAR)) goto error; for (;;) {