Add tag to top-right of all code blocks to specify what language something is

[ci skip]
This commit is contained in:
Jose Diaz-Gonzalez committed 2016-07-03 17:20:46 -04:00
1 parent a9617f23ce
commit a4b2447c85
2 files changed
+93 -1

No files matched your search

+28
View File
@@ -282,6 +282,34 @@ a.list-group-item {
.markdown-body h1 + h2 { .markdown-body h1 + h2 {
margin-top: 1em; margin-top: 1em;
} }
.highlight-show-language {
position: relative;
}
.highlight-show-language-label {
color: black;
background-color: #CFCFCF;
display: inline-block;
position: absolute;
bottom: auto;
left: auto;
top: 0;
right: 0;
width: auto;
height: auto;
font-size: 0.9em;
border-radius: 0 0 0 5px;
padding: 0 0.5em;
text-shadow: none;
z-index: 1;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
-webkit-transform: none;
-moz-transform: none;
-ms-transform: none;
-o-transform: none;
transform: none;
}
code { code {
padding: 0; padding: 0;
padding-top: 0.2em; padding-top: 0.2em;
+65 -1
View File
@@ -47,6 +47,34 @@
<!-- <link href="/dokku/docs/assets/style.css" rel="stylesheet"> --> <!-- <link href="/dokku/docs/assets/style.css" rel="stylesheet"> -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet">
<style> <style>
.highlight-show-language {
position: relative;
}
.highlight-show-language-label {
color: black;
background-color: #CFCFCF;
display: inline-block;
position: absolute;
bottom: auto;
left: auto;
top: 0;
right: 0;
width: auto;
height: auto;
font-size: 0.9em;
border-radius: 0 0 0 5px;
padding: 0 0.5em;
text-shadow: none;
z-index: 1;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
-webkit-transform: none;
-moz-transform: none;
-ms-transform: none;
-o-transform: none;
transform: none;
}
</style> </style>
</head> </head>
<body> <body>
@@ -223,6 +251,25 @@
} else { } else {
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');; el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');;
} }
},
languageClass = function (el) {
if (!hasClass(el, 'highlight')) {
return;
}
var classes = [];
if (el.classList) {
classes = el.classList.value.split(/\s+/);
} else {
classes = el.className.split(/\s+/);
}
var language = null;
for (i = 0; i < classes.length; i++) {
if (classes[i].lastIndexOf('highlight-source-', 0) === 0) {
language = classes[i].replace('highlight-source-', '');
break;
}
}
return language;
}; };
var ls2 = { var ls2 = {
@@ -279,7 +326,6 @@
}); });
} }
Array.prototype.forEach.call(blockquotes, function (el, i) { Array.prototype.forEach.call(blockquotes, function (el, i) {
if (el.innerHTML.toLowerCase().indexOf('new as of') !== -1) { if (el.innerHTML.toLowerCase().indexOf('new as of') !== -1) {
addClass(el, 'new-as-of'); addClass(el, 'new-as-of');
@@ -293,6 +339,24 @@
}); });
}); });
var highlightElements = document.querySelectorAll('pre');
Array.prototype.forEach.call(highlightElements, function(el, i) {
var language = languageClass(el.parentElement);
if (typeof (language) === "undefined") {
return;
}
console.log("=="+language+"===");
var wrapper = document.createElement('div'),
label = document.createElement('div');
wrapper.setAttribute('class', 'highlight-show-language');
label.setAttribute('class', 'highlight-show-language-label');
label.appendChild(document.createTextNode(language));
wrapper.appendChild(label);
el.parentElement.insertBefore(wrapper, el);
});
addListener(currentVersionEl, 'click', function() { addListener(currentVersionEl, 'click', function() {
if (hasClass(versionContainer, 'shift-up')) { if (hasClass(versionContainer, 'shift-up')) {
removeClass(versionContainer, 'shift-up'); removeClass(versionContainer, 'shift-up');