| name | livecodes/import-export |
| description | Import code from GitHub gists/files/repos, GitLab, URLs, DOM, and local files. Export projects as HTML, JSON, ZIP, or to external services. Load this skill when loading projects from external sources or exporting project state.
|
| type | core |
| library | livecodes |
| library_version | 0.13.0 |
| sources | ["live-codes/livecodes:docs/docs/features/import.mdx","live-codes/livecodes:docs/docs/features/export.mdx"] |
LiveCodes — Import and Export Code
LiveCodes imports code from external sources and exports projects in multiple formats.
Setup
import { createPlayground, getPlaygroundUrl } from 'livecodes';
const playground = await createPlayground('#container', {
import: 'https://github.com/user/repo/blob/main/src/index.js',
});
const shareUrl = await playground.getShareUrl();
const shortUrl = await playground.getShareUrl(true);
Core Patterns
Import from GitHub
createPlayground('#container', {
import: 'https://github.com/lodash/lodash/blob/master/isObject.js',
});
createPlayground('#container', {
import: 'https://github.com/user/repo/tree/main/src',
});
createPlayground('#container', {
import: 'https://gist.github.com/abc123',
});
createPlayground('#container', {
import: 'https://github.com/user/repo/tree/main/src',
params: { files: 'App.tsx,styles.css,index.html' },
});
Import from GitLab
createPlayground('#container', {
import: 'https://gitlab.com/-/snippets/12345',
});
createPlayground('#container', {
import: 'https://gitlab.com/user/repo/-/blob/main/src/index.js',
});
Import from URL
createPlayground('#container', {
import: 'https://example.com/code.js',
});
createPlayground('#container', {
params: {
x: 'https://example.com/code',
lang: 'typescript',
},
});
createPlayground('#container', {
import: 'https://play.vuejs.org/#...',
});
Import from shared project
createPlayground('#container', {
import: 'id/abc123',
});
createPlayground('#container', {
import: 'code/...',
});
Import from DOM
createPlayground('#container', {
import: 'https://example.com/blog-post',
});
Import via SDK config
await playground.setConfig({
markup: { language: 'html', content: '<h1>Hello</h1>' },
style: { language: 'css', content: 'h1 { color: blue; }' },
script: { language: 'javascript', content: 'console.log("hi")' },
});
await playground.setConfig('https://example.com/config.json');
Specify files from multi-file sources
createPlayground('#container', {
import: 'https://github.com/user/repo/tree/main/src',
params: {
files: 'Counter.tsx,counter.css,index.html',
active: 'script',
},
});
Export via SDK
const playground = await createPlayground('#container', {
});
const longUrl = await playground.getShareUrl();
const shortUrl = await playground.getShareUrl(true);
const config = await playground.getConfig();
Export via URL
# Long URL (compressed config)
https://livecodes.io/#config/...
# Short URL
https://livecodes.io/?x=id/abc123
Common Import Sources
| Source | URL Pattern | Notes |
|---|
| GitHub file | github.com/user/repo/blob/... | Single file |
| GitHub directory | github.com/user/repo/tree/... | Multiple files |
| GitHub gist | gist.github.com/... | Multi-file gists work |
| GitLab file | gitlab.com/user/repo/-/blob/... | Single file |
| GitLab snippet | gitlab.com/-/snippets/... | Snippet |
| JS Bin | jsbin.com/... | JS Bin embeds |
| Vue Playground | play.vuejs.org/#... | Vue SFC playground |
| TypeScript Playground | typescriptlang.org/play#... | TS playground |
| Raw URL | Any URL | Language auto-detected |
| Local files | Drag & drop | Standalone app only |
File Selection Priority
When importing multiple files, LiveCodes prioritizes:
- Files named
index.*, default.* (markup)
- Files named
style.*, styles.* (style)
- Files named
script.*, app.*, main.*, index.* (script)
- README and markdown files get lower priority
- Use
files parameter to explicitly select files
SDK Import Methods
createPlayground('#container', {
import: 'https://github.com/user/repo',
});
createPlayground('#container', {
params: { x: 'https://github.com/user/repo' },
});
await playground.setConfig('https://example.com/config.json');