Browse Source

bug-fix: image links in reference format will cause crashes

Le Tan 8 years ago
parent
commit
d20dc4a0b0

+ 5 - 1
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/).
+[^1]: This guide references [Mastering Markdown](https://guides.github.com/features/mastering-markdown/).

+ 5 - 1
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/).
+[^1]: 该指南参考了 [Mastering Markdown](https://guides.github.com/features/mastering-markdown/).

+ 5 - 2
src/utils/vutils.cpp

@@ -189,8 +189,11 @@ QVector<ImageLink> VUtils::fetchImagesFromMarkdownFile(VFile *p_file,
         const VElementRegion &reg = 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;

+ 4 - 0
src/vimagepreviewer.cpp

@@ -303,6 +303,10 @@ void VImagePreviewer::fetchImageLinksFromRegions(QVector<ImageLinkInfo> &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);