feat: add support for running html canvas

This commit is contained in:
Hatem Hosny committed 2025-01-05 18:01:48 +02:00
1 parent 4c68afe0f9
commit d407354e16
2 files changed
+26 -7

No files matched your search

+2 -6
View File
@@ -10,6 +10,7 @@ intro: |
This HTML Canvas quick reference cheat sheet lists the common HTML5 Canvas design tags in readable layout.
plugins:
- copyCode
- runCode
---
## Getting Started
@@ -23,12 +24,7 @@ plugins:
<title>Canvas Example</title>
</head>
<body>
<canvas
id="myCanvas"
width="500"
height="400"
style="border:1px solid #000000;"
></canvas>
<canvas id="myCanvas" width="500" height="400" style="border:1px solid #000000;"></canvas>
<script src="script.js"></script>
</body>
</html>
+24 -1
View File
@@ -102,8 +102,11 @@
if (language === 'ts') {
language = 'typescript';
}
if (language === 'js') {
language = 'javascript';
}
const editorId = ['js', 'javascript', 'typescript', 'python', 'php', 'ruby', 'perl'].includes(language)
const editorId = ['javascript', 'typescript', 'python', 'php', 'ruby', 'perl'].includes(language)
? 'script'
: ['css', 'scss'].includes(language)
? 'style'
@@ -208,6 +211,26 @@
}
}
if (language === 'javascript' && pageHeader.startsWith('HTML Canvas')) {
if (!content.includes('const ctx =')) {
content = `const canvas = document.getElementById("myCanvas");\nconst ctx = canvas.getContext("2d");\n\n${content}`;
}
config = {
...baseConfig,
markup: {
language: 'html',
content: "<canvas id=\"myCanvas\" width=\"500\" height=\"400\" style=\"border:1px solid #000000;\"></canvas>\n",
},
script: {
language,
content,
},
tools: {
status: 'closed',
},
}
}
if (language === 'javascript' && pageHeader.startsWith('React')) {
config = {
...baseConfig,