summaryrefslogtreecommitdiff
path: root/src/gmdocument.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-10-12 08:54:47 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-10-12 08:54:47 +0300
commit4a3cda29bbf2494061fb1090698cf1230e43a280 (patch)
treed0359861c951763ac253f2815cac50a343b83d02 /src/gmdocument.c
parent8dbd6148fd761bf62bcb93b5d86c9e3fd37507e6 (diff)
Normalizing long spaces to a tab stop
Experimenting with terminal friendly space normalization where sometimes multiple spaces are used to align content horizontally (with a fixed-width font). When encountering 8 or more consecutive spaces, they are all replaced with a single tab character. Gemtext allows clients to normalize whitespace as they see fit.
Diffstat (limited to 'src/gmdocument.c')
-rw-r--r--src/gmdocument.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index f800f6ed..87b8a22c 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -967,11 +967,18 @@ static void normalize_GmDocument(iGmDocument *d) {
967 continue; 967 continue;
968 } 968 }
969 iBool isPrevSpace = iFalse; 969 iBool isPrevSpace = iFalse;
970 int spaceCount = 0;
970 for (const char *ch = line.start; ch != line.end; ch++) { 971 for (const char *ch = line.start; ch != line.end; ch++) {
971 char c = *ch; 972 char c = *ch;
972 if (c == '\r') continue; 973 if (c == '\r') continue;
973 if (isNormalizableSpace_(c)) { 974 if (isNormalizableSpace_(c)) {
974 if (isPrevSpace) { 975 if (isPrevSpace) {
976 if (++spaceCount == 8) {
977 /* There are several consecutive space characters. The author likely
978 really wants to have some space here, so normalize to a tab stop. */
979 popBack_Block(&normalized->chars);
980 pushBack_Block(&normalized->chars, '\t');
981 }
975 continue; /* skip repeated spaces */ 982 continue; /* skip repeated spaces */
976 } 983 }
977 c = ' '; 984 c = ' ';
@@ -979,6 +986,7 @@ static void normalize_GmDocument(iGmDocument *d) {
979 } 986 }
980 else { 987 else {
981 isPrevSpace = iFalse; 988 isPrevSpace = iFalse;
989 spaceCount = 0;
982 } 990 }
983 appendCStrN_String(normalized, &c, 1); 991 appendCStrN_String(normalized, &c, 1);
984 } 992 }