I now have a string of HTML
code, and I want to format the string. Is there any available method?
You need a js plug-in or method that can be used for conversion in the project.
For example, the original string is:
<p><p>This is a p</p><p>This is another p</p></p>
Add spaces and newlines to become a new string:
<p>
<p>This is a p</p>
<p>This is another p</p>
</p>
The first solution was to use regular expressions to answer the question, but it didn’t work.
I sorted out my thoughts and have solved it perfectly (I think it is perfect).
Here is the old answer for loops:
rrreeeWhy does this question of mine keep getting downvoted? Still a good question. . . .
@mqycn , @zhenguoli
This is a plan written by my friend @candy:
http://tool.oschina.net/codef... online. Other editors include beauty
For development tools, you can try the VSCode editor.
https://code.visualstudio.com/
After the installation is complete, press shift-ctrl-x to open the plug-in list, search for Beautify and install it to beautify HTML code.
Refer to here for the corresponding settings:
https://marketplace.visualstu...
For format conversion in code, you can use HTML String Parser, such as
https://www.npmjs.com/package...
Or you can use cheerio to parse the DOM text and re-output it.
3. (It is not difficult to re-create an HTML Parser, refer to my column
http://ewind.us/2016/toy-html...