mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 05:24:10 +03:00
feat: add support for running go
This commit is contained in:
1 parent
d407354e16
commit
fb1a5d9a3f
2 files changed
+48
-15
No files matched your search
@@ -10,6 +10,7 @@ intro: |
|
||||
This cheat sheet provided basic syntax and methods to help you using [Go](https://go.dev/).
|
||||
plugins:
|
||||
- copyCode
|
||||
- runCode
|
||||
---
|
||||
|
||||
## Getting Started
|
||||
|
||||
@@ -106,26 +106,13 @@
|
||||
language = 'javascript';
|
||||
}
|
||||
|
||||
const editorId = ['javascript', 'typescript', 'python', 'php', 'ruby', 'perl'].includes(language)
|
||||
const editorId = ['javascript', 'typescript', 'python', 'php', 'ruby', 'go', 'perl'].includes(language)
|
||||
? 'script'
|
||||
: ['css', 'scss'].includes(language)
|
||||
? 'style'
|
||||
: 'markup';
|
||||
const title = codeBlock.closest('.h3-wrap')?.querySelector('h3')?.textContent.replace('#', '') || '';
|
||||
|
||||
if (language === 'python') {
|
||||
if (content.includes('>>> ')) {
|
||||
content = content
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map(line => line.startsWith('>>> ') ? line.replace('>>> ', '') : `# ${line}`)
|
||||
.join('\n');
|
||||
}
|
||||
if (content.includes('from typing import')) {
|
||||
language = 'python-wasm';
|
||||
}
|
||||
}
|
||||
|
||||
const baseConfig = {
|
||||
title,
|
||||
activeEditor: editorId,
|
||||
@@ -246,7 +233,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (['php'].includes(language)) {
|
||||
if (language === 'php') {
|
||||
config = {
|
||||
...baseConfig,
|
||||
style: {
|
||||
@@ -263,6 +250,51 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (language === 'python') {
|
||||
if (content.includes('>>> ')) {
|
||||
content = content
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map(line => line.startsWith('>>> ') ? line.replace('>>> ', '') : `# ${line}`)
|
||||
.join('\n');
|
||||
}
|
||||
if (content.includes('from typing import')) {
|
||||
language = 'python-wasm';
|
||||
}
|
||||
config = {
|
||||
...baseConfig,
|
||||
script: {
|
||||
language,
|
||||
content,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if (language === 'go') {
|
||||
if (!content.includes('func main() {') && !content.includes('import')) {
|
||||
if (content.includes('func ')) {
|
||||
const freeCode = content.split('\n').filter(line => !line.startsWith('func ') && !line.startsWith(' ') && !line.startsWith('}')).join('\n');
|
||||
content = `${content.replace(freeCode, '')}\nfunc main() {\n${freeCode.trim().split('\n').map(line => ` ${line}`).join('\n')}\n}`;
|
||||
} else {
|
||||
content = `func main() {\n${content.trim().split('\n').map(line => ` ${line}`).join('\n')}\n}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (content.includes('fmt.') && !content.includes('import')) {
|
||||
content = `import "fmt"\n\n${content}`
|
||||
}
|
||||
if (!content.includes('package main')) {
|
||||
content = `package main\n\n${content}`
|
||||
}
|
||||
config = {
|
||||
...baseConfig,
|
||||
script: {
|
||||
language,
|
||||
content,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const plaugroundUrl = livecodes.getPlaygroundUrl({config});
|
||||
window.open(plaugroundUrl, '_blank');
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user