14#if QT_CONFIG(itemmodel)
35 : m_stream(
stream), m_features(features)
45#if QT_CONFIG(itemmodel)
49 for (
int col = 0; col <
table->columnCount(); ++col) {
52 tableColumnWidths[col] =
qMax(tableColumnWidths[col],
58 for (
int col = 0; col <
table->columnCount(); ++col) {
63 for (
int col = 0; col < tableColumnWidths.size(); ++col)
64 m_stream <<
'|' <<
QString(tableColumnWidths[col], u
'-');
69 for (
int col = 0; col <
table->columnCount(); ++col) {
86 bool lastWasList =
false;
90 for (
int col = 0; col <
table->columns(); ++col) {
95 while (
it != cell.
end()) {
101 if (cell.
columnSpan() == 1 && tableColumnWidths[col] < cellTextLen)
102 tableColumnWidths[col] = cellTextLen;
106 while (!iterator.atEnd()) {
107 if (iterator.currentFrame() &&
child != iterator.currentFrame())
113 bool nextIsDifferent =
false;
119 nextIsDifferent =
true;
126 nextIsDifferent =
true;
131 if (tableRow < cell.
row()) {
134 for (
int col = 0; col < tableColumnWidths.
size(); ++col)
135 m_stream <<
'|' <<
QString(tableColumnWidths[col], u
'-');
139 tableRow = cell.
row();
146 nextIsDifferent && !block.
textList());
147 m_doubleNewlineWritten =
false;
150 int paddingLen = -endingCol;
152 for (
int col = cell.
column(); col < spanEndCol; ++col)
153 paddingLen += tableColumnWidths[col];
156 for (
int col = cell.
column(); col < spanEndCol; ++col)
158 }
else if (m_fencedCodeBlock && ending) {
161 m_codeBlockFence.
clear();
162 }
else if (m_indentedCodeBlock && nextIsDifferent) {
164 }
else if (endingCol > 0) {
169 m_doubleNewlineWritten =
true;
174 child = iterator.currentFrame();
179 m_doubleNewlineWritten =
true;
184QTextMarkdownWriter::ListInfo QTextMarkdownWriter::listInfo(
QTextList *
list)
194 while (
next.isValid()) {
197 qCDebug(lcMDW) <<
"next block in list" <<
list <<
next.text() <<
"part of list?" <<
next.textList();
198 if (!
next.textList()) {
201 qCDebug(lcMDW) <<
"decided list beginning with" <<
first.text() <<
"is loose after" <<
next.text();
216 before =
qMin(before,
s.size());
217 int fragBegin =
qMax(before - 15, 0);
218 if (lcMDW().isDebugEnabled()) {
220 qCDebug(lcMDW) << frag << before;
223 for (
int i = before - 1;
i >= 0; --
i) {
224 if (
s.at(
i).isSpace()) {
229 qCDebug(lcMDW,
"not possible");
237 for (
int i = 0;
i <
len; ++
i) {
241 }
else if (
start >= 0) {
257 if (firstChar ==
'*' || firstChar ==
'+' || firstChar ==
'-') {
314 while (
data < lineEndPositions.nextLineBegin) {
322 data = lineEndPositions.nextLineBegin;
333 const int ColumnLimit = 80;
335 bool missedBlankCodeBlockLine =
false;
339 if (m_fencedCodeBlock && !codeBlock) {
340 m_stream << m_linePrefix << m_codeBlockFence <<
qtmw_Newline;
341 m_fencedCodeBlock =
false;
342 m_codeBlockFence.
clear();
346 const int listLevel =
fmt.indent();
348 const int start =
fmt.start() >= 0 ?
fmt.start() : 1;
351 bool numeric =
false;
352 switch (
fmt.style()) {
355 m_wrappedLineIndent = 2;
359 m_wrappedLineIndent = 2;
363 m_wrappedLineIndent = 2;
372 m_wrappedLineIndent = 4;
375 switch (blockFmt.
marker()) {
385 int indentFirstLine = (listLevel - 1) * (numeric ? 4 : 2);
386 m_wrappedLineIndent += indentFirstLine;
387 if (m_lastListIndent != listLevel && !m_doubleNewlineWritten && listInfo(block.
textList()).loose)
389 m_lastListIndent = listLevel;
396 if (numberStr.
size() == 3)
404 m_stream <<
"- - -\n";
406 }
else if (codeBlock) {
410 missedBlankCodeBlockLine =
true;
411 if (!m_fencedCodeBlock) {
415 m_codeBlockFence =
QString(3, fenceChar.
at(0));
419 m_stream << m_linePrefix << m_codeBlockFence
421 m_fencedCodeBlock =
true;
424 }
else if (!blockFmt.
indent()) {
425 m_wrappedLineIndent = 0;
426 m_linePrefix.
clear();
432 m_linePrefix += quoteMarker;
437 m_indentedCodeBlock =
true;
443 m_stream << m_linePrefix;
449 int col = wrapIndentString.
size();
451 bool startsOrEndsWithBacktick =
false;
454 bool underline =
false;
455 bool strikeOut =
false;
458 missedBlankCodeBlockLine =
false;
459 QString fragmentText = frag.fragment().text();
461 fragmentText.
chop(1);
466 }
else if (blockFmt.
indent() > 0) {
471 startsOrEndsWithBacktick |=
474 if (
fmt.isImageFormat()) {
484 if (
wrap && col +
s.size() > ColumnLimit) {
486 col = m_wrappedLineIndent;
495 s = u
'<' + href + u
'>';
497 s = u
'[' + fragmentText +
"]("_L1 + href;
504 if (
wrap && col +
s.size() > ColumnLimit) {
506 col = m_wrappedLineIndent;
512 bool monoFrag = fontInfo.
fixedPitch() ||
fmt.fontFixedPitch();
515 if (monoFrag != mono && !m_indentedCodeBlock && !m_fencedCodeBlock) {
519 markers += backticks;
520 if (startsOrEndsWithBacktick)
525 if (fontInfo.
bold() != bold) {
527 bold = fontInfo.
bold();
529 if (fontInfo.
italic() != italic) {
531 italic = fontInfo.
italic();
546 if (
wrap && col + markers.
size() * 2 + fragmentText.
size() > ColumnLimit) {
548 const int fragLen = fragmentText.
size();
549 bool breakingLine =
false;
550 while (
i < fragLen) {
551 if (col >= ColumnLimit) {
553 col = m_wrappedLineIndent;
554 while (
i < fragLen && fragmentText[
i].isSpace())
557 int j =
i + ColumnLimit - col;
562 }
else if (wi >=
i) {
568 breakingLine =
false;
573 col += markers.
size();
575 if (col == m_wrappedLineIndent)
580 col = m_wrappedLineIndent;
582 col += subfrag.
size();
587 m_stream << markers << fragmentText;
588 col += markers.
size() + fragmentText.size();
593 if (startsOrEndsWithBacktick) {
597 m_stream << backticks;
598 col += backticks.
size();
616 if (missedBlankCodeBlockLine)
constexpr char toLatin1() const noexcept
Returns the Latin-1 character equivalent to the QChar, or 0.
bool italic() const
Returns the italic value of the matched window system font.
bool fixedPitch() const
Returns the fixed pitch value of the matched window system font.
bool bold() const
Returns true if weight() would return a value greater than QFont::Normal; otherwise returns false.
bool strikeOut() const
Returns the strikeout value of the matched window system font.
bool underline() const
Returns the underline value of the matched window system font.
qsizetype size() const noexcept
qsizetype count() const noexcept
void resize(qsizetype size)
iterator insert(const Key &key, const T &value)
T value(const Key &key, const T &defaultValue=T()) const
bool contains(const Key &key) const
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString & replace(qsizetype i, qsizetype len, QChar after)
void reserve(qsizetype size)
Ensures the string has space for at least size characters.
void chop(qsizetype n)
Removes n characters from the end of the string.
void clear()
Clears the contents of the string and makes it null.
qsizetype size() const
Returns the number of characters in this string.
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QChar * data()
Returns a pointer to the data stored in the QString.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString trimmed() const &
MarkerType marker() const
bool nonBreakableLines() const
Returns true if the lines in the paragraph are non-breakable; otherwise returns false.
int indent() const
Returns the paragraph's indent.
iterator begin() const
Returns a text block iterator pointing to the beginning of the text block.
QTextBlockFormat blockFormat() const
Returns the QTextBlockFormat that describes block-specific properties.
bool isValid() const
Returns true if this text block is valid; otherwise returns false.
int position() const
Returns the index of the block's first character within the document.
QString text() const
Returns the block's contents as plain text.
QTextList * textList() const
If the block represents a list item, returns the list that the item belongs to; otherwise returns \nu...
\reentrant \inmodule QtGui
QString stringProperty(int propertyId) const
Returns the value of the property given by propertyId; if the property isn't of QMetaType::QString ty...
@ BlockTrailingHorizontalRulerWidth
int intProperty(int propertyId) const
Returns the value of the property specified by propertyId.
bool hasProperty(int propertyId) const
Returns true if the text format has a property with the given propertyId; otherwise returns false.
QVariant property(int propertyId) const
Returns the property specified by the given propertyId.
QString name() const
Returns the name of the image.
int itemNumber(const QTextBlock &) const
Returns the index of the list item that corresponds to the given block.
QTextListFormat format() const
Returns the list's format.
bool writeAll(const QTextDocument *document)
int writeBlock(const QTextBlock &block, bool table, bool ignoreFormat, bool ignoreEmpty)
void writeFrame(const QTextFrame *frame)
int columnSpan() const
Returns the number of columns this cell spans.
QTextFrame::iterator end() const
Returns a frame iterator pointing to the end of the table's cell.
int row() const
Returns the number of the row in the table that contains this cell.
int column() const
Returns the number of the column in the table that contains this cell.
QTextFrame::iterator begin() const
Returns a frame iterator pointing to the beginning of the table's cell.
QSet< QString >::iterator it
Combined button and popup list for selecting options.
QTextStream & endl(QTextStream &stream)
Writes '\n' to the stream and flushes the stream.
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLenum GLuint GLint level
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLint GLsizei GLsizei GLenum format
GLenum GLenum GLsizei void * row
GLenum GLenum GLsizei void * table
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
#define QStringLiteral(str)
static const QChar qtmw_Backtick
static const QChar qtmw_Backslash
static const QChar qtmw_DoubleQuote
static const QChar qtmw_CarriageReturn
static int nearestWordWrapIndex(const QString &s, int before)
static const QChar qtmw_Newline
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_Tab
static void maybeEscapeFirstChar(QString &s)
static const QChar qtmw_Period
static LineEndPositions findLineEnd(const QChar *begin, const QChar *end)
static const QChar qtmw_Space
static const QChar qtmw_LineBreak
QVideoFrameFormat::PixelFormat fmt
QFileInfo info(fileName)
[8]
const QChar * nextLineBegin
\inmodule QtCore \reentrant