Fix parsing of line breaks followed by underlined text

master
Damien Tardy-Panis 5 years ago committed by Drew DeVault
parent da7d5e6c19
commit 0917856ac7
  1. 11
      src/main.c
  2. 9
      test/line-breaks

@ -176,19 +176,19 @@ static void parse_format(struct parser *p, enum formatting fmt) {
p->flags ^= fmt; p->flags ^= fmt;
} }
static void parse_linebreak(struct parser *p) { static bool parse_linebreak(struct parser *p) {
uint32_t plus = parser_getch(p); uint32_t plus = parser_getch(p);
if (plus != '+') { if (plus != '+') {
fprintf(p->output, "+"); fprintf(p->output, "+");
parser_pushch(p, plus); parser_pushch(p, plus);
return; return false;
} }
uint32_t lf = parser_getch(p); uint32_t lf = parser_getch(p);
if (lf != '\n') { if (lf != '\n') {
fprintf(p->output, "+"); fprintf(p->output, "+");
parser_pushch(p, lf); parser_pushch(p, lf);
parser_pushch(p, plus); parser_pushch(p, plus);
return; return false;
} }
uint32_t ch = parser_getch(p); uint32_t ch = parser_getch(p);
if (ch == '\n') { if (ch == '\n') {
@ -197,6 +197,7 @@ static void parse_linebreak(struct parser *p) {
} }
parser_pushch(p, ch); parser_pushch(p, ch);
fprintf(p->output, "\n.br\n"); fprintf(p->output, "\n.br\n");
return true;
} }
static void parse_text(struct parser *p) { static void parse_text(struct parser *p) {
@ -230,7 +231,9 @@ static void parse_text(struct parser *p) {
parser_pushch(p, next); parser_pushch(p, next);
break; break;
case '+': case '+':
parse_linebreak(p); if (parse_linebreak(p)) {
last = '\n';
}
break; break;
case '\n': case '\n':
utf8_fputch(p->output, ch); utf8_fputch(p->output, ch);

@ -35,3 +35,12 @@ test(8)
hello++world hello++world
EOF EOF
end 0 end 0
begin "Handles underlined text following line break"
scdoc <<EOF | grep '\\fIworld\\fR' >/dev/null
test(8)
hello++
_world_
EOF
end 0

Loading…
Cancel
Save