Skip to content

Instantly share code, notes, and snippets.

@tesla3327
Last active May 29, 2023 18:39
Show Gist options
  • Save tesla3327/676d480473f2611f7354209a6fde0ba6 to your computer and use it in GitHub Desktop.
Save tesla3327/676d480473f2611f7354209a6fde0ba6 to your computer and use it in GitHub Desktop.
/**
* Run in the console to inline all code block styles before
* copy + pasting into ConvertKit in HTML mode
*/
const CSS_PROPERTIES = [
'background-color',
'font-size',
'color',
];
const arr = document.querySelectorAll('pre, pre *');
arr.forEach(el => {
// Grab computed styles
const styles = getComputedStyle(el);
// Generate inline style and apply
el.style = CSS_PROPERTIES.reduce((prev, next) => {
prev += `${next}: ${styles.getPropertyValue(next)}; color-scheme: only light;`
return prev;
}, '');
});
let html = document.querySelector('.content').innerHTML;
// Escape interpolation
html = html.replaceAll('{{', '{% raw %}{{');
html = html.replaceAll('}}', '}}{% endraw %}');
console.log(html);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment