markup-languages
v1.0.0
Published
File extensions for markup languages.
Maintainers
Readme
💻 markup-languages
File extensions for markup languages.
It's just a JSON file, so you can use it in any environment. Sourced from GitHub's Linguist project (defines all 700+ languages known to GitHub). Data is updated via script and released via new package version.
⚡ Installation
From your project root:
npm install markup-languages🔌 Usage
ES Modules (ESM):
import markupLangs from 'markup-languages'
htmlLangData = markupLangs.HTML
console.log(htmlLangData.extensions) // => [ '.hta', '.htm', '.html', '.html.hl', ... ]CommonJS (CJS):
const markupLangs = require('markup-languages')
htmlLangData = markupLangs.HTML
console.log(htmlLangData.extensions) // => [ '.hta', '.htm', '.html', '.html.hl', ... ]💻 Examples
Get language(s) from an extension:
function getLang(fileExt) {
const langMatches = Object.entries(markupLangs)
.filter(([_, data]) => data.extensions.includes(fileExt))
.map(([lang]) => lang)
return langMatches.length == 1 ? langMatches[0] : langMatches
}
console.log(getLang('.sss')) // => SugarSSGet language(s) from a file path:
function getLangFromPath(filepath) {
const fileExt = filepath.slice(filepath.lastIndexOf('.'))
const langMatches = Object.entries(markupLangs)
.filter(([_, data]) => data.extensions.includes(fileExt))
.map(([lang]) => lang)
return langMatches.length == 1 ? langMatches[0] : langMatches
}
console.log(getLangFromPath('index.html')) // => [ 'Ecmarkup', 'HTML' ]
console.log(getLangFromPath('style.css')) // => CSS
console.log(getLangFromPath('script.js')) // => [] (use programming-languages pkg)MIT License
Copyright © 2026 Adam Lui
📜 Related
More JavaScript utilities / Discuss / Report bug / Report vulnerability / Back to top ↑
