Skip to content

Commit

Permalink
lean のコードブロックを lean4 web editor で開くためのボタンを表示する
Browse files Browse the repository at this point in the history
  • Loading branch information
Seasawher committed Oct 31, 2023
1 parent f5c2e4a commit 9f21ec9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ create-missing = false
build-dir = "book"

[output.html]
additional-js = []
additional-js = ["leanweb.js"]
no-section-label = true
git-repository-url = "https://github.com/lean-ja/tactic-cheetsheet"
23 changes: 23 additions & 0 deletions leanweb.js
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;

// lean4 web editor へのリンクを生成する
let escaped_code = encodeURIComponent(code_block.textContent);
let url = `https://live.lean-lang.org/#code=${escaped_code}`;

// ボタンを生成する
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);

// ボタンを挿入する
buttons.insertBefore(leanWebButton, buttons.firstChild);

// ボタンをクリックしたときに,lean4 web editor を開く
leanWebButton.addEventListener('click', function (e) {
open(url);
});
});

0 comments on commit 9f21ec9

Please sign in to comment.