Function
create
({
input,
language,
}: {
input: string;
language: string;
})
Source from the content-addressed store, hash-verified
| 5 | const LANGUAGES = highlightjs.listLanguages(); |
| 6 | |
| 7 | export async function create({ |
| 8 | input, |
| 9 | language, |
| 10 | }: { |
| 11 | input: string; |
| 12 | language: string; |
| 13 | }) { |
| 14 | try { |
| 15 | const output = |
| 16 | language && LANGUAGES.includes(language) |
| 17 | ? highlightjs.highlight(language, input).value |
| 18 | : highlightjs.highlightAuto(input).value; |
| 19 | return { |
| 20 | status: 200, |
| 21 | data: { |
| 22 | output, |
| 23 | }, |
| 24 | }; |
| 25 | } catch (exception) { |
| 26 | return { |
| 27 | status: 200, |
| 28 | data: { |
| 29 | output: input, |
| 30 | }, |
| 31 | }; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | export default async function handler( |
| 36 | request: NextApiRequest, |
Tested by
no test coverage detected