Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to turn REStructeredText into html?
Forum Updated to NodeBB v4.3 + New Features

How to turn REStructeredText into html?

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 5 Posters 1.4k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nite Coder
    wrote on last edited by
    #3

    Is there a way I could transport the KTextEdit to another distro that isnt't KDE?
    Because I am making this for someone else who runs a machine with Bodhi.

    mrjjM 1 Reply Last reply
    0
    • N Nite Coder

      Is there a way I could transport the KTextEdit to another distro that isnt't KDE?
      Because I am making this for someone else who runs a machine with Bodhi.

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @Nite-Coder
      Hi , its just a Widget. If /when you can get it to compile,
      you can use it on any platform where you app can run.
      The only real issue can be it depends on other stuff from KDE, which you also need then.
      Its a Qt widget so not tied to KDE as windows manager.

      1 Reply Last reply
      1
      • N Offline
        N Offline
        Nite Coder
        wrote on last edited by
        #5

        Right! Forgot I am a year into programming and therefore forget critical details such as that! But by any chance do you know what things it depends on?

        mrjjM 1 Reply Last reply
        0
        • N Nite Coder

          Right! Forgot I am a year into programming and therefore forget critical details such as that! But by any chance do you know what things it depends on?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #6

          @Nite-Coder
          Hi
          Seems pretty clean, from first look
          https://api.kde.org/frameworks/ktextwidgets/html/classKTextEdit.html

          VRoninV 1 Reply Last reply
          1
          • mrjjM mrjj

            @Nite-Coder
            Hi
            Seems pretty clean, from first look
            https://api.kde.org/frameworks/ktextwidgets/html/classKTextEdit.html

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #7

            @mrjj said in How to turn REStructeredText into html?:

            Seems pretty clean

            It's not a walk in the park but every module is built with CMake so once you compile 1 the rest should be easy

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            mrjjM 1 Reply Last reply
            2
            • VRoninV VRonin

              @mrjj said in How to turn REStructeredText into html?:

              Seems pretty clean

              It's not a walk in the park but every module is built with CMake so once you compile 1 the rest should be easy

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @VRonin
              Ah, thx. i looked for the Tier label but i looked wrong place.
              Its tier 3? it seems so thats some mean park agreed.

              1 Reply Last reply
              0
              • N Offline
                N Offline
                Nite Coder
                wrote on last edited by Nite Coder
                #9

                So I have been working on a parser but I have run into some issues!
                I have a parser and it crashes every time I use it!

                It runs fine until I select the reStructeredText option and type something
                The error when I debugged was SIGABRT
                When it fails it just says it exited with code one.
                I am pretty certain it is the parser

                Here is my code:

                main.cpp

                #include "mainwindow.h"
                #include <QApplication>
                
                int main(int argc, char *argv[])
                {
                    QApplication app(argc, argv);
                    QCoreApplication::setApplicationName("SHtmlPlay");
                    QCoreApplication::setApplicationVersion(QT_VERSION_STR);
                    QCoreApplication::setOrganizationName("Sash");
                    
                    MainWindow w;
                    w.show();
                
                    return app.exec();
                }
                
                

                mainwindow.h

                #ifndef MAINWINDOW_H
                #define MAINWINDOW_H
                
                #include <QMainWindow>
                #include <QSplitter>
                #include <QTextEdit>
                #include <QWebEngineView>
                #include <QApplication>
                #include <QGuiApplication>
                #include <QCoreApplication>
                #include <QSettings>
                #include <QScreen>
                #include <QComboBox>
                #include <QToolBar>
                class MainWindow : public QMainWindow
                {
                    Q_OBJECT
                
                public:
                    MainWindow(QWidget *parent = 0);
                    ~MainWindow();
                protected:
                    QSplitter* pEditorLayout;
                    QWebEngineView* pEditorOutput;
                    QTextEdit* pEditor;
                    QString currentFile;
                    QComboBox* pReadTypeSelection;
                    QToolBar* pToolBar;
                    QString reStructeredTexttoHTML(QString input);
                    void writeSettings();
                    void readSettings();
                protected slots:
                    void textChanged();
                };
                
                #endif // MAINWINDOW_H
                
                

                mainwindow.cpp

                #include "mainwindow.h"
                
                MainWindow::MainWindow(QWidget *parent)
                    : QMainWindow(parent)
                {
                    readSettings();
                    pEditorLayout = new QSplitter(Qt::Horizontal);
                    pEditor = new QTextEdit;
                    pEditorOutput = new QWebEngineView;
                    
                    pToolBar = new QToolBar;
                    
                    pReadTypeSelection = new QComboBox;
                    pReadTypeSelection->addItem("HTML");
                    pReadTypeSelection->addItem("reStructeredText");
                    
                    pToolBar->addWidget(pReadTypeSelection);
                    
                    addToolBar(pToolBar);
                    
                    pEditorLayout->addWidget(pEditor);
                    pEditorLayout->addWidget(pEditorOutput);
                    pEditorLayout->setStretchFactor(1,1);
                    setCentralWidget(pEditorLayout);
                    connect(pEditor, &QTextEdit::textChanged, this, &MainWindow::textChanged);
                    connect(pReadTypeSelection, &QComboBox::currentTextChanged, this, &MainWindow::textChanged);
                }
                
                MainWindow::~MainWindow()
                {
                    writeSettings();
                    delete pEditorLayout;
                    delete pEditor;
                    delete pEditorOutput;
                    
                }
                
                //This is my parser! Not mush currently but something to parse for italics and bold
                QString MainWindow::reStructeredTexttoHTML(QString input)
                {
                    std::string str = input.toStdString();
                    if(str == "")
                        return "";
                    while(true)
                    {
                        if(str.find(std::string("**")) > 0)
                        {
                            if(str.find(std::string("**"), str.find(std::string("**"))) > 0)
                            {
                                std::string bold = str.substr( str.find(std::string("**"))+2, str.find(std::string("**"), 
                                                                        str.find(std::string("**"))-2 ));
                                bold = "<b>" + bold + "</b>";
                                int pos = str.find(std::string("**"));
                                str.erase(str.find(std::string("**")), str.find(std::string("**"), str.find(std::string("**"))));
                                bold = reStructeredTexttoHTML( QString::fromStdString( bold ) ).toStdString();
                                str.insert(pos, bold);
                            }
                            else if(str.find("*") > 0)
                            {
                                std::string italics = str.substr( str.find(std::string("**"))+2, str.find(std::string("**"), 
                                                                            str.find(std::string("**")))-2 );
                                italics = "<i>" + italics + "</i>";
                                int pos = str.find(std::string("**"));
                                str.erase(str.find(std::string("**")), str.find(std::string("**"), str.find(std::string("**"))));
                                italics = reStructeredTexttoHTML( QString::fromStdString( italics ) ).toStdString();
                                str.insert(pos, italics);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    return QString::fromStdString(str);
                }
                
                void MainWindow::textChanged()
                {
                    if(pReadTypeSelection->currentText() == "HTML")
                    {
                        pEditorOutput->setHtml(pEditor->toPlainText());
                    }
                    else if(pReadTypeSelection->currentText() == "reStructeredText")
                    {
                        pEditorOutput->setHtml(reStructeredTexttoHTML(pEditor->toPlainText()));
                    }
                    
                }
                
                
                void MainWindow::readSettings()
                {
                    QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
                    const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
                    if (geometry.isEmpty()) {
                        const QRect availableGeometry = QGuiApplication::screens().first()->availableGeometry();
                        resize(availableGeometry.width() / 3, availableGeometry.height() / 2);
                        move((availableGeometry.width() - width()) / 2,
                             (availableGeometry.height() - height()) / 2);
                    } else {
                        restoreGeometry(geometry);
                    }
                }
                
                void MainWindow::writeSettings()
                {
                    QSettings settings(QCoreApplication::organizationName(), QCoreApplication::applicationName());
                    settings.setValue("geometry", saveGeometry());
                }
                
                

                Thanks for any help in advance

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  Hi,

                  What does the stack trace of your crash tell you ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  1
                  • N Offline
                    N Offline
                    Nite Coder
                    wrote on last edited by
                    #11

                    Thanks for all the help!

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      What was the problem ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved