New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding custom styles #292
Comments
#267 you mentioned is work in progress. I'm not sure if passing style supported in the current version. @Reeywhaar - am I right, or right ;) |
closed as dup #5 |
I thought that might be the case. In the meantime, I'll just add the styles using pure JS instead. Here's a couple of examples on how to do that for others who want to add custom styles. They work by first detecting when the From my tests both seem to work equally well so just choose the one you prefer. Example 1 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function (mutation) {
[].filter.call(mutation.addedNodes, function (node) {
return node.nodeName == 'IFRAME';
}).forEach(function (node) {
node.addEventListener('load', function (e) {
console.log("iframe content loaded");
var iframe = document.querySelector('#remark42 iframe');
// style iframe element
// iframe.style.border = "5px solid aqua";
var style = document.createElement('style');
style.id = "custom-remark-styles";
// style.textContent =
// 'body {' +
// ' background-color: green;' +
// ' font-weight: italic;' +
// '}'
// ;
style.textContent = "body { background-color: green; font-weight: italic; }\n" +
"p { padding-bottom: 0; padding-top: 0; }\n" +
"h1 { margin-top: 0; margin-bottom: 0; }\n" +
"div { padding-bottom: 0; padding-top: 0; }";
iframe.contentDocument.head.appendChild(style);
console.log(iframe.contentDocument.head);
// and disconnect
observer.disconnect();
});
});
});
});
var targetNode = document.getElementById("remark42");
observer.observe(targetNode, { childList: true, subtree: true });
// also works
// observer.observe(document.body, { childList: true, subtree: true }); Example 2 var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var observer = new MutationObserver(function(mutations) {
if (mutations[0].type === "childList") { // optional
if (document.querySelector("#remark42 iframe")) {
console.log("iframe added to dom");
var iframe = document.querySelector('#remark42 iframe');
iframe.addEventListener('load', function (e) {
console.log("iframe content loaded");
// style iframe element
// iframe.style.border = "5px solid aqua";
var style = document.createElement('style');
style.id = "custom-remark-styles";
// style.textContent =
// 'body {' +
// ' background-color: green;' +
// ' font-weight: italic;' +
// '}'
// ;
style.textContent = "body { background-color: green; font-weight: italic; }\n" +
"p { padding-bottom: 0; padding-top: 0; }\n" +
"h1 { margin-top: 0; margin-bottom: 0; }\n" +
"div { padding-bottom: 0; padding-top: 0; }";
iframe.contentDocument.head.appendChild(style);
// console.log(iframe.contentDocument.head);
// and disconnect
observer.disconnect();
});
}
}
});
var observerConfig = {
childList: true,
};
var targetNode = document.getElementById("remark42");
observer.observe(targetNode, observerConfig); |
I'd like to add some custom styles to make remark fit better with my page.
According to this remark issue, it's possible to add a custom stylesheet like this:
But it doesn't seem to be working for me. Ive tried both relative and absolute URL's e.g
https://somehost.com/css/remark.css
and/css/remark.cs
,./css/remark.css
.Am I doing it wrong?
The text was updated successfully, but these errors were encountered: