Menu

#28 RichText - Extract Body from HTML

1.0
closed
aliks-os
None
2014-12-23
2014-12-22
Mauro Anjo
No

Hey Alik,

I tested your html body extraction for RichText field and I suggest you to change it as above, since body tag has arguments and rarely will be "" and almost all times will be . So I changed the search string from "" to "<body". It works great :)

                if ((currentFragment.text().contains("[") && currentFragment.text().contains("]")) ||
                    (currentFragment.text().contains("<") && currentFragment.text().contains(">")))
                {
                    QString tmpTxt = sectionField(fieldObject->parentBand, currentFragment.text(), false, false, "");
                    QTextCursor c = document.find(currentFragment.text(),0,QTextDocument::FindWholeWords);
                    if (tmpTxt.isEmpty() || tmpTxt.isNull())
                        tmpTxt = " ";
                    if (tmpTxt.toLower().contains("<body") && tmpTxt.toLower().contains("</body>")) {
                        int start = tmpTxt.toLower().indexOf("<body");
                        int end = tmpTxt.toLower().indexOf("</body>")+1;
                        c.insertHtml(tmpTxt.mid(start,end));
                    } else
                        c.insertText(tmpTxt);
                }

Regards

Discussion

  • aliks-os

    aliks-os - 2014-12-23

    thank you, corrected

     
  • aliks-os

    aliks-os - 2014-12-23
    • status: open --> closed
     

Log in to post a comment.

MongoDB Logo MongoDB