commit 9b01ea2093def60be232a1b57a7d4b3d10b8c8b5
parent 71a5592354dd6750b75f7cd8291d1467cf9146fa
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 27 Jan 2019 10:48:28 -0500
Ignore underscores in the middle_of_a_word
Diffstat:
4 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/include/util.h b/include/util.h
@@ -12,6 +12,7 @@ struct parser {
uint32_t flags;
const char *str;
int fmt_line, fmt_col;
+ uint32_t last[2];
};
enum formatting {
diff --git a/scdoc.5.scd b/scdoc.5.scd
@@ -45,7 +45,7 @@ like this.
## FORMATTING
Text can be made *bold* or _underlined_ with asterisks and underscores: \*bold\*
-or \_underlined\_.
+or \_underlined\_. Underscores in the_middle_of_words will be disregarded.
## INDENTATION
diff --git a/src/main.c b/src/main.c
@@ -163,6 +163,11 @@ static void parse_format(struct parser *p, enum formatting fmt) {
}
fprintf(p->output, "\\fR");
} else {
+ if (fmt == FORMAT_UNDERLINE && !isspace(p->last[0])) {
+ // Ignore underscores in the middle of words
+ utf8_fputch(p->output, '_');
+ return;
+ }
fprintf(p->output, "\\f%c", formats[fmt]);
p->fmt_line = p->line;
p->fmt_col = p->col;
diff --git a/src/util.c b/src/util.c
@@ -14,24 +14,26 @@ void parser_fatal(struct parser *parser, const char *err) {
}
uint32_t parser_getch(struct parser *parser) {
+ uint32_t ch;
if (parser->qhead) {
- return parser->queue[--parser->qhead];
- }
- if (parser->str) {
+ ch = parser->queue[--parser->qhead];
+ } else if (parser->str) {
uint32_t ch = utf8_decode(&parser->str);
if (!ch || ch == UTF8_INVALID) {
parser->str = NULL;
return UTF8_INVALID;
}
- return ch;
- }
- uint32_t ch = utf8_fgetch(parser->input);
- if (ch == '\n') {
- parser->col = 0;
- ++parser->line;
} else {
- ++parser->col;
+ ch = utf8_fgetch(parser->input);
+ if (ch == '\n') {
+ parser->col = 0;
+ ++parser->line;
+ } else {
+ ++parser->col;
+ }
}
+ parser->last[0] = parser->last[1];
+ parser->last[1] = ch;
return ch;
}