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

remotes/origin/work/schwarzer/update_platform_name
Yuri Chornoivan 5 years ago committed by Albert Astals Cid
parent 7d15dc1ae6
commit 74cb4e545d
  1. 22
      generators/markdown/converter.cpp

@ -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
}
}
}
}

Loading…
Cancel
Save