From 83e23c71985ce8e10c5d1515d134cc386b3c476c Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 11 May 2020 12:46:17 -0400 Subject: Eliminate stray whitespace in HTML and Atom --- archive.h | 4 +- atom.c | 90 ++++++++++++------------ default.html | 3 + html.c | 220 +++++++++++++++++++++++++++++------------------------------ 4 files changed, 156 insertions(+), 161 deletions(-) diff --git a/archive.h b/archive.h index 75d8781..f0bda03 100644 --- a/archive.h +++ b/archive.h @@ -26,6 +26,8 @@ #define GENERATOR_URL "https://git.causal.agency/bubger" +#define Q(...) #__VA_ARGS__ + struct Address { char *name; const char *mailbox; @@ -159,8 +161,6 @@ void concatData( void concatThreads(struct List threads, const struct Envelope *envelopes); void concatIndex(struct List threads, const struct Envelope *envelopes); -#define TEMPLATE(...) #__VA_ARGS__ - struct Variable { const char *name; const char *value; diff --git a/atom.c b/atom.c index 7bc4fe9..35cc840 100644 --- a/atom.c +++ b/atom.c @@ -31,12 +31,12 @@ static char *atomID(const struct Envelope *envelope) { } static int atomAuthor(FILE *file, struct Address addr) { - const char *template = TEMPLATE( - - [name] - [mailbox]@[host] - - ); + const char *template = { + Q() + Q([name]) + Q([mailbox]@[host]) + Q() + }; struct Variable vars[] = { { "name", addressName(addr) }, { "mailbox", addr.mailbox }, @@ -62,13 +62,13 @@ static const char *atomUpdated(time_t time) { } int atomEntryOpen(FILE *file, const struct Envelope *envelope) { - const char *template = TEMPLATE( - - [id] - [title] - [updated] - - ); + const char *template = { + Q() + Q([id]) + Q([title]) + Q([updated]) + Q() + }; char *id = atomID(envelope); char *url = atomEntryURL(envelope); struct Variable vars[] = { @@ -88,13 +88,13 @@ int atomEntryOpen(FILE *file, const struct Envelope *envelope) { } int atomContent(FILE *file, const char *content) { - const char *template = TEMPLATE( - -
-
[content]
-
-
- ); + const char *template = { + Q() + Q(
) + Q(
[content]
) + Q(
) + Q(
) + }; struct Variable vars[] = { { "content", content }, {0}, @@ -103,7 +103,7 @@ int atomContent(FILE *file, const char *content) { } int atomEntryClose(FILE *file) { - return templateRender(file, TEMPLATE(
), NULL, NULL); + return templateRender(file, Q(
), NULL, NULL); } static char *atomThreadURL(const struct Envelope *envelope, const char *type) { @@ -116,23 +116,22 @@ static char *atomThreadURL(const struct Envelope *envelope, const char *type) { } int atomThreadOpen(FILE *file, const struct Envelope *envelope) { - const char *template = TEMPLATE( - <[q]xml version="1.0" encoding="utf-8"[q]> - - bubger - [id] - [title] - [updated] - - - - ); + const char *template = { + "" + Q() + Q(bubger) + Q([id]) + Q([title]) + Q([updated]) + Q() + Q() + Q() + }; char *id = atomID(envelope); char *atom = atomThreadURL(envelope, "atom"); char *html = atomThreadURL(envelope, "html"); char *mbox = atomThreadURL(envelope, "mbox"); struct Variable vars[] = { - { "q", "?" }, { "generator", GENERATOR_URL }, { "id", id }, { "title", envelope->subject }, @@ -154,22 +153,21 @@ int atomThreadOpen(FILE *file, const struct Envelope *envelope) { } int atomThreadClose(FILE *file) { - return templateRender(file, TEMPLATE(), NULL, NULL); + return templateRender(file, Q(), NULL, NULL); } int atomIndexOpen(FILE *file) { - const char *template = TEMPLATE( - <[q]xml version="1.0" encoding="utf-8"[q]> - - bubger - mailto:[mailto] - [title] - [updated] - - - ); + const char *template = { + "" + Q() + Q(bubger) + Q(mailto:[mailto]) + Q([title]) + Q([updated]) + Q() + Q() + }; struct Variable vars[] = { - { "q", "?" }, { "generator", GENERATOR_URL }, { "mailto", baseMailto }, { "title", baseTitle }, @@ -181,5 +179,5 @@ int atomIndexOpen(FILE *file) { } int atomIndexClose(FILE *file) { - return templateRender(file, TEMPLATE(), NULL, NULL); + return templateRender(file, Q(), NULL, NULL); } diff --git a/default.html b/default.html index 6ff49cf..36736a6 100644 --- a/default.html +++ b/default.html @@ -80,6 +80,9 @@ ul.recipient li.group::after { address.from::before { content: 'From: '; } +address.from { + margin-right: 1ch; +} ul.to::before { content: 'To: '; margin-right: 1ch; diff --git a/html.c b/html.c index 215c208..0d086da 100644 --- a/html.c +++ b/html.c @@ -28,20 +28,18 @@ static int htmlAddress(FILE *file, const char *class, struct Address addr) { const char *template; if (addr.host) { - template = TEMPLATE( -
  • [name]
  • - ); + template = Q(
  • [name]
  • ); } else if (addr.mailbox) { - template = TEMPLATE( -
  • -
    [mailbox]
    - ) + Q(
  • ) + }; } struct Variable vars[] = { { "class", class }, @@ -55,9 +53,7 @@ static int htmlAddress(FILE *file, const char *class, struct Address addr) { static int htmlAddressList(FILE *file, const char *class, struct AddressList list) { if (!list.len) return 0; - const char *template = TEMPLATE( - ), NULL, NULL); } static char *htmlReply(const struct Envelope *envelope) { @@ -111,9 +107,7 @@ static char *htmlMbox(const char *messageID) { static int htmlNavItem(FILE *file, const char *name, const char *base, const char *url) { - const char *template = TEMPLATE( -
  • [name]
  • - ); + const char *template = Q(
  • [name]
  • ); struct Variable vars[] = { { "name", name }, { "base", base }, @@ -124,7 +118,7 @@ htmlNavItem(FILE *file, const char *name, const char *base, const char *url) { } int htmlMessageNav(FILE *file, const struct Envelope *envelope) { - int error = templateRender(file, TEMPLATE(), NULL, NULL); } static const char *htmlUTC(time_t time) { @@ -146,15 +140,15 @@ static const char *htmlUTC(time_t time) { } int htmlMessageOpen(FILE *file, const struct Envelope *envelope) { - const char *template = TEMPLATE( -
    -
    -

    [subject]

    -
    - [from] -
    - - ); + const char *template = { + Q(
    ) + Q(
    ) + Q(

    [subject]

    ) + Q(
    ) + Q([from]) + Q(
    ) + Q() + }; char *fragment = htmlFragment(envelope->messageID); char *reply = htmlReply(envelope); struct Variable vars[] = { @@ -172,14 +166,14 @@ int htmlMessageOpen(FILE *file, const struct Envelope *envelope) { || htmlAddressList(file, "to", envelope->to) || htmlAddressList(file, "cc", envelope->cc) || htmlMessageNav(file, envelope) - || templateRender(file, TEMPLATE(
    ), NULL, NULL); + || templateRender(file, Q(
    ), NULL, NULL); free(reply); free(fragment); return error; } static int htmlInlineAttrs(FILE *file, const struct BodyPart *part) { - const char *template = " " TEMPLATE([attr]="[value]"); + const char *template = " " Q([attr]="[value]"); if (part->contentID) { struct Variable vars[] = { { "attr", "id" }, @@ -240,7 +234,7 @@ static int htmlMarkupURLs(FILE *file, char *buf) { if (error) return error; swap(&ptr[match[2].rm_so], &nul); - const char *template = TEMPLATE([url]); + const char *template = Q([url]); swap(&ptr[match[3].rm_so], &nul); struct Variable vars[] = { { "url", &ptr[match[2].rm_so] }, @@ -258,13 +252,13 @@ static int htmlMarkupQuote(FILE *file, char *buf) { size_t level = 0; for (char *ch = buf; *ch == '>' || *ch == ' '; level += (*ch++ == '>')); for (size_t i = 0; i < level; ++i) { - error = templateRender(file, TEMPLATE(), NULL, NULL); + error = templateRender(file, Q(), NULL, NULL); if (error) return error; } error = htmlMarkupURLs(file, buf); if (error) return error; for (size_t i = 0; i < level; ++i) { - error = templateRender(file, TEMPLATE(), NULL, NULL); + error = templateRender(file, Q(), NULL, NULL); if (error) return error; } return 0; @@ -303,15 +297,15 @@ static int htmlMarkup(FILE *file, const char *content) { } if (patch && !regexec(®ex, buf, 0, NULL, 0)) { error = templateRender( - file, TEMPLATE([line]), vars, escapeXML + file, Q([line]), vars, escapeXML ); } else if (patch && buf[0] == '-' && strcmp(buf, "---")) { error = templateRender( - file, TEMPLATE([line]), vars, escapeXML + file, Q([line]), vars, escapeXML ); } else if (patch && buf[0] == '+') { error = templateRender( - file, TEMPLATE([line]), vars, escapeXML + file, Q([line]), vars, escapeXML ); } else if (patch) { error = escapeXML(file, buf); @@ -331,23 +325,23 @@ static int htmlMarkup(FILE *file, const char *content) { int htmlInline(FILE *file, const struct BodyPart *part, const char *content) { return 0 - || templateRender(file, TEMPLATE(), NULL, NULL) + || templateRender(file, Q(>), NULL, NULL) || htmlMarkup(file, content) - || templateRender(file, TEMPLATE(), NULL, NULL); + || templateRender(file, Q(), NULL, NULL); } int htmlAttachmentOpen(FILE *file) { - return templateRender(file, TEMPLATE(
      ), NULL, NULL); + return templateRender(file, Q(
        ), NULL, NULL); } int htmlAttachment( FILE *file, const struct BodyPart *part, const struct Variable *path ) { - const char *template = TEMPLATE( -
      • [name][type][/][subtype]
      • - ); + const char *template = { + Q(
      • [name][type][/][subtype]
      • ) + }; char *url = templateURL("../" PATH_ATTACHMENT, path); const char *name = paramGet(part->disposition.params, "filename"); if (!name) name = paramGet(part->params, "name"); @@ -365,11 +359,11 @@ int htmlAttachment( } int htmlAttachmentClose(FILE *file) { - return templateRender(file, TEMPLATE(
      ), NULL, NULL); + return templateRender(file, Q(
    ), NULL, NULL); } int htmlMessageClose(FILE *file) { - return templateRender(file, TEMPLATE(
    ), NULL, NULL); + return templateRender(file, Q(), NULL, NULL); } static char *htmlThreadURL(const struct Envelope *envelope, const char *type) { @@ -382,14 +376,14 @@ static char *htmlThreadURL(const struct Envelope *envelope, const char *type) { } int htmlThreadHead(FILE *file, const struct Envelope *envelope) { - const char *template = TEMPLATE( - - - - [subject] · [title] - - - ); + const char *template = { + Q() + Q() + Q() + Q([subject] · [title]) + Q() + Q() + }; char *atom = htmlThreadURL(envelope, "atom"); char *mbox = htmlThreadURL(envelope, "mbox"); struct Variable vars[] = { @@ -407,19 +401,19 @@ int htmlThreadHead(FILE *file, const struct Envelope *envelope) { } int htmlThreadOpen(FILE *file, const struct Envelope *envelope) { - const char *template = TEMPLATE( -
    -

    [subject]

    - -
    -
    - ); + const char *template = { + Q(
    ) + Q(

    [subject]

    ) + Q() + Q(
    ) + Q(
    ) + }; char *atom = htmlThreadURL(envelope, "atom"); char *mbox = htmlThreadURL(envelope, "mbox"); struct Variable vars[] = { @@ -448,16 +442,10 @@ static size_t threadCount(struct List thread) { int htmlSubthreadOpen(FILE *file, struct List thread) { const char *template = { - TEMPLATE( -
    - - ) - TEMPLATE ( - [replies] repl[ies] - ) - TEMPLATE( - - ) + Q(
    ) + Q() + Q([replies] repl[ies]) + Q() }; size_t count = threadCount(thread); char replies[32]; @@ -471,16 +459,19 @@ int htmlSubthreadOpen(FILE *file, struct List thread) { } int htmlSubthreadClose(FILE *file) { - return templateRender(file, TEMPLATE(
    ), NULL, NULL); + return templateRender(file, Q(
    ), NULL, NULL); } static int htmlFooter(FILE *file) { - const char *template = TEMPLATE( - - ); + const char *template = { + Q(
    ) + Q() + Q(generated) + " " + Q() + Q() + Q(
    ) + }; struct Variable vars[] = { { "generator", GENERATOR_URL }, { "time", htmlUTC(time(NULL)) }, @@ -491,18 +482,18 @@ static int htmlFooter(FILE *file) { int htmlThreadClose(FILE *file) { return 0 - || templateRender(file, TEMPLATE(
    ), NULL, NULL) + || templateRender(file, Q(
    ), NULL, NULL) || htmlFooter(file); } int htmlIndexHead(FILE *file) { - const char *template = TEMPLATE( - - - - [title] - - ); + const char *template = { + Q() + Q() + Q() + Q([title]) + Q() + }; struct Variable vars[] = { { "generator", GENERATOR_URL }, { "title", baseTitle }, @@ -513,7 +504,7 @@ int htmlIndexHead(FILE *file) { static int htmlIndexNav(FILE *file) { int error = 0 - || templateRender(file, TEMPLATE(), NULL, NULL); } int htmlIndexOpen(FILE *file) { - const char *head = TEMPLATE( -
    -

    [title]

    - ); + const char *head = { + Q(
    ) + Q(

    [title]

    ) + }; struct Variable vars[] = { { "title", baseTitle }, {0}, }; - const char *tail = TEMPLATE( -
    -
    -
      - ); + const char *tail = { + Q(
    ) + Q(
    ) + Q(
      ) + }; return 0 || templateRender(file, head, vars, escapeXML) || htmlIndexNav(file) @@ -557,14 +548,17 @@ static char *htmlIndexURL(const struct Envelope *envelope) { int htmlIndexThread( FILE *file, const struct Envelope *envelope, struct List thread ) { - const char *template = TEMPLATE( -
    1. -

      [subject]

      -
      [from]
      - - [replies] repl[ies] -
    2. - ); + const char *template = { + Q(
    3. ) + Q(

      [subject]

      ) + Q(
      [from]
      ) + Q() + " " + Q() + Q([replies] repl[ies]) + Q() + Q(
    4. ) + }; char *url = htmlIndexURL(envelope); size_t count = threadCount(thread) - 1; char replies[32]; @@ -586,6 +580,6 @@ int htmlIndexThread( int htmlIndexClose(FILE *file) { return 0 - || templateRender(file, TEMPLATE(
    ), NULL, NULL) + || templateRender(file, Q(), NULL, NULL) || htmlFooter(file); } -- cgit 1.4.1