web/assets/js/_utils/lang-badge.js
2021-01-25 06:43:02 +08:00

20 lines
435 B
JavaScript

/**
* Add language indicator to code snippets
*/
$(function() {
const prefix = "language-";
const regex = new RegExp(`^${prefix}([a-z])+$`);
$(`div[class^=${prefix}`).each(function() {
let classes = $(this).attr("class").split(" ");
classes.forEach((_class) => {
if (regex.test(_class)) {
let lang = _class.substring(prefix.length);
$(this).attr("lang", `${lang}`);
}
});
});
});