Now there is a bit of trouble: most blog editors support HTML publishing, while most forums support UBB, which means you cannot directly copy and publish previous blog articles to the Forum. What should we do? Manually modify tags one by one? This is obviously too troublesome. Besides, lazy is a human nature! I am also a lazy, so I wrote a tool to help myself convert the HTML of my blog into the UBB format suitable for Forum Publishing, even if it cannot be completely converted, but I have helped my province to do a lot of work.
Because I have been engaged in WEB Front-end development, I know the importance of HTML semantics and how standard encoding is made. Therefore, the HTML published on my blog meets the following standards and uses these standards, this helps you achieve HTML-to-UBB conversion more successfully:
(1) All tags are legally nested and end normally
(2) The title uses the h label and the section uses the p label.
(3) Each blog image occupies one row and is centered. the img label is also placed as a new paragraph in the p label.
(4) The code snippets are generated using the blog garden editor and are the content blocks contained by a div label.
The code of this HTML 2 UBB Conversion Tool is as follows. Through the code, you can see that this is achieved through repeated replacement of regular expressions. To optimize the replacement speed, I will replace a lot of useless HTML content first, in this way, other methods do not need to replace the content. For example, the code snippets generated by the blog editor are the targets to be replaced first, it will be replaced with "[code] Here is the code snippet [/code]", and the text in the middle will be replaced with the actual code.
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ptml xmlns = "http://www.w3.org/1999/xhtml"> <pead> <meta http-equiv =" content-Type "content =" text/html; charset = UTF-8 "/> <title> HTML 2 UBB </title> <style type =" text/css "> * {margin: 0; padding: 0 }# layout {width: 800px; margin: 10px auto} textarea {width: 800px; height: 250px; font-size: 12px} input {width: 800px; height: 30px; margin: 10px 0 }</style> </pead> <body> <pre class = "code" id = "inputCode"> </textarea> <input type = "button" id = "transform" value = "[conversion]" onclick = "transform () "/> <pre class =" code "id =" outputCode "> </textarea> </body> </ptml>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
The tool is used (see the figure below): copy the HTML code you edited before publishing it to your blog and put it in the text box, and then click the "convert" button in the middle, in this way, the tool will generate the UBB text you want to paste to the Forum in the text box below, and the target code is selected, you can copy it.
NOTE: If your HTML code is different from my standards, the conversion will certainly fail. You can modify some code of this tool according to your own code standards, to achieve the desired effect. This article only provides an idea. Author: webflash