commit da3cd52d0a58e1c0042cb5f9dd8293e40e8f310d
parent 3320c97ebd0b88e705a78b9b86dc14a921fec4f7
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 7 Oct 2018 10:40:39 -0400
Add support for explicit line breaks
Diffstat:
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/scdoc.5.scd b/scdoc.5.scd
@@ -35,6 +35,13 @@ an empty line on either side.
Begin a new paragraph with an empty line.
+## LINE BREAKS
+
+Insert a line break by ending a line with \+\+.
+
+The result looks++
+like this.
+
## FORMATTING
Text can be made *bold* or _underlined_ with asterisks and underscores: \*bold\*
diff --git a/src/main.c b/src/main.c
@@ -133,6 +133,29 @@ static void parse_format(struct parser *p, enum formatting fmt) {
p->flags ^= fmt;
}
+static void parse_linebreak(struct parser *p) {
+ uint32_t plus = parser_getch(p);
+ if (plus != '+') {
+ fprintf(p->output, "+");
+ parser_pushch(p, plus);
+ return;
+ }
+ uint32_t lf = parser_getch(p);
+ if (lf != '\n') {
+ fprintf(p->output, "+");
+ parser_pushch(p, plus);
+ parser_pushch(p, '\n');
+ return;
+ }
+ uint32_t ch = parser_getch(p);
+ if (ch == '\n') {
+ parser_fatal(
+ p, "Explicit line breaks cannot be followed by a blank line");
+ }
+ parser_pushch(p, ch);
+ fprintf(p->output, "\n.br\n");
+}
+
static void parse_text(struct parser *p) {
uint32_t ch;
int i = 0;
@@ -154,6 +177,9 @@ static void parse_text(struct parser *p) {
case '_':
parse_format(p, FORMAT_UNDERLINE);
break;
+ case '+':
+ parse_linebreak(p);
+ break;
case '\n':
utf8_fputch(p->output, ch);
return;