From c29fac453f3eaac73b29eb0a66d130220d073fc6 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 31 Jan 2020 14:30:20 +0100 Subject: Markdown importer: use Unicode decoding Given we feed UTF-8 data into the importer, it must be able to cope with Unicode. Build md4c with UTF-8 support, advertise it at usage site, and change a couple of broken decodings. Driveby: the textedit example used the wrong codec to decode a Markdown file. While the Markdown spec doesn't deal with encodings, using the default one for HTML is certainly wrong. Port the loading of both markdown and plaintext to UTF-8, as that what _saving_ via QTextDocumentWriter would use by default. Change-Id: I51c6214cfe45ebfc5a67a7366f7866a5328366ec Reviewed-by: Shawn Rutledge --- src/gui/text/qtextmarkdownimporter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui/text/qtextmarkdownimporter.cpp') diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp index 88965046ce..b6a275f59c 100644 --- a/src/gui/text/qtextmarkdownimporter.cpp +++ b/src/gui/text/qtextmarkdownimporter.cpp @@ -397,8 +397,8 @@ int QTextMarkdownImporter::cbEnterSpan(int spanType, void *det) break; case MD_SPAN_A: { MD_SPAN_A_DETAIL *detail = static_cast(det); - QString url = QString::fromLatin1(detail->href.text, int(detail->href.size)); - QString title = QString::fromLatin1(detail->title.text, int(detail->title.size)); + QString url = QString::fromUtf8(detail->href.text, int(detail->href.size)); + QString title = QString::fromUtf8(detail->title.text, int(detail->title.size)); charFmt.setAnchorHref(url); charFmt.setAnchorNames(QStringList(title)); charFmt.setForeground(m_palette.link()); -- cgit v1.2.3 From 2d265dce58d26047f196d79eabfe41edab45c799 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Fri, 31 Jan 2020 14:32:24 +0100 Subject: Markdown importer: properly set hyperlinks The "title" in markdown is the tooltip, not the name attribute of a link. Also, tell the char format that it's an anchor. Change-Id: I2978848ec6705fe16376d6fe17f31007cce4b801 Reviewed-by: Shawn Rutledge --- src/gui/text/qtextmarkdownimporter.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/gui/text/qtextmarkdownimporter.cpp') diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp index b6a275f59c..7e18a10895 100644 --- a/src/gui/text/qtextmarkdownimporter.cpp +++ b/src/gui/text/qtextmarkdownimporter.cpp @@ -399,8 +399,10 @@ int QTextMarkdownImporter::cbEnterSpan(int spanType, void *det) MD_SPAN_A_DETAIL *detail = static_cast(det); QString url = QString::fromUtf8(detail->href.text, int(detail->href.size)); QString title = QString::fromUtf8(detail->title.text, int(detail->title.size)); + charFmt.setAnchor(true); charFmt.setAnchorHref(url); - charFmt.setAnchorNames(QStringList(title)); + if (!title.isEmpty()) + charFmt.setToolTip(title); charFmt.setForeground(m_palette.link()); qCDebug(lcMD) << "anchor" << url << title; } break; -- cgit v1.2.3