Skip to content

Commit 269812f

Browse files
authored
Merge pull request #90 from easycoder/dev
Update showdown CDN
2 parents 8def0e3 + 14d004c commit 269812f

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

dist/plugins/showdown.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ const EasyCoder_Showdown = {
2121
run: program => {
2222
const command = program[program.pc];
2323
if (typeof showdown === `undefined`) {
24-
program.require(`js`, `https://unpkg.com/showdown@1.9.1/./dist/showdown.js`, function () {
25-
EasyCoder_Showdown.setupExtension();
26-
program.run(command.pc + 1);
27-
});
24+
program.require(`js`, `https://cdn.rawgit.com/showdownjs/showdown/1.9.1/dist/showdown.min.js`,
25+
() => {
26+
EasyCoder_Showdown.setupExtension();
27+
program.run(command.pc + 1);
28+
});
2829
}
2930
else {
3031
EasyCoder_Showdown.setupExtension();

iwsy/iwsy.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,44 @@ const IWSY = (container, text) => {
569569
initScript();
570570
};
571571

572+
// Set up Showdown
573+
const setupShowdown = () => {
574+
if (typeof showdown === `undefined`) {
575+
require(`js`, `https://cdn.rawgit.com/showdownjs/showdown/1.9.1/dist/showdown.min.js`,
576+
() => {
577+
});
578+
}
579+
else {
580+
}
581+
};
582+
583+
// Load a JS or CSS library
584+
const require = (type, src, cb) => {
585+
let prefix = ``;
586+
if (src[0] == `/`) {
587+
prefix = window.location + `/`;
588+
}
589+
const element = document.createElement(type === `css` ? `link` : `script`);
590+
switch (type) {
591+
case `css`:
592+
element.type = `text/css`;
593+
element.href = `${prefix}${src}`;
594+
element.rel = `stylesheet`;
595+
break;
596+
case `js`:
597+
element.type = `text/javascript`;
598+
element.src = `${prefix}${src}`;
599+
break;
600+
default:
601+
return;
602+
}
603+
element.onload = function () {
604+
console.log(`Library ${prefix}${src} loaded`);
605+
cb();
606+
};
607+
document.head.appendChild(element);
608+
},
609+
572610
// Initialize the script
573611
const initScript = () => {
574612
document.onkeydown = null;
@@ -670,6 +708,7 @@ const IWSY = (container, text) => {
670708
if (script.runMode === `auto`) {
671709
document.addEventListener(`click`, onClick);
672710
}
711+
setupShowdown();
673712
initScript();
674713
IWSY.plugins = {};
675714
preloadImages();

js/plugins/showdown.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ const EasyCoder_Showdown = {
2121
run: program => {
2222
const command = program[program.pc];
2323
if (typeof showdown === `undefined`) {
24-
program.require(`js`, `https://unpkg.com/showdown@1.9.1/./dist/showdown.js`, function () {
25-
EasyCoder_Showdown.setupExtension();
26-
program.run(command.pc + 1);
27-
});
24+
program.require(`js`, `https://cdn.rawgit.com/showdownjs/showdown/1.9.1/dist/showdown.min.js`,
25+
() => {
26+
EasyCoder_Showdown.setupExtension();
27+
program.run(command.pc + 1);
28+
});
2829
}
2930
else {
3031
EasyCoder_Showdown.setupExtension();

0 commit comments

Comments
 (0)