PDA

View Full Version : Convert html to bbcode



abrahametalero
2nd March 2011, 22:05
I'm trying to convert html to bbcode

I try using QRexExp, but I'm not so good with it...

That I try to do is extract the html from a QTextEdit with the function QTextEdit.toHtml().

In my QTextEdit i put the QTextEdit.setFontWeigh(), QTextEdit.setFontItalic() and QTextEdit.setFontUnderline() functions.

Here I have a problem:

The QTextEdit give to me the next html code:



<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:4800; font-style:italic; text-decoration: underline;">asdasd</span></p>


How can I remove it and put the tags that are (In this case [ b], [ i], [ u]) with it respective tag end ([/ b], [/ i], [/ u])

I search a library that help me but I don't found it
Sorry if i don't explain it good... And for my bad englesh...

squidge
2nd March 2011, 22:14
Use QDomDocument and parse the tags and attributes, converting to bb code as you go.

If your only interested in [ b], [ i], [ u], then it will be simple (If you want to just convert the html tags <B> <I> <U> then it will be even easier and you can throw away all other tags.)

Don't be tempted to parse the HTML yourself. It may seem simpler, but it's really not worth it.

There is an example of reading the tree of the XML document in the QDomDocument documentation.