Last active
February 6, 2018 19:39
-
-
Save stritti/e47d780cedc0146e9c3b7e7c0e8eee68 to your computer and use it in GitHub Desktop.
How to embed Microsoft MakeCode Blocks to your HTML page
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>Show Blocks</title> | |
<link rel="stylesheet" href="//pxt.azureedge.net/blob/c4478bc8315eba07849eb0eb2a4e7604081e3be7/doccdn/semantic.css" /> | |
<link rel="stylesheet" href="//pxt.azureedge.net/blob/cb1f99cdf08c83e493934fed721ec63c9123ae5f/doccdn/blockly.css" /> | |
</head> | |
<body> | |
<h1>Demo of Blocks Integration</h1> | |
<p> | |
<pre><code class="lang-blocks">basic.showNumber(2)</code></pre> | |
<pre><code class="lang-sig">basic.showNumber(2)</code></pre> | |
<pre><code class="lang-block">basic.showNumber(2)</code></pre> | |
</p> | |
<script src="//code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> | |
<script type="text/javascript" src="https://makecode.microbit.org/--embed"></script> | |
<script type="text/javascript" src="makecode-blocks.js"></script> | |
</body> | |
</html> |
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
//copied from sources of MakeCode documentation: https://makecode.microbit.org/blocks-embed | |
function renderSnippets() { | |
var codeElems = $('code') | |
for (var i = 0; i < codeElems.length; i++) { | |
codeElems[i].className = codeElems[i].className.replace('-ignore', '') | |
} | |
var downloadScreenshots = /screenshots=1/i.test(window.location.href); | |
var path = window.location.href.split('/').pop().split(/[?#]/)[0]; | |
ksRunnerReady(function () { | |
pxt.runner.renderAsync({ | |
snippetClass: 'lang-blocks', | |
signatureClass: 'lang-sig', | |
blocksClass: 'lang-block', | |
shuffleClass: 'lang-shuffle', | |
simulatorClass: 'lang-sim', | |
linksClass: 'lang-cards', | |
namespacesClass: 'lang-namespaces', | |
codeCardClass: 'lang-codecard', | |
packageClass: 'lang-package', | |
projectClass: 'lang-project', | |
snippetReplaceParent: true, | |
simulator: true, | |
hex: true, | |
hexName: path, | |
downloadScreenshots: downloadScreenshots | |
}).done(); | |
}); | |
} | |
$(document).ready(function () { | |
renderSnippets(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Improved Version by @pelikhan could be found here: https://jsfiddle.net/ndyz1d57/1/
See also: microsoft/pxt-microbit#623