Skip to content

Commit 1a20c35

Browse files
Add file titles to code blocks
1 parent 59b41a2 commit 1a20c35

File tree

2 files changed

+92
-79
lines changed

2 files changed

+92
-79
lines changed

lib/markup.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,18 @@ function highlight (description) {
5555
let element = $(el)
5656
let klass = element.attr('class')
5757
let lang = ''
58+
let tableHeader = ''
5859
if (klass) {
59-
lang = determineLanguage(klass.split('-').pop())
60+
let type = klass.split('-').pop()
61+
if (isFile(type)) {
62+
tableHeader = `
63+
<thead>
64+
<tr>
65+
<td colspan="2">${type}</td>
66+
</tr>
67+
</thead>`
68+
}
69+
lang = determineLanguage(type)
6070
}
6171
let lines = element.html().split('\n')
6272

@@ -71,7 +81,7 @@ function highlight (description) {
7181
element.parent().after(`<div class="highlight ${lang}">
7282
<div class="ribbon"></div>
7383
<div class="scroller">
74-
<table class="CodeRay">
84+
<table class="CodeRay">${tableHeader}
7585
<tbody>
7686
<tr>
7787
<td class="line-numbers"><pre>${lineNumbers}</pre></td>
@@ -102,3 +112,7 @@ function determineLanguage (lang) {
102112
function removeHLJSPrefix (string) {
103113
return string.replace(/hljs-/g, '')
104114
}
115+
116+
function isFile (string) {
117+
return /\./.test(string)
118+
}

0 commit comments

Comments
 (0)