Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtextmarkdownwriter_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 QTEXTMARKDOWNWRITER_P_H
5#define QTEXTMARKDOWNWRITER_P_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/private/qtguiglobal_p.h>
19#include <QtCore/QTextStream>
20
23
25
26class QAbstractItemModel;
27class QTextTableCell;
28
29class Q_GUI_EXPORT QTextMarkdownWriter
30{
31public:
32 QTextMarkdownWriter(QTextStream &stream, QTextDocument::MarkdownFeatures features);
33 bool writeAll(const QTextDocument *document);
34#if QT_CONFIG(itemmodel)
35 void writeTable(const QAbstractItemModel *table);
36#endif
37
38 int writeBlock(const QTextBlock &block, bool table, bool ignoreFormat, bool ignoreEmpty);
39 void writeFrame(const QTextFrame *frame);
40 void writeFrontMatter(const QString &fm);
41
42private:
43 struct ListInfo {
44 bool loose;
45 };
46
47 ListInfo listInfo(QTextList *list);
48 void setLinePrefixForBlockQuote(int level);
49 int measureCellWidth(const QTextTableCell &cell, bool ignoreFormat);
50
51private:
52 // The part of the writer's state that writeBlock() mutates as it goes.
53 // Grouped together so that measureCellWidth() can save, reset and restore
54 // it in one go.
55 struct BlockState {
56 QString linePrefix;
57 QString codeBlockFence;
58 int wrappedLineIndent = 0;
59 int lastListIndent = 1;
60 bool doubleNewlineWritten = false;
61 bool linePrefixWritten = false;
62 bool indentedCodeBlock = false;
63 bool fencedCodeBlock = false;
64 };
65
66 // A pointer rather than a reference, because measureCellWidth() temporarily
67 // redirects output to a scratch stream; but it is never null.
68 QTextStream *m_stream;
69
70 QTextDocument::MarkdownFeatures m_features;
71 QMap<QTextList *, ListInfo> m_listInfo;
72 BlockState m_blockState;
73};
74
75QT_END_NAMESPACE
76
77#endif // QTEXTMARKDOWNWRITER_P_H
Combined button and popup list for selecting options.
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
static const QChar qtmw_Period
static const QChar qtmw_LineBreak
static const QChar qtmw_Space
static const QChar qtmw_DoubleQuote
static int nearestWordWrapIndex(const QString &s, int before)
static const QChar qtmw_Backtick
static const QChar qtmw_CarriageReturn
static int adjacentBackticksCount(const QString &s)
static QString createLinkTitle(const QString &title)
static bool isBlankLine(const QChar *begin, const QChar *end)
static const QChar qtmw_Backslash
static void maybeEscapeFirstChar(QString &s)
static const QChar qtmw_Tab
static const QChar qtmw_Newline
static LineEndPositions findLineEnd(const QChar *begin, const QChar *end)
static void escapeSpecialCharacters(QString &s)