How can I show code (specifically C++) in an HTML page?

前端 未结 3 2053
独厮守ぢ
独厮守ぢ 2021-02-05 14:51

How can I show code in a website using HTML? Basically, I have a C++ program that I\'d like to share on my website and I want to show it in the page.

Is there anyway to

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-05 15:39

    HTML includes a tag called , which is meant for the purpose you describe.

    The spec even includes an example class name convention to indicate which language the code is in:

    var i: Integer;
        begin
            i := 1;
        end.

    I don’t know of any web browser that supports such a convention (come on, Chrome), but the JavaScript syntax highlighters mentioned in other answers could use it to work their magic.

    As you can see in the example, the tag is usually wrapped in the

     tag, which preserves white space, which is often important for code.

提交回复
热议问题