diff --git a/src/main.c b/src/main.c index 72d677c..5d1892c 100644 --- a/src/main.c +++ b/src/main.c @@ -195,7 +195,7 @@ static void parse_linebreak(struct parser *p) { } static void parse_text(struct parser *p) { - uint32_t ch, last = ' '; + uint32_t ch, next, last = ' '; int i = 0; while ((ch = parser_getch(p)) != UTF8_INVALID) { switch (ch) { @@ -213,11 +213,13 @@ static void parse_text(struct parser *p) { parse_format(p, FORMAT_BOLD); break; case '_': - if (!isalnum(last) || (p->flags & FORMAT_UNDERLINE)) { + next = parser_getch(p); + if (!isalnum(last) || ((p->flags & FORMAT_UNDERLINE) && !isalnum(next))) { parse_format(p, FORMAT_UNDERLINE); } else { utf8_fputch(p->output, ch); } + parser_pushch(p, next); break; case '+': parse_linebreak(p); diff --git a/test/inline-formatting b/test/inline-formatting index 7f61ba6..cbee5fa 100755 --- a/test/inline-formatting +++ b/test/inline-formatting @@ -17,7 +17,15 @@ hello_world EOF end 0 -begin "Allows underscores in bolded words" +begin "Ignores underscores in underlined words" +scdoc </dev/null +test(8) + +_hello_world_ +EOF +end0 + +begin "Ignores underscores in bolded words" scdoc </dev/null test(8)