Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-123133

QTextDocument .toMarkdown() formats Markdown incorrectly - not closing Markdown characters appropriately

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.6.2
    • GUI: Text handling
    • None
    • macOS

    Description

      Hello,

       

      While developing my block editor (https://get-plume.com) I came across your QML texteditor example (https://doc.qt.io/qt-6/qtquickcontrols-texteditor-example.html). While very useful, there is a clear bug when converting a QTextDocument with multiple formating options applied to Markdown.

       

      For example, when formatting a selection using both underline and italic, the HTML shows ok, but upon converting the QTextDocument doc to Markdown via doc.toMarkdown() this is the output:

      "*_some*_"

      While it should be:

      "*_some_*"

       

      Same with strike-through and bold:

      "**~~some**~~"

      While it should be:

      "**~~some~~**"

       

      I thought I might be able to convert the HTML using a third party library (https://github.com/tim-gromeyer/html2md) but the HTML produced by QTextDocument doesn't seem standard, therefore, the third party library doesn't recognize the format.

       

      Here's a very simple code to reproduce this bug:

      #include <QApplication>
      #include <QString>
      #include <QTextDocument>int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);    
          QString html = "<html><body><u><i>something</i></u></body></html>";           
          QTextDocument textDoc;
          textDoc.setHtml(html);
          qDebug() << textDoc.toMarkdown();    
          return app.exec();
      }
       

      Which prints the following wrong string:

      "*_something*_\n\n"

      Where it should be:

      "*_something_*\n\n"

       

      I would love if you could fix it soon, as it will prevent me from working on a weird hack around it. Thanks!

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            rubymamis Ruby Mamistvalove
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes