Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qtextmarkdownimporter_p.h
Go to the documentation of this file.
1
// Copyright (C) 2019 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4
#
ifndef
QTEXTMARKDOWNIMPORTER_H
5
#
define
QTEXTMARKDOWNIMPORTER_H
6
7
//
8
// W A R N I N G
9
// -------------
10
//
11
// This file is not part of the Qt API. It exists purely as an
12
// implementation detail. This header file may change from version to
13
// version without notice, or even be removed.
14
//
15
// We mean it.
16
//
17
18
#
include
<
QtGui
/
qfont
.
h
>
19
#
include
<
QtGui
/
qtguiglobal
.
h
>
20
#
include
<
QtGui
/
qpalette
.
h
>
21
#
include
<
QtGui
/
qtextdocument
.
h
>
22
#
include
<
QtGui
/
qtextlist
.
h
>
23
#
include
<
QtCore
/
qpointer
.
h
>
24
#
include
<
QtCore
/
qstack
.
h
>
25
#
include
<
QtCore
/
private
/
qglobal_p
.
h
>
26
27
QT_BEGIN_NAMESPACE
28
29
class
QTextCursor;
30
class
QTextDocument;
31
class
QTextTable;
32
33
class
Q_GUI_EXPORT
QTextMarkdownImporter
34
{
35
public
:
36
enum
Feature {
37
FeatureCollapseWhitespace = 0x0001,
38
FeaturePermissiveATXHeaders = 0x0002,
39
FeaturePermissiveURLAutoLinks = 0x0004,
40
FeaturePermissiveMailAutoLinks = 0x0008,
41
FeatureNoIndentedCodeBlocks = 0x0010,
42
FeatureNoHTMLBlocks = 0x0020,
43
FeatureNoHTMLSpans = 0x0040,
44
FeatureTables = 0x0100,
45
FeatureStrikeThrough = 0x0200,
46
FeaturePermissiveWWWAutoLinks = 0x0400,
47
FeatureTasklists = 0x0800,
48
FeatureUnderline = 0x4000,
49
FeatureFrontMatter = 0x100000,
// Qt feature, not yet in MD4C
50
// NOTE: flags above are kept in sync with #define MD_FLAG_*; therefore,
51
// do NOT add any more Qt-specific flags (within the lower 32 bits).
52
// Because we have FeatureFrontMatter, we cannot support MD_FLAG_FOOTNOTES.
53
54
// composite flags
55
FeaturePermissiveAutoLinks = FeaturePermissiveMailAutoLinks
56
| FeaturePermissiveURLAutoLinks | FeaturePermissiveWWWAutoLinks,
57
FeatureNoHTML = QTextDocument::MarkdownNoHTML,
58
DialectCommonMark = QTextDocument::MarkdownDialectCommonMark,
59
DialectGitHub = QTextDocument::MarkdownDialectGitHub
60
};
61
Q_DECLARE_FLAGS(Features, Feature)
62
63
QTextMarkdownImporter(QTextDocument *doc, Features features);
64
QTextMarkdownImporter(QTextDocument *doc, QTextDocument::MarkdownFeatures features);
65
66
void
import(
const
QString &markdown);
67
68
public
:
69
// MD4C callbacks
70
int
cbEnterBlock(
int
blockType,
void
* detail);
71
int
cbLeaveBlock(
int
blockType,
void
* detail);
72
int
cbEnterSpan(
int
spanType,
void
* detail);
73
int
cbLeaveSpan(
int
spanType,
void
* detail);
74
int
cbText(
int
textType,
const
char
* text,
unsigned
size);
75
76
private
:
77
void
insertBlock();
78
79
private
:
80
QTextCursor m_cursor;
81
QTextTable *m_currentTable =
nullptr
;
// because m_cursor->currentTable() doesn't work
82
#
if
QT_CONFIG
(
regularexpression
)
83
QString m_htmlAccumulator;
84
#
endif
85
QString m_blockCodeLanguage;
86
QList<
int
> m_nonEmptyTableCells;
// in the current row
87
QStack<QPointer<QTextList>> m_listStack;
88
QStack<QTextCharFormat> m_spanFormatStack;
89
QFont m_monoFont;
90
QPalette m_palette;
91
#
if
QT_CONFIG
(
regularexpression
)
92
int
m_htmlTagDepth = 0;
93
#
endif
94
int
m_blockQuoteDepth = 0;
95
int
m_tableColumnCount = 0;
96
int
m_tableRowCount = 0;
97
int
m_tableCol = -1;
// because relative cell movements (e.g. m_cursor->movePosition(QTextCursor::NextCell)) don't work
98
int
m_paragraphMargin = 0;
99
int
m_blockType = 0;
100
char
m_blockCodeFence = 0;
101
Features m_features;
102
QTextImageFormat m_imageFormat;
103
QTextListFormat m_listFormat;
104
QTextBlockFormat::MarkerType m_markerType = QTextBlockFormat::MarkerType::NoMarker;
105
bool
m_needsInsertBlock =
false
;
106
bool
m_needsInsertList =
false
;
107
bool
m_listItem =
false
;
// true from the beginning of LI to the end of the first P
108
bool
m_codeBlock =
false
;
109
bool
m_imageSpan =
false
;
110
bool
m_blockQuoteInsideListItem =
false
;
111
};
112
113
Q_DECLARE_OPERATORS_FOR_FLAGS(QTextMarkdownImporter::Features)
114
115
QT_END_NAMESPACE
116
117
#
endif
// QTEXTMARKDOWNIMPORTER_H
QTextMarkdownImporter
Definition
qtextmarkdownimporter_p.h:34
Q_STATIC_LOGGING_CATEGORY
QT_BEGIN_NAMESPACE Q_STATIC_LOGGING_CATEGORY(lcSynthesizedIterableAccess, "qt.iterable.synthesized", QtWarningMsg)
CbDebugLog
static void CbDebugLog(const char *msg, void *userdata)
Definition
qtextmarkdownimporter.cpp:92
CbEnterSpan
static int CbEnterSpan(MD_SPANTYPE type, void *detail, void *userdata)
Definition
qtextmarkdownimporter.cpp:74
CbLeaveBlock
static int CbLeaveBlock(MD_BLOCKTYPE type, void *detail, void *userdata)
Definition
qtextmarkdownimporter.cpp:68
CbText
static int CbText(MD_TEXTTYPE type, const MD_CHAR *text, MD_SIZE size, void *userdata)
Definition
qtextmarkdownimporter.cpp:86
lfMarkerString
static constexpr auto lfMarkerString() noexcept
Definition
qtextmarkdownimporter.cpp:32
qtmi_Space
static const QChar qtmi_Space
Definition
qtextmarkdownimporter.cpp:30
qtmi_BlockQuoteIndent
static const int qtmi_BlockQuoteIndent
Definition
qtextmarkdownimporter.cpp:36
MdAlignment
static Qt::Alignment MdAlignment(MD_ALIGN a, Qt::Alignment defaultAlignment=Qt::AlignLeft|Qt::AlignVCenter)
Definition
qtextmarkdownimporter.cpp:101
crlfMarkerString
static constexpr auto crlfMarkerString() noexcept
Definition
qtextmarkdownimporter.cpp:33
CbEnterBlock
static int CbEnterBlock(MD_BLOCKTYPE type, void *detail, void *userdata)
Definition
qtextmarkdownimporter.cpp:62
qtmi_Newline
static const QChar qtmi_Newline
Definition
qtextmarkdownimporter.cpp:29
CbLeaveSpan
static int CbLeaveSpan(MD_SPANTYPE type, void *detail, void *userdata)
Definition
qtextmarkdownimporter.cpp:80
splitFrontMatter
static auto splitFrontMatter(QStringView md)
Definition
qtextmarkdownimporter.cpp:134
qtbase
src
gui
text
qtextmarkdownimporter_p.h
Generated on
for Qt by
1.18.0