Files
ui/docs/app/workers/prettier.js
2024-09-24 14:43:19 +02:00

34 lines
906 B
JavaScript

/* eslint-disable no-undef */
import('https://unpkg.com/prettier@3.3.3/standalone.js')
import('https://unpkg.com/prettier@3.3.3/plugins/babel.js')
import('https://unpkg.com/prettier@3.3.3/plugins/estree.js')
import('https://unpkg.com/prettier@3.3.3/plugins/html.js')
import('https://unpkg.com/prettier@3.3.3/plugins/markdown.js')
import('https://unpkg.com/prettier@3.3.3/plugins/typescript.js')
self.onmessage = async function (event) {
self.postMessage({
uid: event.data.uid,
message: await handleMessage(event.data.message)
})
}
function handleMessage(message) {
switch (message.type) {
case 'format':
return handleFormatMessage(message)
}
}
async function handleFormatMessage(message) {
const { options, source } = message
const formatted = await prettier.format(source, {
parser: 'markdown',
plugins: prettierPlugins,
...options
})
return formatted
}