From f1db2e16795ae3e5a4b829e6f3b3d512ab855361 Mon Sep 17 00:00:00 2001 From: Carlo Abelli Date: Tue, 26 Feb 2019 15:52:03 -0500 Subject: [PATCH] fix underscores in underlined words Currently, the first underscore encountered while underlining ends underlining. As a result, underscores in underlined words are not ignored e.g. _hello_world_ does not parse correctly. This checks the next character to see if it is still in a word before ending underlining. --- src/main.c | 6 ++++-- test/inline-formatting | 10 +++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) 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)