For some reason, my code highlighting works when I'm editing the question, but not in my actual post.
(I've tried giving it a hint; no difference.)
Is this a bug?
The question does not have any tags that designate which rules to highlight the code. See Changes to syntax highlighting for more information.
Just put in
The reason it "works" in the edit preview is that it's performing a best-guess highlight. It looks to me like it's best guess is C, which makes sense here. Once you submit the answer, it uses the question tags to determine the highlighting that is applied.
If you are really interested in getting syntax highlighting for D code, you'll need to either submit a bug to Google's Code Prettify project and wait for them to add it, or submit a patch yourself. More information is available in my answer here: Why is there no syntax highlight for SQL merge statements?