Add support for explicit line breaks

master
Drew DeVault 6 years ago
parent 3320c97ebd
commit da3cd52d0a
  1. 7
      scdoc.5.scd
  2. 26
      src/main.c

@ -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\*

@ -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;

Loading…
Cancel
Save