com um clique
livecodes-headless-mode
// Run playground without visible UI using SDK methods directly. Load this skill when building Markdown compilers, code formatters, or tools that need compiled output without display.
// Run playground without visible UI using SDK methods directly. Load this skill when building Markdown compilers, code formatters, or tools that need compiled output without display.
Use SDK with React, Vue, Svelte, Solid, Preact, and Web Components. sdkReady callback pattern, reactive props, and framework-specific setup. Load this skill when embedding LiveCodes in a framework application.
Create and configure embedded playgrounds using createPlayground(), EmbedOptions, container setup, loading modes (eager/lazy/click), and appUrl for self-hosted instances. Load this skill when embedding LiveCodes in web pages, configuring playground containers, or setting up SDK integration.
Open-source, client-side code playground supporting 90+ languages/frameworks. Runs entirely in the browser with SDK for embedding. Entry point for all LiveCodes skills.
Configure playground behavior through Config object, query parameters, EmbedOptions, editor settings, processors, external resources, and custom settings. Load this skill when setting up project content, configuring CSS processors, or customizing display.
Configure how the playground is displayed: full, focus, simple, lite, editor, codeblock, and result modes. Load this skill when choosing display mode for embeddings, configuring read-only views, or showing only result or editor.
Quick start for standalone app at livecodes.io, embedding playgrounds with CDN or npm, and self-hosting basics. Load this skill for initial setup and basic usage patterns.
| name | livecodes/headless-mode |
| description | Run playground without visible UI using SDK methods directly. Load this skill when building Markdown compilers, code formatters, or tools that need compiled output without display. |
| type | core |
| library | livecodes |
| library_version | 0.13.0 |
| requires | ["sdk-embedding","sdk-methods"] |
| sources | ["live-codes/livecodes:docs/docs/sdk/headless.mdx"] |
This skill builds on sdk-embedding and sdk-methods. Read them first for foundational concepts.
Headless mode runs LiveCodes without any visible UI. Use SDK methods to compile code, get output, and react to events.
import { createPlayground } from 'livecodes';
// Create headless playground - container is optional
const playground = await createPlayground({
headless: true,
config: {
markup: { language: 'markdown', content: '# Hello World' },
},
});
// Use SDK methods
const code = await playground.getCode();
console.log(code.markup.compiled); // "<h1>Hello World</h1>"
console.log(code.result); // Result page HTML
import { createPlayground } from 'livecodes';
let playground;
async function compileMarkdown(markdown) {
if (!playground) {
playground = await createPlayground({
headless: true,
config: { autoupdate: false },
});
}
await playground.setConfig({
markup: { language: 'markdown', content: markdown },
});
const code = await playground.getCode();
return code.markup.compiled;
}
// Usage
const html = await compileMarkdown('# Hello\n\nWorld');
console.log(html); // "<h1>Hello</h1>\n<p>World</p>"
import { createPlayground } from 'livecodes';
let playground;
async function compileJSX(jsxCode) {
if (!playground) {
playground = await createPlayground({
headless: true,
config: { autoupdate: false },
});
}
await playground.setConfig({
script: { language: 'react', content: jsxCode },
});
const code = await playground.getCode();
return code.script.compiled;
}
const compiled = await compileJSX(`
function App() {
return <h1>Hello</h1>;
}
`);
import { createPlayground } from 'livecodes';
let playground;
async function runPython(code) {
if (!playground) {
playground = await createPlayground({
headless: true,
config: { autoupdate: true },
});
}
// Set up console listener before running
const outputs = [];
playground.watch('console', ({ method, args }) => {
outputs.push({ method, args });
});
await playground.setConfig({
script: { language: 'python', content: code },
});
// Python runs automatically with autoupdate: true
// Or: await playground.run();
return outputs;
}
// Usage
const outputs = await runPython('print("Hello from Python!")');
// [{ method: 'log', args: ['Hello from Python!'] }]
async function getResultHTML(config) {
const playground = await createPlayground({
headless: true,
config: { ...config, autoupdate: false },
});
await playground.setConfig(config);
const code = await playground.getCode();
return code.result; // Result page HTML
}
const playground = await createPlayground({
headless: true,
config: { autoupdate: false },
});
// Watch for compiled code changes
playground.watch('code', ({ code, config }) => {
console.log('Compiled:', code.script.compiled);
});
// Change config - watch callback fires
await playground.setConfig({
script: { language: 'typescript', content: 'const x: number = 1;' },
});
| Aspect | Visible | Headless |
|---|---|---|
| Container | Required | Optional |
| UI | Shown | Hidden |
| Use case | User interaction | Programmatic compilation |