Test JS with callout
Javascript
code posted
by
Yo
created at 16 Oct 14:53, updated at 05 Apr 04:16
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
/** * Add language indicator to code snippets */ // ace.config.set( // "basePath", // "https://cdn.jsdelivr.net/npm/ace-builds@1.4.12/src-noconflict/" // ) $(function () { const prefix = "language-"; const regex = new RegExp(`^${prefix}([a-z])+$`); $(`div[class^=${prefix}`).each(function () { let classes = $(this).attr("class").split(" "); classes.forEach((_class) => { if (regex.test(_class)) { const id = prefix+parseInt(Math.random()*100); let lang = _class.substring(prefix.length); $(this).attr("lang", `${lang}`); // $(this).css({"height": "500px", "width": "100%"}); // $(this).attr("id", id); // console.log(id); // ace.edit(id, { // theme: "ace/theme/dracula", // mode: `ace/mode/${lang}`, // autoScrollEditorIntoView: true, // readOnly: true // }); } }); }); }); |
1.08 KB in 2 ms with coderay