fix wysiwyg compatibility in widgets
This commit is contained in:
parent
705cf9e8ba
commit
39a1b07c07
|
|
@ -167,8 +167,7 @@ class FroghatPlugin {
|
||||||
WIDGETS = {};
|
WIDGETS = {};
|
||||||
|
|
||||||
function loadWidget(name, callback) {
|
function loadWidget(name, callback) {
|
||||||
var widget = null;
|
if (Object.keys(WIDGETS).indexOf(name) == -1) {
|
||||||
if (Object.values(WIDGETS).indexOf(name) == -1) {
|
|
||||||
(async () => {
|
(async () => {
|
||||||
await FroghatAPIv1.search("Widget", name, (res) => {
|
await FroghatAPIv1.search("Widget", name, (res) => {
|
||||||
if (res.code == 200) {
|
if (res.code == 200) {
|
||||||
|
|
@ -205,9 +204,7 @@ function loadWidget(name, callback) {
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
} else {
|
} else {
|
||||||
if (callback) {
|
return WIDGETS[name];
|
||||||
callback(WIDGETS[name]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,19 +216,36 @@ class MacroPlugin extends FroghatPlugin {
|
||||||
|
|
||||||
widget: {
|
widget: {
|
||||||
inline: true,
|
inline: true,
|
||||||
|
editable: false,
|
||||||
|
|
||||||
toHTML: (token, node) => {
|
toHTML: (token, node) => {
|
||||||
var widgetName = token.keywords.split(" ")[0];
|
var widgetName = token.keywords.split(" ")[0];
|
||||||
var contents = '';
|
var contents = '';
|
||||||
loadWidget(widgetName, (widget) => {
|
var cached = loadWidget(widgetName, (widget) => {
|
||||||
|
console.log(token, node);
|
||||||
contents = widget.processor(token, widget);
|
contents = widget.processor(token, widget);
|
||||||
var targets = wiki.element.querySelectorAll(`[data-macro-name="widget"][data-keywords="${token.keywords}"]`);
|
var targets = wiki.element.querySelectorAll(`[data-macro-name="widget"][data-keywords="${token.keywords}"]`);
|
||||||
targets.forEach(widgetElement => {
|
targets.forEach(widgetElement => {
|
||||||
widgetElement.style = widget.css;
|
widgetElement.style = widget.css;
|
||||||
widgetElement.innerHTML = contents;
|
widgetElement.innerHTML = contents;
|
||||||
});
|
});
|
||||||
|
wiki.cachedHTML = wiki.element.innerHTML;
|
||||||
});
|
});
|
||||||
return node + "</span>";
|
var ret = node + (cached ? cached.processor(token, cached) : "");
|
||||||
|
return ret;
|
||||||
|
},
|
||||||
|
postprocess: (html) => {
|
||||||
|
const buf = document.createElement('div');
|
||||||
|
buf.innerHTML = html;
|
||||||
|
var targets = buf.querySelectorAll(`[data-macro-name="widget"]`);
|
||||||
|
targets.forEach(widgetElement => {
|
||||||
|
var widget = WIDGETS[widgetElement.dataset.keywords.split(" ")[0]];
|
||||||
|
if (widget) {
|
||||||
|
widgetElement.style = widget.css;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
return buf.innerHTML;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
style: {
|
style: {
|
||||||
|
|
@ -263,9 +277,6 @@ class MacroPlugin extends FroghatPlugin {
|
||||||
toc: {
|
toc: {
|
||||||
inline: true,
|
inline: true,
|
||||||
element: 'aside',
|
element: 'aside',
|
||||||
toHTML: (token, node) => {
|
|
||||||
return node + "</aside>";
|
|
||||||
},
|
|
||||||
postprocess: (html) => {
|
postprocess: (html) => {
|
||||||
const subList = (depth) => {
|
const subList = (depth) => {
|
||||||
var li = document.createElement("li");
|
var li = document.createElement("li");
|
||||||
|
|
@ -477,7 +488,8 @@ class MacroPlugin extends FroghatPlugin {
|
||||||
},
|
},
|
||||||
postprocess: (html) => {
|
postprocess: (html) => {
|
||||||
plugin.getTokens(plugin.pattern, html).forEach(token => {
|
plugin.getTokens(plugin.pattern, html).forEach(token => {
|
||||||
html = html.replaceAll(token.source, token.rendered);
|
var pat = new RegExp('(?<!<pre>.+?)' + token.source, 'mg');
|
||||||
|
html = html.replaceAll(pat, token.rendered);
|
||||||
});
|
});
|
||||||
html = html.replaceAll(plugin.endPattern, '</div>');
|
html = html.replaceAll(plugin.endPattern, '</div>');
|
||||||
Object.values(plugin.macros).forEach(macro => {
|
Object.values(plugin.macros).forEach(macro => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user