Results 1 to 2 of 2

Thread: Convert html to bbcode

  1. #1
    Join Date
    Feb 2011
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Convert html to bbcode

    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:

    Qt Code:
    1. <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>
    To copy to clipboard, switch view to plain text mode 

    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...

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Convert html to bbcode

    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.

  3. The following user says thank you to squidge for this useful post:

    abrahametalero (3rd March 2011)

Similar Threads

  1. Html to bbcode
    By abrahametalero in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 05:41
  2. convert ampersand encoded HTML into something readable
    By tetsuoii in forum Qt Programming
    Replies: 5
    Last Post: 24th October 2010, 18:49
  3. How to convert text to HTML in QTextEdit
    By Roszko in forum Newbie
    Replies: 5
    Last Post: 31st December 2009, 09:40
  4. Convert html links in widget actions
    By jiveaxe in forum Qt Programming
    Replies: 4
    Last Post: 16th November 2009, 12:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.