File tree 2 files changed +27
-1
lines changed
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change
1
+ Array . from ( document . querySelectorAll ( ".language-lean" ) ) . forEach ( function ( code_block ) {
2
+ let pre_block = code_block . parentElement ;
3
+
4
+ // create a link to lean4 web editor
5
+ let escaped_code = encodeURIComponent ( code_block . textContent ) ;
6
+ let url = `https://live.lean-lang.org/#code=${ escaped_code } ` ;
7
+
8
+ // create a button
9
+ let buttons = pre_block . querySelector ( ".buttons" ) ;
10
+ let leanWebButton = document . createElement ( 'button' ) ;
11
+ leanWebButton . className = 'fa fa-external-link lean-web-button' ;
12
+ leanWebButton . hidden = true ;
13
+ leanWebButton . title = 'Run on lean4 playground' ;
14
+ leanWebButton . setAttribute ( 'aria-label' , leanWebButton . title ) ;
15
+
16
+ // insert the button
17
+ buttons . insertBefore ( leanWebButton , buttons . firstChild ) ;
18
+
19
+ // open the link when the button is clicked
20
+ leanWebButton . addEventListener ( 'click' , function ( e ) {
21
+ open ( url ) ;
22
+ } ) ;
23
+ } ) ;
Original file line number Diff line number Diff line change @@ -6,4 +6,7 @@ src = "md"
6
6
title = " Metaprogramming in Lean 4"
7
7
8
8
[output .html ]
9
- git-repository-url = " https://github.com/leanprover-community/lean4-metaprogramming-book"
9
+ git-repository-url = " https://github.com/leanprover-community/lean4-metaprogramming-book"
10
+ additional-js = [
11
+ " assets/blockPlay.js" , # Add "Run on Lean4 Playground" button to each code block
12
+ ]
You can’t perform that action at this time.
0 commit comments