Created
April 1, 2020 18:18
-
-
Save xiangjjj/b5005573a3408edc2ed83502f860bdd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Inline Math for Notion.so | |
// @homepageURL https://www.notion.so/evertheylen/Notion-Inline-Math-9c5047a4e7c84643848b3630db8d5a5e | |
// @version 0.2.1 | |
// @match https://www.notion.so/* | |
// @grant GM_addStyle | |
// @require https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.js | |
// ==/UserScript== | |
// Instructions for use: | |
// - Make sure you have at least one normal math block on your page | |
// - Use inline code starting with "math:". For example: `math: f(x) = x^2` | |
// - Press F2 to rerender all inline math. You can of course change the shortcut in the code below. | |
// - The inline math will revert to inline code when the block becomes active. | |
GM_addStyle(` | |
.notion-frame span .katex { | |
padding-right: 0 !important; | |
} | |
`) | |
function rerender_all() { | |
var code = document.querySelectorAll("span[style*=\"monospace\"]") | |
code.forEach(function(el) { | |
var s = el.textContent | |
if (s.startsWith("$") && s.endsWith("$")) { | |
el.style.color = null | |
el.style.background = null | |
s = s.substring(1, s.length-1) | |
console.log("rendering ", s) | |
katex.render(s, el, {throwOnError: false, font: 'mathit'}) | |
} | |
}) | |
} | |
window.addEventListener('keydown', function(e) { | |
if (e.altKey) { | |
console.log("rerender!"); | |
rerender_all() | |
} | |
}, true) | |
// I don't know a good way to trigger rerender automatically yet | |
//document.addEventListener('DOMContentLoaded', rerender_all, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment