~sircmpwn/scdoc

0917856ac7d1daaea1001a6aebdc37bc099c6b21 — Damien Tardy-Panis 6 days ago da7d5e6 master
Fix parsing of line breaks followed by underlined text
2 files changed, 16 insertions(+), 4 deletions(-)

M src/main.c
M test/line-breaks
M src/main.c => src/main.c +7 -4
@@ 176,19 176,19 @@ static void parse_format(struct parser *p, enum formatting fmt) {
	p->flags ^= fmt;
}

static void parse_linebreak(struct parser *p) {
static bool parse_linebreak(struct parser *p) {
	uint32_t plus = parser_getch(p);
	if (plus != '+') {
		fprintf(p->output, "+");
		parser_pushch(p, plus);
		return;
		return false;
	}
	uint32_t lf = parser_getch(p);
	if (lf != '\n') {
		fprintf(p->output, "+");
		parser_pushch(p, lf);
		parser_pushch(p, plus);
		return;
		return false;
	}
	uint32_t ch = parser_getch(p);
	if (ch == '\n') {


@@ 197,6 197,7 @@ static void parse_linebreak(struct parser *p) {
	}
	parser_pushch(p, ch);
	fprintf(p->output, "\n.br\n");
	return true;
}

static void parse_text(struct parser *p) {


@@ 230,7 231,9 @@ static void parse_text(struct parser *p) {
			parser_pushch(p, next);
			break;
		case '+':
			parse_linebreak(p);
			if (parse_linebreak(p)) {
				last = '\n';
			}
			break;
		case '\n':
			utf8_fputch(p->output, ch);

M test/line-breaks => test/line-breaks +9 -0
@@ 35,3 35,12 @@ test(8)
hello++world
EOF
end 0

begin "Handles underlined text following line break"
scdoc <<EOF | grep '\\fIworld\\fR' >/dev/null
test(8)

hello++
_world_
EOF
end 0