LumisDocs
Recipes

Auto-detect language

Let Lumis infer the language from content, filename, or shebang.

const html = await highlight(
  '#!/usr/bin/env bash\necho "hello"',
  htmlInline({theme: frappe}),
)

Resolving the id without highlighting

Highlighting detects the language for you. To ask what a snippet is before deciding what to do with it, call the detector directly. It returns the same id highlighting would have used, falling back to plaintext.

import * as languages from '@lumis-sh/lumis/languages';

languages.guess('lib/app.ex')                      // "elixir"
languages.guess(undefined, '#!/usr/bin/env bash')  // "bash"

On this page