mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-11 02:25:34 -04:00
Spoiler feature
Select text to hide, then right click --> Spoiler
This commit is contained in:
parent
cdda411c79
commit
5a8f74ce99
4 changed files with 51 additions and 0 deletions
|
@ -26,6 +26,7 @@
|
|||
#include <QMessageBox>
|
||||
#include <QTextDocumentFragment>
|
||||
#include <qmath.h>
|
||||
#include <QUrl>
|
||||
|
||||
#include "HandleRichText.h"
|
||||
#include "gui/RetroShareLink.h"
|
||||
|
@ -643,6 +644,28 @@ static void optimizeHtml(QDomDocument& doc
|
|||
continue;
|
||||
}
|
||||
|
||||
//hidden text in a
|
||||
if (element.tagName().toLower() == "a") {
|
||||
if(element.hasAttribute("href")){
|
||||
QString href = element.attribute("href", "");
|
||||
if(href.startsWith("hidden:")){
|
||||
//this text should be hidden and appear in title
|
||||
//we need this trick, because QTextEdit doesn't export the title attribute
|
||||
QString title = href.remove(0, QString("hidden:").length());
|
||||
QString text = element.text();
|
||||
element.setTagName("span");
|
||||
element.removeAttribute("href");
|
||||
QDomNodeList c = element.childNodes();
|
||||
for(int i = 0; i < c.count(); i++){
|
||||
element.removeChild(c.at(i));
|
||||
};
|
||||
element.setAttribute(QString("title"), title);
|
||||
QDomText textnode = doc.createTextNode(text);
|
||||
element.appendChild(textnode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// iterate children
|
||||
optimizeHtml(doc, element, stylesList, knownStyle);
|
||||
|
||||
|
@ -1004,3 +1027,20 @@ QString RsHtml::makeQuotedText(RSTextBrowser *browser)
|
|||
text = sl.join("\n>");
|
||||
return QString(">") + text;
|
||||
}
|
||||
|
||||
void RsHtml::insertSpoilerText(QTextCursor cursor)
|
||||
{
|
||||
QString hiddentext = cursor.selection().toPlainText();
|
||||
if(hiddentext.isEmpty()) return;
|
||||
QString publictext = "*SPOILER*";
|
||||
|
||||
QString encoded = hiddentext;
|
||||
encoded = encoded.replace(QChar('\"'), QString("""));
|
||||
encoded = encoded.replace(QChar('\''), QString("'"));
|
||||
encoded = encoded.replace(QChar('<'), QString("<"));
|
||||
encoded = encoded.replace(QChar('>'), QString(">"));
|
||||
encoded = encoded.replace(QChar('&'), QString("&"));
|
||||
|
||||
QString html = QString("<a href=\"hidden:%1\" title=\"%1\">%2</a>").arg(encoded, publictext);
|
||||
cursor.insertHtml(html);
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ class QDomDocument;
|
|||
class QDomElement;
|
||||
class EmbedInHtml;
|
||||
class RetroShareLink;
|
||||
class QTextCursor;
|
||||
|
||||
class RsHtml
|
||||
{
|
||||
|
@ -75,6 +76,7 @@ public:
|
|||
static QString plainText(const std::string &text);
|
||||
|
||||
static QString makeQuotedText(RSTextBrowser* browser);
|
||||
static void insertSpoilerText(QTextCursor cursor);
|
||||
|
||||
protected:
|
||||
void embedHtml(QTextDocument *textDocument, QDomDocument &doc, QDomElement ¤tElement, EmbedInHtml& embedInfos, ulong flag);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue