scdoc2mdoc

A fork of scdoc to output mdoc(7)
git clone git://git.sgregoratto.me/scdoc2mdoc
Log | Files | Refs | README | LICENSE

commit 49e39ef72a0c669adf03f15f0e54b0aceae3d563
parent 35028f262a0a9fbf851d224a3e2719a8ecb1300e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun, 10 Dec 2017 00:01:01 -0500

Handle escaping correctly

Diffstat:
Msrc/main.c | 22++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/main.c b/src/main.c @@ -66,7 +66,14 @@ static void parse_text(struct parser *p) { while ((ch = parser_getch(p)) != UTF8_INVALID) { switch (ch) { case '\\': - fprintf(p->output, "\\\\"); + ch = parser_getch(p); + if (ch == UTF8_INVALID) { + parser_fatal(p, "Unexpected EOF"); + } else if (ch == '\\') { + fprintf(p->output, "\\\\"); + } else { + utf8_fputch(p->output, ch); + } break; case '.': if (!i) { @@ -146,16 +153,23 @@ static void parse_document(struct parser *p) { break; } + if (indent != 0) { + // Only text is allowed at this point + parser_pushch(p, ch); + parse_text(p); + continue; + } + switch (ch) { case '#': parse_heading(p); break; - case '\n': - roff_macro(p, "P", NULL); - break; case ' ': parser_fatal(p, "Tabs are required for indentation"); break; + case '\n': + roff_macro(p, "P", NULL); + break; default: parser_pushch(p, ch); parse_text(p);