Standard American style is to put the punctuation inside the quotation marks, but obviously this causes problems with technical documentation. Therefore, it has become standard practice in technical books to either put punctuation marks outside quotation when giving code examples, or seperate such examples with blockquotes or a seperate typeface. e.g.
It’s a convention accepted in America but not in England or most of the other English speaking world. It’s also a stupid convention. It is at best non-intuitive and at worst will lead to errors as you point out. It is one rule that I violate with glee.