diff --git a/src/main.c b/src/main.c index 2508a7f..688b544 100644 --- a/src/main.c +++ b/src/main.c @@ -286,10 +286,13 @@ static int parse_indent(struct parser *p, int *indent, bool write) { ++i; } parser_pushch(p, ch); - if (ch == '\n' && *indent != 0) { - // Don't change indent when we encounter empty lines + if ((ch == '\n' || ch == UTF8_INVALID) && *indent != 0) { + // Don't change indent when we encounter empty lines or EOF return *indent; } + if (abs(i - *indent) > 1) { + parser_fatal(p, "Changed indentation by an amount greater than 1"); + } if (write) { if (i < *indent) { for (int j = *indent; i < j; --j) { @@ -297,8 +300,6 @@ static int parse_indent(struct parser *p, int *indent, bool write) { } } else if (i == *indent + 1) { fprintf(p->output, ".RS 4\n"); - } else if (i != *indent && ch == '\t') { - parser_fatal(p, "Indented by an amount greater than 1"); } } *indent = i; diff --git a/test/indent b/test/indent index 087e30c..0df281d 100755 --- a/test/indent +++ b/test/indent @@ -19,3 +19,14 @@ Not indented Not indented EOF end 0 + +begin "Disallows indentation changes > 1" +scdoc </dev/null +test(8) + +Not indented + Indented one level + Indented three levels +Not indented +EOF +end 1