Browse Source

markdown-it: support specifying image size via markdown-it-imsize plugin

Only supported in read mode.
Le Tan 7 years ago
parent
commit
6558fa85b7

+ 1 - 0
README.md

@@ -195,6 +195,7 @@ In VNote, almost everything is configurable, such as background color, font, and
 - [markdown-it-sub](https://github.com/markdown-it/markdown-it-sub) (MIT License)
 - [markdown-it-sup](https://github.com/markdown-it/markdown-it-sup) (MIT License)
 - [markdown-it-front-matter](https://github.com/craigdmckenna/markdown-it-front-matter) (MIT License)
+- [markdown-it-imsize](https://github.com/tatsy/markdown-it-imsize) (Unknown) (Thanks @Kinka for help)
 - [mermaid 7.0.0](https://github.com/knsv/mermaid) (MIT License)
 - [MathJax](https://www.mathjax.org/) (Apache-2.0)
 - [showdown](https://github.com/showdownjs/showdown) (Unknown)

+ 1 - 0
README_zh.md

@@ -196,6 +196,7 @@ VNote中,几乎一切都是可以定制的,例如背景颜色、字体以及
 - [markdown-it-sub](https://github.com/markdown-it/markdown-it-sub) (MIT License)
 - [markdown-it-sup](https://github.com/markdown-it/markdown-it-sup) (MIT License)
 - [markdown-it-front-matter](https://github.com/craigdmckenna/markdown-it-front-matter) (MIT License)
+- [markdown-it-imsize](https://github.com/tatsy/markdown-it-imsize) (Unknown) (Thanks @Kinka for help)
 - [mermaid 7.0.0](https://github.com/knsv/mermaid) (MIT License)
 - [MathJax](https://www.mathjax.org/) (Apache-2.0)
 - [showdown](https://github.com/showdownjs/showdown) (Unknown)

+ 2 - 0
src/resources/markdown-it.js

@@ -96,6 +96,8 @@ if (VMarkdownitOption.metadata) {
 
 mdit = mdit.use(window.markdownitFootnote);
 
+mdit = mdit.use(window["markdown-it-imsize.js"]);
+
 var mdHasTocSection = function(markdown) {
     var n = markdown.search(/(\n|^)\[toc\]/i);
     return n != -1;

+ 4 - 0
src/utils/markdown-it/README.md

@@ -27,3 +27,7 @@ Vitaly Puzrin
 # [markddown-it-front-matter](https://github.com/craigdmckenna/markdown-it-front-matter)
 v0.1.2
 Craig McKenna
+
+# [markdown-it-imsize](https://github.com/tatsy/markdown-it-imsize)
+v2.0.1
+Tatsuya Yatagawa

File diff suppressed because it is too large
+ 0 - 0
src/utils/markdown-it/markdown-it-imsize.min.js


+ 1 - 0
src/utils/vutils.cpp

@@ -653,6 +653,7 @@ QString VUtils::generateHtmlTemplate(const QString &p_template,
         extraFile = "<script src=\"qrc" + VNote::c_markdownitExtraFile + "\"></script>\n" +
                     "<script src=\"qrc" + VNote::c_markdownitAnchorExtraFile + "\"></script>\n" +
                     "<script src=\"qrc" + VNote::c_markdownitTaskListExtraFile + "\"></script>\n" +
+                    "<script src=\"qrc" + VNote::c_markdownitImsizeExtraFile + "\"></script>\n" +
                     "<script src=\"qrc" + VNote::c_markdownitFootnoteExtraFile + "\"></script>\n";
 
         const MarkdownitOption &opt = g_config->getMarkdownitOption();

+ 1 - 0
src/vnote.cpp

@@ -40,6 +40,7 @@ const QString VNote::c_markdownitSubExtraFile = ":/utils/markdown-it/markdown-it
 const QString VNote::c_markdownitSupExtraFile = ":/utils/markdown-it/markdown-it-sup.min.js";
 const QString VNote::c_markdownitFootnoteExtraFile = ":/utils/markdown-it/markdown-it-footnote.min.js";
 const QString VNote::c_markdownitFrontMatterExtraFile = ":/utils/markdown-it/markdown-it-front-matter.js";
+const QString VNote::c_markdownitImsizeExtraFile = ":/utils/markdown-it/markdown-it-imsize.min.js";
 
 const QString VNote::c_showdownJsFile = ":/resources/showdown.js";
 const QString VNote::c_showdownExtraFile = ":/utils/showdown/showdown.min.js";

+ 1 - 0
src/vnote.h

@@ -51,6 +51,7 @@ public:
     static const QString c_markdownitSupExtraFile;
     static const QString c_markdownitFootnoteExtraFile;
     static const QString c_markdownitFrontMatterExtraFile;
+    static const QString c_markdownitImsizeExtraFile;
 
     // Showdown
     static const QString c_showdownJsFile;

+ 1 - 0
src/vnote.qrc

@@ -214,5 +214,6 @@
         <file>resources/mathjax_preview_template.html</file>
         <file>utils/dom-to-image/dom-to-image.js</file>
         <file>utils/markdown-it/markdown-it-front-matter.js</file>
+        <file>utils/markdown-it/markdown-it-imsize.min.js</file>
     </qresource>
 </RCC>

+ 8 - 2
src/vpreviewmanager.cpp

@@ -131,7 +131,7 @@ void VPreviewManager::fetchImageLinksFromRegions(QVector<VElementRegion> p_image
     QTextDocument *doc = m_editor->document();
 
     for (int i = 0; i < p_imageRegions.size(); ++i) {
-        VElementRegion &reg = p_imageRegions[i];
+        const VElementRegion &reg = p_imageRegions[i];
         QTextBlock block = doc->findBlock(reg.m_startPos);
         if (!block.isValid()) {
             continue;
@@ -140,7 +140,13 @@ void VPreviewManager::fetchImageLinksFromRegions(QVector<VElementRegion> p_image
         int blockStart = block.position();
         int blockEnd = blockStart + block.length() - 1;
         QString text = block.text();
-        Q_ASSERT(reg.m_endPos <= blockEnd);
+
+        // Since the image links update signal is emitted after a timer, during which
+        // the content may be changed.
+        if (reg.m_endPos > blockEnd) {
+            continue;
+        }
+
         ImageLinkInfo info(reg.m_startPos,
                            reg.m_endPos,
                            blockStart,

Some files were not shown because too many files changed in this diff