How to preserve whitespace indentation of text enclosed in HTML
 tags excluding the current indentation level of the 
 tag in the document?

后端 未结 11 1501
萌比男神i
萌比男神i 2020-12-02 18:32

I\'m trying to display my code on a website but I\'m having problems preserving the whitespace indentation correctly.

For instance given the following snippet:

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 18:49

    The pre tag preserves all the white spaces you have used while writing in the body. Where as normally if you do not use pre it will display the text normally...(HTML will make the browser to neglect those white spaces) Here try this I have used the paragraph tag. Output:-

    Here is my code:

    def some_function

      return 'Hello, World!'

    end

    Here is my code:

    def some_function

      return 'Hello, World!'
    end

提交回复
热议问题