feat: add support for running typescript

This commit is contained in:
Hatem Hosny committed 2025-01-05 02:24:11 +02:00
1 parent a35a51cc05
commit 8cddefb52f
2 files changed
+13 -9

No files matched your search

+2 -5
View File
@@ -11,6 +11,7 @@ intro: |
A TypeScript cheat sheet with the most important concepts, functions, methods, and more. A complete quick reference for beginners.
plugins:
- copyCode
- runCode
---
## Getting Started
@@ -293,11 +294,7 @@ class Greeter {
```ts
function enumerable(value: boolean) {
return function (
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
descriptor.enumerable = value;
};
}
+11 -4
View File
@@ -81,6 +81,11 @@
const code_Blocks = document.querySelectorAll('pre > code');
const runInnerHTML = '<svg height="1em" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g stroke-width="0"></g><g stroke-linecap="round" stroke-linejoin="round"></g><g><path d="M16.6582 9.28638C18.098 10.1862 18.8178 10.6361 19.0647 11.2122C19.2803 11.7152 19.2803 12.2847 19.0647 12.7878C18.8178 13.3638 18.098 13.8137 16.6582 14.7136L9.896 18.94C8.29805 19.9387 7.49907 20.4381 6.83973 20.385C6.26501 20.3388 5.73818 20.0469 5.3944 19.584C5 19.053 5 18.1108 5 16.2264V7.77357C5 5.88919 5 4.94701 5.3944 4.41598C5.73818 3.9531 6.26501 3.66111 6.83973 3.6149C7.49907 3.5619 8.29805 4.06126 9.896 5.05998L16.6582 9.28638Z" stroke="currentColor" stroke-width="2" stroke-linejoin="round"></path></g></svg>';
code_Blocks.forEach(function (codeBlock) {
let content = codeBlock.textContent;
let language = [...codeBlock.classList].filter(c => c.startsWith("language-"))[0].replace("language-", "");
if (language === 'shell') return;
// Create a run button element
const runButton = document.createElement('button');
runButton.className = 'bg-emerald-500 p-2 text-white fadeIn shadow-xl rounded flex items-center absolute top-12 right-2';
@@ -93,9 +98,11 @@
// Add click event listener to run button
runButton.addEventListener('click', () => {
let content = codeBlock.textContent;
let language = [...codeBlock.classList].filter(c => c.startsWith("language-"))[0].replace("language-", "");
const editorId = ['javascript', 'python'].includes(language)
if (language === 'ts') {
language = 'typescript';
}
const editorId = ['javascript', 'typescript', 'python'].includes(language)
? 'script'
: ['scss'].includes(language)
? 'style'
@@ -145,7 +152,7 @@
}
}
if (language === 'scss') {
if (['scss', 'typescript'].includes(language)) {
config = {
...baseConfig,
tools: {