ui: emphasis follows CommonMark flanking rules (pointers in code keep their asterisks)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
lotherkandClaude Sonnet 5.5 committed 2026-11-12 03:30:32 +00:00
1 parent 2e7a88c462
commit c0a295dfa7
3 files changed
+61 -3

No files matched your search

+52 -2
View File
@@ -751,6 +751,55 @@ entry_prefix(const struct entry *e, char *buf, size_t len)
#define MD_ITALIC 0x02
#define MD_CODE 0x04
/*
* Is the '*' run at p (len 1 or 2) emphasis, or just an asterisk? The rules of
* CommonMark, short: an opener is followed by text and preceded by a space or
* punctuation, a closer is preceded by text, and an opener needs its closer on
* the same line. Without this "void *ctx, const char *name" in a code answer
* lost its pointers and came out italic.
*/
static int
emph_ok(const char *start, const char *p, int len, int open_now, int in_code)
{
char prev = p > start ? p[-1] : ' ';
char next = p[len];
int prev_space = prev == ' ' || prev == '\t' || prev == '\n';
int next_space = next == '\0' || next == ' ' || next == '\t' ||
next == '\n';
const char *q;
if (in_code)
return 0;
if (open_now) /* a closer: it must follow text */
return !prev_space;
if (next_space) /* an opener: it must precede text */
return 0;
if (!(prev_space || strchr("([{\"'-,.;:/", prev) != NULL))
return 0;
/*
* ... and a closer must follow on this line before another opener does:
* the nearest opener takes the closer, the earlier ones stay asterisks.
*/
for (q = p + len; *q != '\0' && *q != '\n'; q++) {
int rl = 0;
if (*q != '*')
continue;
while (q[rl] == '*')
rl++;
if (rl == len) {
char pq = q[-1], nq = q[rl];
if (pq != ' ' && pq != '\t')
return 1; /* a closer */
if (nq != '\0' && nq != ' ' && nq != '\t' && nq != '\n')
return 0; /* a nearer opener */
}
q += rl - 1;
}
return 0;
}
static size_t
md_strip_n(const char *in, char *out, unsigned char *attr)
{
@@ -782,7 +831,8 @@ md_strip_n(const char *in, char *out, unsigned char *attr)
bold = 1;
continue;
}
if (!fence && p[0] == '*' && p[1] == '*') {
if (!fence && p[0] == '*' && p[1] == '*' &&
emph_ok(in, p, 2, bold, code)) {
bold = !bold;
p += 2;
continue;
@@ -797,7 +847,7 @@ md_strip_n(const char *in, char *out, unsigned char *attr)
* Qwen3.6-35B-A3B-UD-Q8_K_XL came out as Qwen3.6-35B-A3B-UD-Q8KX,
* which is a different model as far as a reader is concerned.
*/
if (!fence && *p == '*') {
if (!fence && *p == '*' && emph_ok(in, p, 1, italic, code)) {
italic = !italic;
p++;
continue;
+4 -1
View File
@@ -20,7 +20,10 @@ class H(http.server.BaseHTTPRequestHandler):
self.send_header("Content-Type", "text/event-stream")
self.end_headers()
w = self.wfile.write
if last["role"] == "tool":
if last["role"] == "user" and "pointers" in str(last.get("content")):
w(ev({"choices": [{"delta": {"content":
"void *ctx, const char *name -- **bold** and *it*"}}]}))
elif last["role"] == "tool":
w(ev({"choices": [{"delta": {"content":
"obs: " + str(last.get("content", ""))[:300]}}]}))
else:
+5
View File
@@ -71,6 +71,11 @@ tmux new-session -d -s $S -x 120 -y 30 -c "$D/proj" \
SPLINTER_COOLDOWN_DIR=$D/c $PWD/splinter --no-config \
--endpoint http://127.0.0.1:$P/v1/chat/completions --model m --chat 2>/dev/null"
check "German UI from LANG=de_DE" shows 'bereit'
# an asterisk in code is an asterisk; real emphasis loses its markers
tmux send-keys -t $S -l 'pointers bitte'
tmux send-keys -t $S Enter
check "pointers keep their asterisks" shows 'void \*ctx, const char \*name'
check "bold loses its markers" shows -- '-- bold and it'
check "no raw catalogue keys on the screen" sh -c \
"! tmux capture-pane -t $S -p | grep -Eq '(^|[ >])(ui|sidebar|status|widget|agent|usage|role)\.[a-z_]+'"