You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-12-17 23:27:48 +02:00
All: Improved resource side loading
This commit is contained in:
@@ -2,7 +2,6 @@ const MarkdownIt = require('markdown-it');
|
||||
const Entities = require('html-entities').AllHtmlEntities;
|
||||
const htmlentities = (new Entities()).encode;
|
||||
const Resource = require('lib/models/Resource.js');
|
||||
const ModelCache = require('lib/ModelCache');
|
||||
const ObjectUtils = require('lib/ObjectUtils');
|
||||
const { shim } = require('lib/shim.js');
|
||||
const { _ } = require('lib/locale');
|
||||
@@ -17,7 +16,6 @@ class MdToHtml {
|
||||
this.loadedResources_ = {};
|
||||
this.cachedContent_ = null;
|
||||
this.cachedContentKey_ = null;
|
||||
this.modelCache_ = new ModelCache();
|
||||
|
||||
// Must include last "/"
|
||||
this.resourceBaseUrl_ = ('resourceBaseUrl' in options) ? options.resourceBaseUrl : null;
|
||||
@@ -30,12 +28,18 @@ class MdToHtml {
|
||||
const r = resources[n];
|
||||
k.push(r.id);
|
||||
}
|
||||
|
||||
k.push(md5(escape(body))); // https://github.com/pvorb/node-md5/issues/41
|
||||
k.push(md5(JSON.stringify(style)));
|
||||
k.push(md5(JSON.stringify(options)));
|
||||
return k.join('_');
|
||||
}
|
||||
|
||||
clearCache() {
|
||||
this.cachedContent_ = null;
|
||||
this.cachedContentKey_ = null;
|
||||
}
|
||||
|
||||
renderAttrs_(attrs) {
|
||||
if (!attrs) return '';
|
||||
|
||||
@@ -74,8 +78,6 @@ class MdToHtml {
|
||||
}
|
||||
|
||||
async loadResource(id, options) {
|
||||
// console.info('Loading resource: ' + id);
|
||||
|
||||
// Initially set to to an empty object to make
|
||||
// it clear that it is being loaded. Otherwise
|
||||
// it sometimes results in multiple calls to
|
||||
@@ -83,7 +85,6 @@ class MdToHtml {
|
||||
this.loadedResources_[id] = {};
|
||||
|
||||
const resource = await Resource.load(id);
|
||||
//const resource = await this.modelCache_.load(Resource, id);
|
||||
|
||||
if (!resource) {
|
||||
// Can happen for example if an image is attached to a note, but the resource hasn't
|
||||
@@ -92,6 +93,12 @@ class MdToHtml {
|
||||
return;
|
||||
}
|
||||
|
||||
if (resource.fetch_status !== Resource.FETCH_STATUS_DONE) {
|
||||
delete this.loadedResources_[id];
|
||||
console.warn('Resource not yet fetched: ' + id);
|
||||
return;
|
||||
}
|
||||
|
||||
this.loadedResources_[id] = resource;
|
||||
|
||||
if (options.onResourceLoaded) options.onResourceLoaded();
|
||||
@@ -209,7 +216,6 @@ class MdToHtml {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
renderTokens_(markdownIt, tokens, options) {
|
||||
let output = [];
|
||||
let previousToken = null;
|
||||
|
||||
Reference in New Issue
Block a user