Handle escaping correctly

master
Drew DeVault 7 years ago
parent 35028f262a
commit 49e39ef72a
  1. 22
      src/main.c

@ -66,7 +66,14 @@ static void parse_text(struct parser *p) {
while ((ch = parser_getch(p)) != UTF8_INVALID) { while ((ch = parser_getch(p)) != UTF8_INVALID) {
switch (ch) { switch (ch) {
case '\\': 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; break;
case '.': case '.':
if (!i) { if (!i) {
@ -146,16 +153,23 @@ static void parse_document(struct parser *p) {
break; break;
} }
if (indent != 0) {
// Only text is allowed at this point
parser_pushch(p, ch);
parse_text(p);
continue;
}
switch (ch) { switch (ch) {
case '#': case '#':
parse_heading(p); parse_heading(p);
break; break;
case '\n':
roff_macro(p, "P", NULL);
break;
case ' ': case ' ':
parser_fatal(p, "Tabs are required for indentation"); parser_fatal(p, "Tabs are required for indentation");
break; break;
case '\n':
roff_macro(p, "P", NULL);
break;
default: default:
parser_pushch(p, ch); parser_pushch(p, ch);
parse_text(p); parse_text(p);

Loading…
Cancel
Save