How to realize the function of displaying the code of blog articles


I"m going to assign a value to innerHTML, but I find it particularly troublesome. If there is too much code, I need to write a lot of code to the right of the equal sign

there is still a problem with line wrapping

is there a master who has done this function? give me some advice on how to achieve this function

Sep.26,2021

you can simply use the

  tag directly, and you can retain the code format 

.

if you want to be upscale, you can use a code highlighting plug-in highlightjs

if you need code highlighting.

source code output, just use the pre tag. For example,

  


you should first get a code editor so that you can export the code in dom format, and then render dom

.
Menu