Skip to content

Commit 858b963

Browse files
committed
(docs) add live demo for Embeding REPL
1 parent f00aa0e commit 858b963

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

docs/docs/lips/embeding-repl.md renamed to docs/docs/lips/embedding-repl.mdx

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ sidebar_position: 9
33
description: "Embedding the LIPS Scheme REPL"
44
---
55

6+
import CodePen from '@site/src/CodePen';
7+
68
# Embedding LIPS REPL
79

810
To embed the LIPS REPL you need on your website you need:
@@ -132,4 +134,4 @@ term.echo(intro.replace(/(\((?:env|dir|help|apropos)[^)]*\))/g, function(code) {
132134

133135
## Working Demo
134136

135-
Here is a working [Codepen REPL Demo](https://codepen.io/jcubic/pen/OJepZbd).
137+
<CodePen id="OJepZbd" height={400} title="LIPS REPL Demo" />

docs/src/CodePen.tsx

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { useEffect } from 'react';
2+
3+
type CodePenProps = {
4+
id: string;
5+
title: string;
6+
height: number;
7+
};
8+
9+
export default function CodePen({ id, title, height = 300 }: CodePenProps) {
10+
useEffect(() => {
11+
globalThis.__codepen_loaded__ ??= 0;
12+
globalThis.__codepen_loaded__ += 1;
13+
const count = globalThis.__codepen_loaded__;
14+
if (count === 1) {
15+
const script = document.createElement('script');
16+
script.className = 'codepen';
17+
script.dataset.id = count;
18+
script.src = 'https://cpwebassets.codepen.io/assets/embed/ei.js';
19+
script.async = true;
20+
document.body.appendChild(script);
21+
}
22+
return () => {
23+
globalThis.__codepen_loaded__ -= 1;
24+
const script = document.querySelector(`script.codepen[data-id="${count}"]`);
25+
script?.remove();
26+
};
27+
}, []);
28+
return (
29+
<p className="codepen"
30+
data-height={height}
31+
data-default-tab="result"
32+
data-slug-hash={id}
33+
data-pen-title={title}
34+
data-user="jcubic"
35+
style={{
36+
height: 300,
37+
boxSizing: 'border-box',
38+
display: 'flex',
39+
alignItems: 'center',
40+
justifyContent: 'center',
41+
border: '2px solid',
42+
margin: '1em 0',
43+
padding: '1em'
44+
}}>
45+
<span>See the Pen <a href={`https://codepen.io/jcubic/pen/${id}`}>
46+
{title}</a> by Jakub T. Jankiewicz (<a href="https://codepen.io/jcubic">@jcubic</a>)
47+
{' '}on <a href="https://codepen.io">CodePen</a>.</span>
48+
</p>
49+
);
50+
}

0 commit comments

Comments
 (0)