From d20dc4a0b0c92229ee1c208128b36cd2401c033b Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 23 Sep 2017 14:56:53 +0800 Subject: [PATCH] bug-fix: image links in reference format will cause crashes --- src/resources/docs/markdown_guide_en.md | 6 +++++- src/resources/docs/markdown_guide_zh.md | 6 +++++- src/utils/vutils.cpp | 7 +++++-- src/vimagepreviewer.cpp | 4 ++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/resources/docs/markdown_guide_en.md b/src/resources/docs/markdown_guide_en.md index b99aec75..536852f7 100644 --- a/src/resources/docs/markdown_guide_en.md +++ b/src/resources/docs/markdown_guide_en.md @@ -70,6 +70,10 @@ Notice that the sequence number is irrelevant. Markdown will change the sequence [Link Text](/url/of/the/link) ``` +**Notes**: + +- It is not recommended to use image links in reference format. VNote will not preview those images. + ### Blockquotes ```md As VNote suggests: @@ -136,4 +140,4 @@ If you want to enter a new paragraph, you should add an empty line and then cont Generally, you need to add an empty line after a block element (such as code block, lists, blockquote) to explicitly end it. -[^1]: This guide references [Mastering Markdown](https://guides.github.com/features/mastering-markdown/). \ No newline at end of file +[^1]: This guide references [Mastering Markdown](https://guides.github.com/features/mastering-markdown/). diff --git a/src/resources/docs/markdown_guide_zh.md b/src/resources/docs/markdown_guide_zh.md index 9d859bcd..ac815020 100644 --- a/src/resources/docs/markdown_guide_zh.md +++ b/src/resources/docs/markdown_guide_zh.md @@ -71,6 +71,10 @@ __This text will be bold__ [Link Text](/url/of/the/link) ``` +**注意**: + +- VNote不推荐使用参考式的图片链接。VNote不会预览这些图片。 + ### 块引用 ```md As VNote suggests: @@ -137,4 +141,4 @@ This is a footnote [^1]. 一般来说,您应该在一个块元素(例如代码块、列表和块引用)后面插入一个空行来显式结束该元素。 -[^1]: 该指南参考了 [Mastering Markdown](https://guides.github.com/features/mastering-markdown/). \ No newline at end of file +[^1]: 该指南参考了 [Mastering Markdown](https://guides.github.com/features/mastering-markdown/). diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 46f16005..1ab7d59d 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -189,8 +189,11 @@ QVector VUtils::fetchImagesFromMarkdownFile(VFile *p_file, const VElementRegion ® = regions[i]; QString linkText = text.mid(reg.m_startPos, reg.m_endPos - reg.m_startPos); bool matched = regExp.exactMatch(linkText); - Q_ASSERT(matched); - Q_UNUSED(matched); + if (!matched) { + // Image links with reference format will not match. + continue; + } + QString imageUrl = regExp.capturedTexts()[2].trimmed(); ImageLink link; diff --git a/src/vimagepreviewer.cpp b/src/vimagepreviewer.cpp index b101d503..bae56f0d 100644 --- a/src/vimagepreviewer.cpp +++ b/src/vimagepreviewer.cpp @@ -303,6 +303,10 @@ void VImagePreviewer::fetchImageLinksFromRegions(QVector &p_image reg.m_endPos - reg.m_startPos)); } + if (info.m_linkUrl.isEmpty()) { + continue; + } + // Check if this image link has been previewed previously. info.m_previewImageID = isImageLinkPreviewed(info);