Add version history, screenshots, embed generator, collections, npm search, format-on-save, and custom fonts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { loadScript } from './utils.js';
|
||||
import { getActiveEditor, getActiveTab, getCurrentMode, getCssType } from './editors.js';
|
||||
import { getActiveEditor, getActiveTab, getCurrentMode, getCssType, switchTab, getEditorValues } from './editors.js';
|
||||
|
||||
const PRETTIER_CDN = 'https://cdn.jsdelivr.net/npm/prettier@3';
|
||||
const PLUGINS = [
|
||||
@@ -79,3 +79,31 @@ export async function formatActiveEditor() {
|
||||
console.warn('Prettier format error:', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
export async function formatAll() {
|
||||
await ensurePrettier();
|
||||
const mode = getCurrentMode();
|
||||
const cssType = getCssType();
|
||||
const tabIds = ['html', 'css', 'js'];
|
||||
|
||||
for (const tabId of tabIds) {
|
||||
const config = getParser(tabId, mode, cssType);
|
||||
if (!config) continue;
|
||||
// Temporarily switch to this tab to get its editor
|
||||
switchTab(tabId);
|
||||
const editor = getActiveEditor();
|
||||
if (!editor) continue;
|
||||
const code = editor.getValue();
|
||||
if (!code.trim()) continue;
|
||||
try {
|
||||
const formatted = await prettier.format(code, {
|
||||
parser: config.parser,
|
||||
plugins: config.plugins,
|
||||
singleQuote: true,
|
||||
trailingComma: 'all',
|
||||
printWidth: 100,
|
||||
});
|
||||
editor.setValue(formatted);
|
||||
} catch (_) { /* skip tabs that fail */ }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user