scdoc2mdoc

A fork of scdoc to output mdoc(7)
git clone git://git.sgregoratto.me/scdoc2mdoc
Log | Files | Refs | README | LICENSE

commit f1db2e16795ae3e5a4b829e6f3b3d512ab855361
parent 533c284ee89113e15fdaa96ec16b5b49ca6e1657
Author: Carlo Abelli <carlo.abelli@gmail.com>
Date:   Tue, 26 Feb 2019 15:52:03 -0500

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.

Diffstat:
Msrc/main.c | 6++++--
Mtest/inline-formatting | 10+++++++++-
2 files changed, 13 insertions(+), 3 deletions(-)

diff --git 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 @@ -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)