Redraw mermaid on preview
This commit is contained in:
parent
f03f70345a
commit
ca9f874afb
@ -313,6 +313,15 @@ define([
|
|||||||
// finally, find all 'clickable' items and remove the class
|
// finally, find all 'clickable' items and remove the class
|
||||||
$el.find('.clickable').removeClass('clickable');
|
$el.find('.clickable').removeClass('clickable');
|
||||||
};
|
};
|
||||||
|
var renderMermaid = function ($el) {
|
||||||
|
Mermaid.init(undefined, $el);
|
||||||
|
// clickable elements in mermaid don't work well with our sandboxing setup
|
||||||
|
// the function below strips clickable elements but still leaves behind some artifacts
|
||||||
|
// tippy tooltips might still be useful, so they're not removed. It would be
|
||||||
|
// preferable to just support links, but this covers up a rough edge in the meantime
|
||||||
|
removeMermaidClickables($el);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
DiffMd.apply = function (newHtml, $content, common) {
|
DiffMd.apply = function (newHtml, $content, common) {
|
||||||
var contextMenu = common.importMediaTagMenu();
|
var contextMenu = common.importMediaTagMenu();
|
||||||
@ -387,8 +396,15 @@ define([
|
|||||||
var mts = [];
|
var mts = [];
|
||||||
$content.find('media-tag, pre.mermaid').each(function (i, el) {
|
$content.find('media-tag, pre.mermaid').each(function (i, el) {
|
||||||
if (el.nodeName.toLowerCase() === "pre") {
|
if (el.nodeName.toLowerCase() === "pre") {
|
||||||
|
var clone = el.cloneNode();
|
||||||
return void mts.push({
|
return void mts.push({
|
||||||
svg: el.cloneNode(true)
|
svg: clone,
|
||||||
|
render: function () {
|
||||||
|
var $el = $(clone);
|
||||||
|
$el.text(clone.getAttribute('mermaid-source'));
|
||||||
|
$el.attr('data-processed', '');
|
||||||
|
renderMermaid($el);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var $el = $(el);
|
var $el = $(el);
|
||||||
@ -401,7 +417,7 @@ define([
|
|||||||
// Find initial position
|
// Find initial position
|
||||||
var idx = -1;
|
var idx = -1;
|
||||||
mts.some(function (obj, i) {
|
mts.some(function (obj, i) {
|
||||||
if (isSvg && $mt.find('svg').attr('id') === $(obj.svg).find('svg').attr('id')) {
|
if (isSvg && $mt.attr('mermaid-source') === $(obj.svg).attr('mermaid-source')) {
|
||||||
idx = i;
|
idx = i;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -412,8 +428,15 @@ define([
|
|||||||
});
|
});
|
||||||
if (idx === -1) {
|
if (idx === -1) {
|
||||||
if (isSvg) {
|
if (isSvg) {
|
||||||
|
var clone = $mt[0].cloneNode();
|
||||||
mts.unshift({
|
mts.unshift({
|
||||||
svg: $mt[0].cloneNode(true)
|
svg: clone,
|
||||||
|
render: function () {
|
||||||
|
var $el = $(clone);
|
||||||
|
$el.text(clone.getAttribute('mermaid-source'));
|
||||||
|
$el.attr('data-processed', '');
|
||||||
|
renderMermaid($el);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
mts.unshift({
|
mts.unshift({
|
||||||
@ -511,12 +534,7 @@ define([
|
|||||||
// check if you had cached a pre-rendered instance of the supplied source
|
// check if you had cached a pre-rendered instance of the supplied source
|
||||||
if (typeof(cached) !== 'object') {
|
if (typeof(cached) !== 'object') {
|
||||||
try {
|
try {
|
||||||
Mermaid.init(undefined, $el);
|
renderMermaid($el);
|
||||||
// clickable elements in mermaid don't work well with our sandboxing setup
|
|
||||||
// the function below strips clickable elements but still leaves behind some artifacts
|
|
||||||
// tippy tooltips might still be useful, so they're not removed. It would be
|
|
||||||
// preferable to just support links, but this covers up a rough edge in the meantime
|
|
||||||
removeMermaidClickables($el);
|
|
||||||
} catch (e) { console.error(e); }
|
} catch (e) { console.error(e); }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -250,36 +250,47 @@ define([
|
|||||||
|
|
||||||
// Check src and cryptkey
|
// Check src and cryptkey
|
||||||
var cfg = tags[i];
|
var cfg = tags[i];
|
||||||
|
var tag;
|
||||||
|
|
||||||
if (cfg.svg) {
|
if (cfg.svg) {
|
||||||
$spinner.hide();
|
|
||||||
$inner.append(cfg.svg);
|
$inner.append(cfg.svg);
|
||||||
locked = false;
|
if (!cfg.render) {
|
||||||
return;
|
$spinner.hide();
|
||||||
|
console.error('here');
|
||||||
|
locked = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.error('there');
|
||||||
|
setTimeout(cfg.render);
|
||||||
|
tag = cfg.svg;
|
||||||
|
} else {
|
||||||
|
var src = cfg.src;
|
||||||
|
var key = cfg.key;
|
||||||
|
if (cfg.href) {
|
||||||
|
var parsed = Hash.parsePadUrl(cfg.href);
|
||||||
|
var secret = Hash.getSecrets(parsed.type, parsed.hash, cfg.password);
|
||||||
|
var host = priv.fileHost || priv.origin || '';
|
||||||
|
src = host + Hash.getBlobPathFromHex(secret.channel);
|
||||||
|
var _key = secret.keys && secret.keys.cryptKey;
|
||||||
|
if (_key) { key = 'cryptpad:' + Nacl.util.encodeBase64(_key); }
|
||||||
|
}
|
||||||
|
if (!src || !key) {
|
||||||
|
locked = false;
|
||||||
|
$spinner.hide();
|
||||||
|
return void UI.log(Messages.error);
|
||||||
|
}
|
||||||
|
tag = h('media-tag', {
|
||||||
|
src: src,
|
||||||
|
'data-crypto-key': key
|
||||||
|
});
|
||||||
|
$inner.append(tag);
|
||||||
|
MediaTag(tag).on('error', function () {
|
||||||
|
locked = false;
|
||||||
|
$spinner.hide();
|
||||||
|
UI.log(Messages.error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var src = cfg.src;
|
|
||||||
var key = cfg.key;
|
|
||||||
if (cfg.href) {
|
|
||||||
var parsed = Hash.parsePadUrl(cfg.href);
|
|
||||||
var secret = Hash.getSecrets(parsed.type, parsed.hash, cfg.password);
|
|
||||||
var host = priv.fileHost || priv.origin || '';
|
|
||||||
src = host + Hash.getBlobPathFromHex(secret.channel);
|
|
||||||
var _key = secret.keys && secret.keys.cryptKey;
|
|
||||||
if (_key) { key = 'cryptpad:' + Nacl.util.encodeBase64(_key); }
|
|
||||||
}
|
|
||||||
if (!src || !key) {
|
|
||||||
locked = false;
|
|
||||||
$spinner.hide();
|
|
||||||
return void UI.log(Messages.error);
|
|
||||||
}
|
|
||||||
|
|
||||||
var tag = h('media-tag', {
|
|
||||||
src: src,
|
|
||||||
'data-crypto-key': key
|
|
||||||
});
|
|
||||||
$inner.append(tag);
|
|
||||||
|
|
||||||
var observer = new MutationObserver(function(mutations) {
|
var observer = new MutationObserver(function(mutations) {
|
||||||
mutations.forEach(function() {
|
mutations.forEach(function() {
|
||||||
locked = false;
|
locked = false;
|
||||||
@ -291,11 +302,6 @@ define([
|
|||||||
childList: true,
|
childList: true,
|
||||||
characterData: false
|
characterData: false
|
||||||
});
|
});
|
||||||
MediaTag(tag).on('error', function () {
|
|
||||||
locked = false;
|
|
||||||
$spinner.hide();
|
|
||||||
UI.log(Messages.error);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
show(i);
|
show(i);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user