diff --git a/scdoc.5.scd b/scdoc.5.scd index 293193f..b94952e 100644 --- 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 index cb6b5bd..3765f7e 100644 --- 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;