Salagir's Blog

Old name was: "Why do witches burn?"

This is french section. Go to English version

Convert HTML into BBcode

Le avril 8th, 2009

BBcode is the syntax used in phpBB forums and some other websites with edit forms, due to it’s simple and intuitive syntax, opposed to that stupid wiki code no one ever gets.

If, like me, you ever wanted to post the content of an html page, this Perl script is for you.
It takes a HTML file and creates a text file with the BB syntax.
You only need to copy this text into your post.

This is not made to copy-paste images, weird colors and CSS… Only text with some bold, italic, paragraphs, and others…

I wrote this script, in 2005, simply because I didn’t find any that was doing the same thing as well as I wanted.

It’d be better, for a good use of the script, that the html is valid

Example :
File test.html :

<p>What a <b>beautiful</b> day!!<br />
The sun...</p>
<p>The sunny shines !</p>

Running:

$ perl html2bbcode.pl test.html

Resulting file test.bb :

What a [b]beautiful[/b] day!!
The sun...


The sunny shines !

You can download the code:

Leave a Reply