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

Only supported in read mode.
This commit is contained in:
Le Tan 2018-05-04 20:38:24 +08:00
parent ccaaeeef87
commit 6558fa85b7
10 changed files with 22 additions and 2 deletions

View File

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

View File

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

View File

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

View File

@ -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 one or more lines are too long

View File

@ -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();

View File

@ -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";

View File

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

View File

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

View File

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