-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add "run on Lean4 Playground" button to code blocks
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Array.from(document.querySelectorAll(".language-lean")).forEach(function (code_block) { | ||
let pre_block = code_block.parentElement; | ||
|
||
// create a link to lean4 web editor | ||
let escaped_code = encodeURIComponent(code_block.textContent); | ||
let url = `https://live.lean-lang.org/#code=${escaped_code}`; | ||
|
||
// create a button | ||
let buttons = pre_block.querySelector(".buttons"); | ||
let leanWebButton = document.createElement('button'); | ||
leanWebButton.className = 'fa fa-external-link lean-web-button'; | ||
leanWebButton.hidden = true; | ||
leanWebButton.title = 'Run on lean4 playground'; | ||
leanWebButton.setAttribute('aria-label', leanWebButton.title); | ||
|
||
// insert the button | ||
buttons.insertBefore(leanWebButton, buttons.firstChild); | ||
|
||
// open the link when the button is clicked | ||
leanWebButton.addEventListener('click', function (e) { | ||
open(url); | ||
}); | ||
}); |
This file contains 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