2021-01-08 04:59:28 +01:00
|
|
|
<link rel="stylesheet"
|
|
|
|
href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/default.min.css">
|
|
|
|
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js"></script>
|
|
|
|
<!-- and it's easy to individually load additional languages -->
|
|
|
|
<script charset="UTF-8"
|
|
|
|
src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/languages/go.min.js"></script>
|
|
|
|
|
|
|
|
{%- assign name = 'code_badge.enabled' -%}
|
2021-01-08 05:12:57 +01:00
|
|
|
{%- include functions.html func='get_value' default='true' -%}
|
2021-01-08 04:59:28 +01:00
|
|
|
{%- assign badge_enabled = return -%}
|
|
|
|
|
|
|
|
{%- assign name = 'code_badge.color' -%}
|
|
|
|
{%- include functions.html func='get_value' default='#fff' -%}
|
|
|
|
{%- assign badge_color = return -%}
|
|
|
|
|
|
|
|
{%- assign name = 'code_badge.background_color' -%}
|
|
|
|
{%- include functions.html func='get_value' default='#ff4e00' -%}
|
|
|
|
{%- assign badge_background_color = return -%}
|
|
|
|
|
|
|
|
{%- assign name = 'code_badge.text_transform' -%}
|
|
|
|
{%- include functions.html func='get_value' default='uppercase' -%}
|
|
|
|
{%- assign badge_text_transform = return -%}
|
|
|
|
|
2021-01-08 05:12:57 +01:00
|
|
|
{{ badge_enabled }}
|
|
|
|
{{ badge_color }}
|
|
|
|
{{ badge_background_color }}
|
|
|
|
{{ badge_text_transform }}
|
|
|
|
|
2021-01-08 04:59:28 +01:00
|
|
|
<script>
|
|
|
|
// Init highlight js
|
|
|
|
document.addEventListener('DOMContentLoaded', function(event) {
|
|
|
|
var els = document.querySelectorAll('pre code')
|
|
|
|
|
|
|
|
function addLangData(block) {
|
|
|
|
var outer = block.parentElement.parentElement.parentElement;
|
|
|
|
var lang = block.getAttribute('data-lang');
|
|
|
|
for (var i = 0; i < outer.classList.length; i++) {
|
|
|
|
var cls = outer.classList[i];
|
|
|
|
if (cls.startsWith('language-')) {
|
|
|
|
lang = cls;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!lang) {
|
|
|
|
cls = block.getAttribute('class');
|
|
|
|
lang = cls ? cls.replace('hljs ', '') : '';
|
|
|
|
}
|
|
|
|
if (lang.startsWith('language-')) {
|
|
|
|
lang = lang.substr(9);
|
|
|
|
}
|
|
|
|
block.setAttribute('class', 'hljs ' + lang);
|
|
|
|
block.parentNode.setAttribute('data-lang', lang);
|
|
|
|
}
|
|
|
|
|
2021-01-08 05:12:57 +01:00
|
|
|
function addBadge(block) {
|
|
|
|
var enabled = ('{{ badge_enabled }}' || 'true').toLowerCase();
|
|
|
|
if (enabled == 'true') {
|
|
|
|
var pre = block.parentElement;
|
|
|
|
pre.classList.add('badge');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-08 04:59:28 +01:00
|
|
|
function handle(block) {
|
|
|
|
addLangData(block);
|
2021-01-08 05:12:57 +01:00
|
|
|
addBadge(block)
|
2021-01-08 04:59:28 +01:00
|
|
|
hljs.highlightBlock(block);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < els.length; i++) {
|
|
|
|
var el = els[i];
|
|
|
|
handle(el);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
/* code language badge */
|
2021-01-08 05:12:57 +01:00
|
|
|
pre.badge::before {
|
2021-01-08 04:59:28 +01:00
|
|
|
content: attr(data-lang);
|
2021-01-08 05:12:57 +01:00
|
|
|
color: {{badge_color}};
|
|
|
|
background-color: {{badge_background_color}};
|
2021-01-08 04:59:28 +01:00
|
|
|
padding: 0 .5em;
|
|
|
|
border-radius: 0 2px;
|
2021-01-08 05:12:57 +01:00
|
|
|
text-transform: {{badge_text_transform}};
|
2021-01-08 04:59:28 +01:00
|
|
|
text-align: center;
|
|
|
|
min-width: 32px;
|
|
|
|
display: inline-block;
|
|
|
|
position: absolute;
|
|
|
|
right: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fix wrong badge display for firefox browser */
|
|
|
|
code > table pre::before {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
</style>
|