Solve blank line breaking in front end of golang in Web Development

Time:2020-5-25

Question:

When using golang for web development, sometimes the rendered template will appear some strange blank line wrapping when it is displayed in the foreground. The specific feature is to check the blank part of CSS style sheet that has no relevant definition.

analysis:

Check the source code of the page in question, copy the blank line feed part and transcode it to Unicode code, and find that it contains\u2028Such characters [figure 1].


[figure 1]

In addition, you can directly check the HTML in the browser and select edit as HTML. You can also find that there is a small red dot in the blank. When you move the mouse, it will directly show that the character is\u2028[figure 2]. Looking up the data, we found that such line breaks are not supported in JavaScript.


[figure 2]

resolvent:

In the web page inspection, you can find that deleting these red dots directly can solve the problem. There is a way of direct front-end processing on the Internet, that is, searching the\u2028And replace it with\\u2028You can, of course, use golang in the background to process, that is, you can retrieve and replace the content before outputting HTML.


strings.Replace(html,"\u2028","",-1)

Well, the above is the whole content of this article. I hope it can help your study and work. If you have any questions, please leave a message.

Recommended Today

nuxt.js Imitating wechat app communication chat | Vue + nuxt chat | imitating wechat interface

Project overview be based on vue.js + nuxt.js +Chat room imitating wechat app interface developed by vuex + webpack + node + vant and other technologiesNuxtchatroom project。 It realizes the functions of card type drag and slide, message / expression sending, picture / video preview, red packet / circle of friends and so on. Technology […]