Skip to content

Commit 03cbdd3

Browse files
committed
[Docs Site] Adopt code block design
1 parent c4bf6eb commit 03cbdd3

File tree

3 files changed

+74
-61
lines changed

3 files changed

+74
-61
lines changed

bin/playground.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

ec.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export default {
1717
],
1818
themes: [darkTheme, lightTheme],
1919
styleOverrides: {
20+
borderWidth: "1px",
21+
borderRadius: "0.25rem",
2022
textMarkers: {
2123
defaultLuminance: ["32%", "88%"],
2224
},

src/plugins/expressive-code/workers-playground.js

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
// @ts-check
12
import { definePlugin } from "@expressive-code/core";
23
import { h } from "@expressive-code/core/hast";
34

45
import lzstring from "lz-string";
56

6-
export function serialiseWorker(code) {
7+
/**
8+
* @param {string} code
9+
*/
10+
function serialiseWorker(code) {
711
const formData = new FormData();
812

913
const metadata = {
@@ -26,7 +30,10 @@ export function serialiseWorker(code) {
2630
return formData;
2731
}
2832

29-
export async function compressWorker(worker) {
33+
/**
34+
* @param {FormData} worker
35+
*/
36+
async function compressWorker(worker) {
3037
const serialisedWorker = new Response(worker);
3138
return lzstring.compressToEncodedURIComponent(
3239
`${serialisedWorker.headers.get(
@@ -39,23 +46,26 @@ export default () => {
3946
return definePlugin({
4047
name: "Adds 'Run Worker' button to JS codeblocks",
4148
baseStyles: `
42-
.run {
43-
display: flex;
44-
gap: 0.25rem;
45-
flex-direction: row;
46-
position: absolute;
47-
inset-block-start: calc(var(--ec-brdWd) + var(--button-spacing));
48-
inset-inline-end: calc(var(--ec-brdWd) + var(--ec-uiPadInl) * 3);
49-
direction: ltr;
50-
unicode-bidi: isolate;
49+
.wrapper {
50+
box-shadow: var(--ec-frm-frameBoxShdCssVal);
51+
margin-top: 0 !important;
52+
}
5153
52-
text-decoration-color: var(--sl-color-accent);
53-
span {
54-
color: var(--sl-color-white);
55-
font-family: var(--sl-font-system);
56-
}
57-
}
58-
`,
54+
.expressive-code:has(.playground-frame) .frame {
55+
box-shadow: unset;
56+
57+
& > pre {
58+
border-bottom-left-radius: 0;
59+
border-bottom-right-radius: 0;
60+
}
61+
}
62+
63+
.playground-frame {
64+
border: var(--ec-brdWd) solid var(--ec-brdCol);
65+
border-top: unset;
66+
border-bottom-left-radius: calc(var(--ec-brdRad) + var(--ec-brdWd));
67+
border-bottom-right-radius: calc(var(--ec-brdRad) + var(--ec-brdWd));
68+
}`,
5969
hooks: {
6070
postprocessRenderedBlock: async (context) => {
6171
if (!context.codeBlock.meta.includes("playground")) return;
@@ -64,16 +74,50 @@ export default () => {
6474
serialiseWorker(context.codeBlock.code),
6575
);
6676

67-
const url = `https://workers.cloudflare.com/playground#${serialised}`;
68-
69-
const runButton = h("a.run", { href: url, target: "__blank" }, [
70-
h("span", "Run Worker in Playground"),
71-
]);
72-
73-
const ast = context.renderData.blockAst;
74-
ast.children.push(runButton);
75-
76-
context.renderData.blockAst = ast;
77+
context.renderData.blockAst = {
78+
type: "element",
79+
tagName: "div",
80+
properties: {
81+
className: ["wrapper"],
82+
},
83+
children: [
84+
context.renderData.blockAst,
85+
{
86+
type: "element",
87+
tagName: "div",
88+
properties: {
89+
className: [
90+
"playground-frame",
91+
"!flex",
92+
"!p-4",
93+
"!justify-end",
94+
"!items-center",
95+
],
96+
},
97+
children: [
98+
{
99+
type: "element",
100+
tagName: "a",
101+
properties: {
102+
className: [
103+
"!bg-cl1-brand-orange",
104+
"!rounded",
105+
"!px-6",
106+
"!py-2",
107+
"!text-black",
108+
"!font-medium",
109+
"!no-underline",
110+
],
111+
href: `https://workers.cloudflare.com/playground#${serialised}`,
112+
},
113+
children: [
114+
{ type: "text", value: "Run Worker in Playground" },
115+
],
116+
},
117+
],
118+
},
119+
],
120+
};
77121
},
78122
},
79123
});

0 commit comments

Comments
 (0)