(This post is part of a series, all with the same title) (it does not use Emmy but the older sicmutils library)


1 + 2 + 3
    

Interlude: importing snippets from an HTML file into this post

We embed the source as an IFrame within this post, albeit sandboxed, i.e. code is not executed.

<iframe id="code_snippets" sandbox="allow-same-origin" src="/blog/html/code_snippet.html" width="600" height="150"></iframe>

Since the 4+5+6 snippet carries an id (id = "first") in that source, we can access and copy it over. For this we use a helper function.

<script>
var loadSnippet = (iframeNode, snippetNode) => {
 let msg = snippetNode + " not in IFrame " + iframeNode;
 let prn_msg = () => {alert(msg); return(msg);};
 let nde = document.getElementById(iframeNode)
                   .contentWindow.document
                   .getElementById(snippetNode);
 document.getElementById(snippetNode).innerHTML =
     nde != null ? nde.innerHTML : prn_msg();}
</script>

Now we can easily copy arbitrary snippets from the source into this post using addSnippet, the asynchronous sibling of loadSnippet.

<pre id="first"></pre>
<script>
 addSnippet('code_snippets','first');
</script>