Near keyword does not work
Seems like near keyword in text block does not work. And we have to reorder block manually, but reordering doesn't work too in complex examples. See below.
Simple
If we want to render text near to a block or group
a; b; c; d;
foo: |txt
bar biz baz
| {
near: b
}
Expected
[a] [b] [c] [d]
↑ or↑
`foo`
Actual

Workaround
We can reorder the text block and now it works as expected without near keyword.
a; b;
foo: |txt
bar biz baz
|
c; d;

Complex
if we want to render text near to a connected block or group
a -> e; b -> f;
foo: |txt
bar biz baz
| {
near: b
}
c -> g; d -> h;
Expected
`foo`
↓ or↓
[a] [b] [c] [d]
↓ ↓ ↓ ↓
[e] [f] [g] [h]
Actual

Misc
Tested on d2 versions 0.0.13 and latest e6c7d066164040098d294c00779a2248c402c864
it does not, sorry for the lack of clarity. i have it in the next release of d2-docs to document that:
https://github.com/terrastruct/d2-docs/pull/15/files#diff-d23c28129c5e819c092f20bfcbf291203169d455eabed54a3498779040e06b20R123
we'll add support for it probably in the release after
Also, it seems near only "works" with top-level shapes. Otherwise, it gives a "failed to recompile" error and a panic dump, for example:
dog.flea
comment: |md
parasite
| {
near: dog.flea
}
documented