Formatting in comments

The comments to the posts here are generally very helpful.

I appreciate your contributions to the site.

I wanted to offer a tip for those who leave comments and are frustrated by the way the comments appear, especially those who write nicely formatted snippet of code only to see the formatting lost.

There is a way to post formatted code.

Comments can use basic HTML markup.

In particular, you can wrap a section of code with <pre> and </pre> and the levels of indentation will be retained.

Sometimes I see that someone has left a block of code wrapped between <code> and </code> tags, but this doesn’t do what they expected.

That’s because <code> is an inline element and <pre> is a block element.

The former can be used in the middle of a sentence, such as referring to the qsort function, but for multiple lines of code you need the latter.

The comment editor does not accept LaTeX markup, but you can write a fair amount of mathematics with plain HTML.

Thanks again for your comments.

.

Leave a Reply