~sircmpwn/scdoc

da3cd52d0a58e1c0042cb5f9dd8293e40e8f310d — Drew DeVault 3 years ago 3320c97
Add support for explicit line breaks
2 files changed, 33 insertions(+), 0 deletions(-)

M scdoc.5.scd
M src/main.c
M scdoc.5.scd => scdoc.5.scd +7 -0
@@ 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\*

M src/main.c => src/main.c +26 -0
@@ 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;