Support the markdown underline extension
MarkdownDialectGitHub now includes this feature, so *emph* is italicized and _emph_ is underlined. This is a better fit for QTextDocument capabilities; until now, _underlined_ markdown could be read, but would be rendered with italics, because in CommonMark, *emphasis* and _emphasis_ are the same. But QTextMarkdownWriter already writes underlining and italics distinctly in this way. [ChangeLog][QtGui][Text] By default (with MarkdownDialectGitHub), markdown _underline_ and *italic* text styles are now distinct. Fixes: QTBUG-84429 Change-Id: Ifc6defa4852abe831949baa4ce28bae5f1a82265 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
2106a625e8
commit
f5c7799f59
@ -11,10 +11,12 @@ comments in each of the following sections to encourage you to experiment.
|
||||
|
||||
## Font and Paragraph Styles
|
||||
|
||||
QTextEdit supports **bold**, *italic*, & ~~strikethrough~~ font styles, and
|
||||
can display <span style="font-size:10pt; font-weight:600;
|
||||
color:#00007f;">multicolored</span> text. Font families such as <span
|
||||
style="font-family:Times New Roman">Times New Roman</span> and `Courier`
|
||||
QTextEdit supports **bold**, *italic*, _underline_ & ~~strikethrough~~ font
|
||||
styles, and can display
|
||||
<span style="font-size:10pt; font-weight:600; color:#00007f;"> multicolored</span>
|
||||
text. Font families such as
|
||||
<span style="font-family:Times New Roman">Times New Roman</span> and
|
||||
<span style="font-family:Courier">Courier</span>
|
||||
can also be used directly. *If you place the cursor in a region of styled text,
|
||||
the controls in the tool bars will change to reflect the current style.*
|
||||
|
||||
|
@ -151,7 +151,7 @@ public:
|
||||
enum MarkdownFeature {
|
||||
MarkdownNoHTML = 0x0020 | 0x0040,
|
||||
MarkdownDialectCommonMark = 0,
|
||||
MarkdownDialectGitHub = 0x0004 | 0x0008 | 0x0400 | 0x0100 | 0x0200 | 0x0800
|
||||
MarkdownDialectGitHub = 0x0004 | 0x0008 | 0x0400 | 0x0100 | 0x0200 | 0x0800 | 0x4000
|
||||
};
|
||||
Q_DECLARE_FLAGS(MarkdownFeatures, MarkdownFeature)
|
||||
Q_FLAG(MarkdownFeatures)
|
||||
|
@ -69,12 +69,13 @@ static_assert(int(QTextMarkdownImporter::FeatureNoHTMLBlocks) == MD_FLAG_NOHTMLB
|
||||
static_assert(int(QTextMarkdownImporter::FeatureNoHTMLSpans) == MD_FLAG_NOHTMLSPANS);
|
||||
static_assert(int(QTextMarkdownImporter::FeatureTables) == MD_FLAG_TABLES);
|
||||
static_assert(int(QTextMarkdownImporter::FeatureStrikeThrough) == MD_FLAG_STRIKETHROUGH);
|
||||
static_assert(int(QTextMarkdownImporter::FeatureUnderline) == MD_FLAG_UNDERLINE);
|
||||
static_assert(int(QTextMarkdownImporter::FeaturePermissiveWWWAutoLinks) == MD_FLAG_PERMISSIVEWWWAUTOLINKS);
|
||||
static_assert(int(QTextMarkdownImporter::FeaturePermissiveAutoLinks) == MD_FLAG_PERMISSIVEAUTOLINKS);
|
||||
static_assert(int(QTextMarkdownImporter::FeatureTasklists) == MD_FLAG_TASKLISTS);
|
||||
static_assert(int(QTextMarkdownImporter::FeatureNoHTML) == MD_FLAG_NOHTML);
|
||||
static_assert(int(QTextMarkdownImporter::DialectCommonMark) == MD_DIALECT_COMMONMARK);
|
||||
static_assert(int(QTextMarkdownImporter::DialectGitHub) == MD_DIALECT_GITHUB);
|
||||
static_assert(int(QTextMarkdownImporter::DialectGitHub) == MD_DIALECT_GITHUB | MD_FLAG_UNDERLINE);
|
||||
|
||||
// --------------------------------------------------------
|
||||
// MD4C callback function wrappers
|
||||
@ -397,6 +398,9 @@ int QTextMarkdownImporter::cbEnterSpan(int spanType, void *det)
|
||||
case MD_SPAN_STRONG:
|
||||
charFmt.setFontWeight(QFont::Bold);
|
||||
break;
|
||||
case MD_SPAN_U:
|
||||
charFmt.setFontUnderline(true);
|
||||
break;
|
||||
case MD_SPAN_A: {
|
||||
MD_SPAN_A_DETAIL *detail = static_cast<MD_SPAN_A_DETAIL *>(det);
|
||||
QString url = QString::fromUtf8(detail->href.text, int(detail->href.size));
|
||||
|
@ -80,6 +80,7 @@ public:
|
||||
FeatureStrikeThrough = 0x0200,
|
||||
FeaturePermissiveWWWAutoLinks = 0x0400,
|
||||
FeatureTasklists = 0x0800,
|
||||
FeatureUnderline = 0x4000,
|
||||
// composite flags
|
||||
FeaturePermissiveAutoLinks = FeaturePermissiveMailAutoLinks
|
||||
| FeaturePermissiveURLAutoLinks | FeaturePermissiveWWWAutoLinks,
|
||||
|
@ -69,9 +69,10 @@ public:
|
||||
Normal = 0x0,
|
||||
Italic = 0x1,
|
||||
Bold = 0x02,
|
||||
Strikeout = 0x04,
|
||||
Mono = 0x08,
|
||||
Link = 0x10
|
||||
Underlined = 0x04,
|
||||
Strikeout = 0x08,
|
||||
Mono = 0x10,
|
||||
Link = 0x20
|
||||
};
|
||||
Q_DECLARE_FLAGS(CharFormats, CharFormat)
|
||||
};
|
||||
@ -252,6 +253,12 @@ void tst_QTextMarkdownImporter::nestedSpans_data()
|
||||
QTest::newRow("bold italic")
|
||||
<< "before ***bold italic*** after"
|
||||
<< 1 << (Bold | Italic);
|
||||
QTest::newRow("bold underlined")
|
||||
<< "before **_bold underlined_** after"
|
||||
<< 1 << (Bold | Underlined);
|
||||
QTest::newRow("italic underlined")
|
||||
<< "before *_italic underlined_* after"
|
||||
<< 1 << (Italic | Underlined);
|
||||
QTest::newRow("bold strikeout")
|
||||
<< "before **~~bold strikeout~~** after"
|
||||
<< 1 << (Bold | Strikeout);
|
||||
@ -322,12 +329,14 @@ void tst_QTextMarkdownImporter::nestedSpans()
|
||||
QTextCharFormat fmt = cur.charFormat();
|
||||
qCDebug(lcTests) << "word" << wordToCheck << cur.selectedText() << "font" << fmt.font()
|
||||
<< "weight" << fmt.fontWeight() << "italic" << fmt.fontItalic()
|
||||
<< "underlined" << fmt.fontUnderline()
|
||||
<< "strikeout" << fmt.fontStrikeOut() << "anchor" << fmt.isAnchor()
|
||||
<< "monospace" << QFontInfo(fmt.font()).fixedPitch() // depends on installed fonts (QTBUG-75649)
|
||||
<< fmt.fontFixedPitch() // returns false even when font family is "monospace"
|
||||
<< fmt.hasProperty(QTextFormat::FontFixedPitch); // works
|
||||
QCOMPARE(fmt.fontWeight() > QFont::Normal, expectedFormat.testFlag(Bold));
|
||||
QCOMPARE(fmt.fontItalic(), expectedFormat.testFlag(Italic));
|
||||
QCOMPARE(fmt.fontUnderline(), expectedFormat.testFlag(Underlined));
|
||||
QCOMPARE(fmt.fontStrikeOut(), expectedFormat.testFlag(Strikeout));
|
||||
QCOMPARE(fmt.isAnchor(), expectedFormat.testFlag(Link));
|
||||
QCOMPARE(fmt.hasProperty(QTextFormat::FontFixedPitch), expectedFormat.testFlag(Mono));
|
||||
|
@ -11,10 +11,11 @@ comments in each of the following sections to encourage you to experiment.
|
||||
|
||||
## Font and Paragraph Styles
|
||||
|
||||
QTextEdit supports **bold**, *italic*, and ~~strikethrough~~ font styles, and can
|
||||
display multicolored text. Font families such as Times New Roman and `Courier`
|
||||
can also be used directly. *If you place the cursor in a region of styled text,
|
||||
the controls in the tool bars will change to reflect the current style.*
|
||||
QTextEdit supports **bold**, *italic*, _underline_ and ~~strikethrough~~ font
|
||||
styles, and can display multicolored text. Font families such as Times New
|
||||
Roman and `Courier` can also be used directly. *If you place the cursor in a
|
||||
region of styled text, the controls in the tool bars will change to reflect the
|
||||
current style.*
|
||||
|
||||
Paragraphs can be formatted so that the text is left-aligned, right-aligned,
|
||||
centered, or fully justified.
|
||||
@ -70,7 +71,7 @@ column spans, text formatting within cells, and size constraints for columns.
|
||||
|9:00 - 11:00 |Introduction to Qt |||
|
||||
|11:00 - 13:00|Using qmake |Object-oriented Programming|Layouts in Qt |
|
||||
|13:00 - 15:00|Qt Designer Tutorial |Extreme Programming |Writing Custom Styles |
|
||||
|15:00 - 17:00|Qt Linguist and Internationalization| | |
|
||||
|15:00 - 17:00|Qt Linguist and Internationalization|Test-Driven Development | |
|
||||
|
||||
*Try adding text to the cells in the table and experiment with the alignment of
|
||||
the paragraphs.*
|
||||
|
Loading…
x
Reference in New Issue
Block a user