mirror of
https://github.com/minetest/contentdb.git
synced 2024-11-14 11:33:51 +01:00
81 lines
1.6 KiB
JavaScript
81 lines
1.6 KiB
JavaScript
// @author rubenwardy
|
|
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later
|
|
|
|
$("textarea.markdown").each(function() {
|
|
async function render(plainText, preview) {
|
|
const response = await fetch(new Request("/api/markdown/", {
|
|
method: "POST",
|
|
credentials: "same-origin",
|
|
body: plainText,
|
|
headers: {
|
|
"Accept": "text/html; charset=UTF-8",
|
|
},
|
|
}));
|
|
|
|
preview.innerHTML = await response.text();
|
|
}
|
|
|
|
let timeout_id = null;
|
|
|
|
function urlInserter(url) {
|
|
return (editor) => {
|
|
var cm = editor.codemirror;
|
|
var stat = getState(cm);
|
|
var options = editor.options;
|
|
_replaceSelection(cm, stat.table, `[](${url})`);
|
|
};
|
|
}
|
|
|
|
this.easy_mde = new EasyMDE({
|
|
element: this,
|
|
hideIcons: ["image"],
|
|
showIcons: ["code", "table"],
|
|
forceSync: true,
|
|
toolbar: [
|
|
"bold",
|
|
"italic",
|
|
"heading",
|
|
"|",
|
|
"code",
|
|
"quote",
|
|
"unordered-list",
|
|
"ordered-list",
|
|
"|",
|
|
"link",
|
|
"table",
|
|
"|",
|
|
"preview",
|
|
"side-by-side",
|
|
"fullscreen",
|
|
"|",
|
|
"guide",
|
|
// {
|
|
// name: "rules",
|
|
// className: "fa fa-book",
|
|
// title: "others buttons",
|
|
// children: [
|
|
// {
|
|
// name: "rules",
|
|
// action: urlInserter("/policy_and_guidance/#2-accepted-content"),
|
|
// className: "fa fa-star",
|
|
// title: "2. Accepted content",
|
|
// text: "2. Accepted content",
|
|
// },
|
|
// ]
|
|
// },
|
|
],
|
|
previewRender: (plainText, preview) => {
|
|
if (timeout_id) {
|
|
clearTimeout(timeout_id);
|
|
}
|
|
|
|
timeout_id = setTimeout(() => {
|
|
render(plainText, preview);
|
|
timeout_id = null;
|
|
}, 500);
|
|
|
|
return preview.innerHTML;
|
|
}
|
|
});
|
|
})
|