mirror of
https://github.com/cotes2020/jekyll-theme-chirpy.git
synced 2025-12-18 13:44:15 +00:00
Feature: display the language of code snippets
This commit is contained in:
20
assets/js/_utils/lang-badge.js
Normal file
20
assets/js/_utils/lang-badge.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Add language indicator to code snippets
|
||||
*/
|
||||
|
||||
$(function() {
|
||||
const prefix = "language-";
|
||||
const regex = new RegExp(`^${prefix}([a-z])+$`);
|
||||
|
||||
$(`div[class^=${prefix}`).each(function() {
|
||||
let clzsses = $(this).attr("class").split(" ");
|
||||
|
||||
clzsses.forEach((clzss) => {
|
||||
if (regex.test(clzss)) {
|
||||
let lang = clzss.substring(prefix.length);
|
||||
$(this).attr("lang", `${lang}`);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
2
assets/js/post.min.js
vendored
2
assets/js/post.min.js
vendored
@@ -15,3 +15,5 @@ layout: compress
|
||||
{% include_relative _utils/toc-filter.js %}
|
||||
|
||||
{% include_relative _utils/img-hyperlink.js %}
|
||||
|
||||
{% include_relative _utils/lang-badge.js %}
|
||||
|
||||
Reference in New Issue
Block a user