File indexing completed on 2024-04-28 11:20:46

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
0004 */
0005 
0006 #include <QJsonValue>
0007 
0008 #include "helpresult.h"
0009 using namespace Cantor;
0010 
0011 class Cantor::HelpResultPrivate
0012 {
0013 public:
0014     HelpResultPrivate() = default;
0015     ~HelpResultPrivate() = default;
0016 
0017     QString html;
0018 };
0019 
0020 HelpResult::HelpResult(const QString& text, bool isHtml) : d(new HelpResultPrivate)
0021 {
0022     QString html;
0023     if (!isHtml)
0024     {
0025         html = text.toHtmlEscaped();
0026         html.replace(QLatin1Char(' '), QLatin1String("&nbsp;"));
0027         html.replace(QLatin1Char('\n'), QLatin1String("<br/>\n"));
0028     }
0029     else
0030         html = text;
0031 
0032     d->html = html;
0033 }
0034 
0035 Cantor::HelpResult::~HelpResult()
0036 {
0037     delete d;
0038 }
0039 
0040 int HelpResult::type()
0041 {
0042     return HelpResult::Type;
0043 }
0044 
0045 QDomElement HelpResult::toXml(QDomDocument& doc)
0046 {
0047     //No need to save results of a help request
0048     QDomElement e=doc.createElement(QStringLiteral("Result"));
0049     e.setAttribute(QStringLiteral("type"), QStringLiteral("help"));
0050     return e;
0051 }
0052 
0053 QJsonValue Cantor::HelpResult::toJupyterJson()
0054 {
0055     // No need to save help result
0056     return QJsonValue();
0057 }
0058 
0059 QString HelpResult::toHtml()
0060 {
0061     return d->html;
0062 }
0063 
0064 QVariant HelpResult::data()
0065 {
0066     return QVariant(d->html);
0067 }
0068 
0069 QString HelpResult::mimeType()
0070 {
0071     return QStringLiteral("text/html");
0072 }
0073 
0074 void HelpResult::save(const QString& filename)
0075 {
0076     //No need to save results of a help request
0077     Q_UNUSED(filename);
0078 }