Как использовать формат Markdown в QML 5.14 - PullRequest
2 голосов
/ 10 января 2020

Недавно Qt 5.14 был выпущен. В этой версии добавлена ​​поддержка формата Markdown .

Добавлена ​​поддержка формата Markdown (включая диалекты CommonMark и GitHub) для Text и TextEdit в качестве альтернативы HTML. Это включает расширение контрольного списка GitHub, позволяющее переключать флажки в TextEdit.

Я ожидаю, что я могу ввести текст в TextEdit или Text и мой текст будет выглядеть это . Тот же результат вы могли видеть в Discord или StackOverflow.

Но у меня есть проблема с этим. Я не могу найти какую-либо документацию или ссылки на то, как ее использовать. Я думал, что могу найти информацию в TextEdit textFormat или Text textFormat , но есть только старые html теги (они были заменены на Markdown формат ) .

Вот некоторая часть моего кода, если вам это нужно. (Код может быть ошибочным, потому что я не проверял его после его изменения.)

import QtQuick 2.14
import QtQuick.Controls 2.14

Item {
    width: 100
    height: 100

    Text { 
        id: messageText
        height: 50
        width: 100
        text: msgLine.text
        wrapMode: Text.WrapAtWordBoundaryOrAnywhere
        textFormat: Text.StyledText
        font.pointSize: 13
        lineHeight: 1.15
        anchors.top: parent.top
    }

    TextEdit {
        id: msgLine
        height: 50
        width: 100
        anchors.top: messageText.bottom
        Text.RichText // I have changed this value to others
        verticalAlignment: Text.AlignVCenter
        TextEdit.WrapAtWordBoundaryOrAnywhere
     }
}

Я хочу спросить, есть ли какая-либо документация о том, как его использовать, или какой-либо пример , Заранее спасибо!

1 Ответ

5 голосов
/ 10 января 2020

Кажется, что это ошибка в документации Qt ( QTBUG-80749 ), если вы хотите использовать уценку в Text или TextEdit тогда вы должны установить TextEdit.MarkdownText в свойстве textFormat:

import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick.Layouts 1.14

Window {
    id: root
    visible: true
    width: 960
    height: 480
    QtObject{
        id: internals
        property string markdown_text: "*Italic*    **Bold**
# Heading 1
## Heading 2

[Link](http://a.com)

* List
* List
* List

- [x] @mentions, #refs, [links](), **formatting**, and <del>tags</del> supported
- [x] list syntax required (any unordered or ordered list supported)
- [x] this is a complete item
- [ ] this is an incomplete item

First Header | Second Header
------------ | -------------
Content from cell 1 | Content from cell 2
Content in the first column | Content in the second column
"
    }

    RowLayout{
        anchors.fill: parent
        TextEdit{
            id: te_output
            Layout.fillWidth: true
            textFormat: TextEdit.MarkdownText
            text: internals.markdown_text
        }
        Text{
            id: t_output
            Layout.fillWidth: true
            textFormat: TextEdit.MarkdownText
            text: internals.markdown_text
        }
    }
}

enter image description here

...