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.
master
Carlo Abelli 6 years ago committed by Drew DeVault
parent 533c284ee8
commit f1db2e1679
  1. 6
      src/main.c
  2. 10
      test/inline-formatting

@ -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);

@ -17,7 +17,15 @@ hello_world
EOF
end 0
begin "Allows underscores in bolded words"
begin "Ignores underscores in underlined words"
scdoc <<EOF | grep '\\fIhello_world\\fR' >/dev/null
test(8)
_hello_world_
EOF
end0
begin "Ignores underscores in bolded words"
scdoc <<EOF | grep '^\\fBhello_world\\fR' >/dev/null
test(8)

Loading…
Cancel
Save