Commit 74cb4e54 authored by Yuri Chornoivan's avatar Yuri Chornoivan Committed by Albert Astals Cid
Browse files

Show alt text instead of the missing image in the Markdown code

parent 7d15dc1a
Pipeline #68532 passed with stage
in 9 minutes and 38 seconds
......@@ -186,23 +186,29 @@ void Converter::convertImages(const QTextBlock &parent, const QDir &dir, QTextDo
if (textFragment.isValid()) {
const QTextCharFormat textCharFormat = textFragment.charFormat();
if (textCharFormat.isImageFormat()) {
// TODO: Show images from http URIs
QTextImageFormat format;
const qreal specifiedHeight = textCharFormat.toImageFormat().height();
const qreal specifiedWidth = textCharFormat.toImageFormat().width();
format.setName(QDir::cleanPath(dir.absoluteFilePath(textCharFormat.toImageFormat().name())));
const QImage img = QImage(format.name());
setImageSize(format, specifiedWidth, specifiedHeight, img.width(), img.height());
QTextCursor cursor(textDocument);
cursor.setPosition(textFragment.position(), QTextCursor::MoveAnchor);
cursor.setPosition(textFragment.position() + textFragment.length(), QTextCursor::KeepAnchor);
cursor.removeSelectedText();
cursor.insertImage(format);
const QString imageFilePath = QDir::cleanPath(dir.absoluteFilePath(textCharFormat.toImageFormat().name()));
if (QFile::exists(imageFilePath)) {
format.setName(imageFilePath);
const QImage img = QImage(format.name());
setImageSize(format, specifiedWidth, specifiedHeight, img.width(), img.height());
cursor.insertImage(format);
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
} else if ((!textCharFormat.toImageFormat().property(QTextFormat::ImageAltText).toString().isEmpty())) {
cursor.insertText(textCharFormat.toImageFormat().property(QTextFormat::ImageAltText).toString());
#endif
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment