نسخ من khaledmahfouz5/Maqtaa
Fix async-loaded gist embed scripts (#630)
Signed-off-by: Thomas Miceli <tho.miceli@gmail.com>
هذا الالتزام موجود في:
@@ -165,10 +165,39 @@ func escapeJavaScriptContent(htmlContent, cssUrl, themeUrl string) (string, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
js := fmt.Sprintf(`
|
js := fmt.Sprintf(`
|
||||||
document.write('<link rel="stylesheet" href=%s>');
|
(function() {
|
||||||
document.write('<link rel="stylesheet" href=%s>');
|
if (!customElements.get('opengist-embed')) {
|
||||||
document.write(%s);
|
customElements.define('opengist-embed', class extends HTMLElement {
|
||||||
`,
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.attachShadow({ mode: 'open' });
|
||||||
|
}
|
||||||
|
|
||||||
|
init(css1, css2, content) {
|
||||||
|
this.shadowRoot.innerHTML = %s
|
||||||
|
<style>
|
||||||
|
@import url(${css1});
|
||||||
|
@import url(${css2});
|
||||||
|
:host { display: block; all: initial; font-family: sans-serif; }
|
||||||
|
</style>
|
||||||
|
<div class="container">${content}</div>
|
||||||
|
%s;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentScript = document.currentScript || (function() {
|
||||||
|
var scripts = document.getElementsByTagName('script');
|
||||||
|
return scripts[scripts.length - 1];
|
||||||
|
})();
|
||||||
|
|
||||||
|
const instance = document.createElement('opengist-embed');
|
||||||
|
instance.init(%s, %s, %s);
|
||||||
|
currentScript.parentNode.insertBefore(instance, currentScript.nextSibling);
|
||||||
|
})();
|
||||||
|
`,
|
||||||
|
"`",
|
||||||
|
"`",
|
||||||
string(jsonCssUrl),
|
string(jsonCssUrl),
|
||||||
string(jsonThemeUrl),
|
string(jsonThemeUrl),
|
||||||
string(jsonContent),
|
string(jsonContent),
|
||||||
|
|||||||
10
public/css/embed.css
مباع
10
public/css/embed.css
مباع
@@ -35,6 +35,14 @@
|
|||||||
--border-width-1: 1px;
|
--border-width-1: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@layer base {
|
||||||
|
:host {
|
||||||
|
--tw-border-style: solid;
|
||||||
|
--tw-border-width: 0;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.opengist-embed {
|
.opengist-embed {
|
||||||
@import "tailwindcss";
|
@import "tailwindcss";
|
||||||
@layer base {
|
@layer base {
|
||||||
@@ -50,4 +58,4 @@
|
|||||||
@import './ipynb.css';
|
@import './ipynb.css';
|
||||||
@import "./style.css";
|
@import "./style.css";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم