Skip to content

Languages

Codeshine supports 45+ programming languages with accurate syntax highlighting.

Supported Languages

Tier 1 - Core Languages

These languages have the most comprehensive grammar support:

LanguageAliases
JavaScriptjavascript, js
TypeScripttypescript, ts
JSXjsx
TSXtsx
HTMLhtml
CSScss
JSONjson
Markdownmarkdown, md
LanguageAliases
Pythonpython, py
Javajava
Cc
C++cpp, c++
C#csharp, cs
Gogo, golang
Rustrust, rs
Rubyruby, rb
PHPphp
Swiftswift
Kotlinkotlin, kt

Tier 3 - Modern Languages

LanguageAliases
Zigzig
Elixirelixir, ex
Scalascala
Haskellhaskell, hs
Clojureclojure, clj
F#fsharp, fs
OCamlocaml, ml
Erlangerlang, erl
Juliajulia, jl
Rr
Dartdart
Lualua
Perlperl, pl

Tier 4 - Config & Data

LanguageAliases
YAMLyaml, yml
TOMLtoml
XMLxml
GraphQLgraphql, gql
SQLsql
Dockerfiledockerfile, docker
Shellshell, bash, sh, zsh
PowerShellpowershell, ps1
Makefilemakefile, make
INIini

Tier 5 - Other Languages

LanguageAliases
WASMwasm, wat
Assemblyasm, assembly
LaTeXlatex, tex
Diffdiff, patch
Plain Texttext, plain, txt

Usage

Specify Language

typescript
import { Codeshine } from '@oxog/codeshine'; const codeshine = new Codeshine(); // Use language namecodeshine.highlight(code, { language: 'typescript' }); // Use aliascodeshine.highlight(code, { language: 'ts' });

Auto Detection

typescript
import { detectLanguage } from '@oxog/codeshine'; const code = `def hello():    print("Hello!")`; const language = detectLanguage(code);// Returns: 'python' // Or use 'auto' as languagecodeshine.highlight(code, { language: 'auto' });

Language Detection

Codeshine can automatically detect the language based on:

  1. Shebang lines - #!/usr/bin/env python
  2. Keywords - Language-specific keywords
  3. Syntax patterns - Unique syntax features
  4. File extensions - When filename is provided
typescript
// Detection with filename hintconst language = detectLanguage(code, { filename: 'app.tsx' });

Getting Language Info

typescript
import { getLanguage, listLanguages } from '@oxog/codeshine'; // Get language definitionconst tsLang = getLanguage('typescript');console.log(tsLang.name);    // 'TypeScript'console.log(tsLang.aliases); // ['ts'] // List all languagesconst languages = listLanguages();languages.forEach(lang => {  console.log(`${lang.name}: ${lang.aliases.join(', ')}`);});

Language Features

Each language grammar includes patterns for:

  • Keywords - Reserved words (if, for, function)
  • Strings - String literals with escape sequences
  • Numbers - Integer, float, hex, binary, octal
  • Comments - Single and multi-line comments
  • Operators - Arithmetic, logical, comparison
  • Functions - Function definitions and calls
  • Types - Type annotations and declarations
  • Classes - Class definitions and members
  • Variables - Variable declarations
  • Constants - Built-in constants
  • Regex - Regular expressions
  • Templates - Template literals and interpolation

Example: Multiple Languages

typescript
const codeshine = new Codeshine(); // JavaScriptconst jsHtml = codeshine.highlight(`const greet = (name) => \`Hello, \${name}!\`;`, { language: 'javascript' }); // Pythonconst pyHtml = codeshine.highlight(`def greet(name):    return f"Hello, {name}!"`, { language: 'python' }); // Rustconst rsHtml = codeshine.highlight(`fn greet(name: &str) -> String {    format!("Hello, {}!", name)}`, { language: 'rust' }); // Goconst goHtml = codeshine.highlight(`func greet(name string) string {    return fmt.Sprintf("Hello, %s!", name)}`, { language: 'go' });

Plain Text

For code without syntax highlighting:

typescript
codeshine.highlight(text, { language: 'text' });// orcodeshine.highlight(text, { language: 'plain' });

Language-Specific Features

JSX/TSX

Full support for React syntax:

tsx
function Button({ label }: Props) {  return (    <button className="btn" onClick={handleClick}>      {label}    </button>  );}

Markdown

Fenced code blocks, headers, lists:

markdown
# Heading - Item 1- Item 2 \`\`\`javascriptconst x = 1;\`\`\`

Shell

Commands, variables, pipes:

bash
#!/bin/bashNAME="World"echo "Hello, $NAME!" | grep -o "Hello"

SQL

Keywords, strings, comments:

sql
SELECT id, name, emailFROM usersWHERE active = TRUEORDER BY created_at DESCLIMIT 10;

Released under the MIT License.