aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/eqn.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2017-06-22 00:30:20 +0000
committerIngo Schwarze <schwarze@openbsd.org>2017-06-22 00:30:20 +0000
commita6e8996beb3309355b7ba9fbf8a1349d2c8e33f9 (patch)
treea06923673e2c8c8988d00883614f1ad453a6cbf1 /eqn.c
parent740cd0a594b09fec1d26c6215b609b4fa7b33b35 (diff)
downloadmandoc-a6e8996beb3309355b7ba9fbf8a1349d2c8e33f9.tar.gz
mandoc-a6e8996beb3309355b7ba9fbf8a1349d2c8e33f9.tar.zst
mandoc-a6e8996beb3309355b7ba9fbf8a1349d2c8e33f9.zip
Fix font selection for text boxes in the terminal formatter.
Issue reported by bentley@. The AST data structure is powerful enough that all required information can easily be provided in the parser, and no change of the formatting code is needed.
Diffstat (limited to 'eqn.c')
-rw-r--r--eqn.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/eqn.c b/eqn.c
index 915a9715..96c65b1b 100644
--- a/eqn.c
+++ b/eqn.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eqn.c,v 1.29 2017/06/21 20:47:46 schwarze Exp $ */
+/* $Id: eqn.c,v 1.67 2017/06/22 00:30:20 schwarze Exp $
/*
* Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -84,6 +84,8 @@ enum eqn_tok {
EQN_TOK_ABOVE,
EQN_TOK__MAX,
EQN_TOK_FUNC,
+ EQN_TOK_QUOTED,
+ EQN_TOK_SYM,
EQN_TOK_EOF
};
@@ -517,7 +519,7 @@ eqn_tok_parse(struct eqn_node *ep, char **p)
if (quoted) {
if (p != NULL)
*p = mandoc_strndup(start, sz);
- return EQN_TOK__MAX;
+ return EQN_TOK_QUOTED;
}
for (i = 0; i < EQN_TOK__MAX; i++)
@@ -528,7 +530,7 @@ eqn_tok_parse(struct eqn_node *ep, char **p)
if (STRNEQ(start, sz,
eqnsyms[i].str, strlen(eqnsyms[i].str))) {
mandoc_asprintf(p, "\\[%s]", eqnsyms[i].sym);
- return EQN_TOK__MAX;
+ return EQN_TOK_SYM;
}
}
@@ -1084,8 +1086,10 @@ this_tok:
* TODO: make sure we're not in an open subexpression.
*/
return ROFF_EQN;
- case EQN_TOK_FUNC:
case EQN_TOK__MAX:
+ case EQN_TOK_FUNC:
+ case EQN_TOK_QUOTED:
+ case EQN_TOK_SYM:
assert(p != NULL);
/*
* If we already have something in the stack and we're
@@ -1112,17 +1116,27 @@ this_tok:
cur->text = p;
/*
* If not inside any explicit font context,
- * give every letter its own box.
+ * quoted strings become italic, and every letter
+ * of a bare string gets its own italic box.
*/
- if (fontp == NULL && *p != '\0') {
+ do {
+ if (fontp != NULL || *p == '\0' ||
+ tok == EQN_TOK_SYM)
+ break;
+ if (tok == EQN_TOK_QUOTED) {
+ cur->font = EQNFONT_ITALIC;
+ break;
+ }
cp = p;
for (;;) {
+ if (isalpha((unsigned char)*cp))
+ cur->font = EQNFONT_ITALIC;
cpn = cp + 1;
if (*cp == '\\')
mandoc_escape(&cpn, NULL, NULL);
if (*cpn == '\0')
break;
- if (isalpha((unsigned char)*cp) == 0 &&
+ if (cur->font != EQNFONT_ITALIC &&
isalpha((unsigned char)*cpn) == 0) {
cp = cpn;
continue;
@@ -1137,7 +1151,7 @@ this_tok:
cur = nbox;
cp = nbox->text;
}
- }
+ } while (0);
/*
* Post-process list status.
*/