From 4b29f37a662fa30d360bfccc843a5f8c1387f3c1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 11 Sep 2019 15:04:02 -0400 Subject: [PATCH] tables: add expand options --- scdoc.5.scd | 15 +++++++++++++++ src/main.c | 36 ++++++++++++++++++++++++++++++++++-- diff --git a/scdoc.5.scd b/scdoc.5.scd index 65a2b3661042fc89138c65950a60ce85ce5823fd..f4d393be89a86bcc6e003dbe092240f7af95cab5 100644 --- a/scdoc.5.scd +++ b/scdoc.5.scd @@ -155,6 +155,21 @@ : こんにちは : 世界 ! +You may also cause columns to expand to fill the available space with < (left +align), = (center align), and > (right align), like so: + +``` +[[ *Normal column* +:< Expanded column +| *Foo* +: Bar +``` + +[[ *Normal column* +:< Expanded column +| *Foo* +: Bar + ## LITERAL TEXT You may turn off scdoc formatting and output literal text with escape codes and diff --git a/src/main.c b/src/main.c index cf142880ec779524557e74b5053d51cdcea7d07a..19a134cea3fde65effda8397732ebe953931b3a4 100644 --- a/src/main.c +++ b/src/main.c @@ -434,6 +434,9 @@ enum table_align { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT, + ALIGN_LEFT_EXPAND, + ALIGN_CENTER_EXPAND, + ALIGN_RIGHT_EXPAND, }; struct table_row { @@ -508,6 +511,15 @@ break; case ']': curcell->align = ALIGN_RIGHT; break; + case '<': + curcell->align = ALIGN_LEFT_EXPAND; + break; + case '=': + curcell->align = ALIGN_CENTER_EXPAND; + break; + case '>': + curcell->align = ALIGN_RIGHT_EXPAND; + break; case ' ': if (prevrow) { struct table_cell *pcell = prevrow->cell; @@ -576,8 +588,28 @@ currow = table; while (currow) { curcell = currow->cell; while (curcell) { - fprintf(p->output, "%c%s", "lcr"[curcell->align], - curcell->next ? " " : ""); + char *align = ""; + switch (curcell->align) { + case ALIGN_LEFT: + align = "l"; + break; + case ALIGN_CENTER: + align = "c"; + break; + case ALIGN_RIGHT: + align = "r"; + break; + case ALIGN_LEFT_EXPAND: + align = "lx"; + break; + case ALIGN_CENTER_EXPAND: + align = "cx"; + break; + case ALIGN_RIGHT_EXPAND: + align = "rx"; + break; + } + fprintf(p->output, "%s%s", align, curcell->next ? " " : ""); curcell = curcell->next; } fprintf(p->output, "%s\n", currow->next ? "" : "."); -- 2.48.1