Simple HTML to UBB script tool code

Source: Internet
Author: User

You may be a sharing technician. Although you are not a technical expert, you want to share what you know with netizens through a blog. To let more people know about your experience, you may try to publish your blog to professional forums. 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"> 

Tip: the code can be modified before running!

The tool is used to copy the HTML code you edited before publishing it to the blog and put it in the text box. 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.

If you often use this kind of tool, we have prepared online tools for you, visit: http://tool.bkjia.com/tool/Html_Ubb.asp

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.