Skip to content

Add file titles to code blocks #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lib/markup.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ function highlight (description) {
let element = $(el)
let klass = element.attr('class')
let lang = ''
let tableHeader = ''
if (klass) {
lang = determineLanguage(klass.split('-').pop())
let type = klass.split('-').pop()
if (isFile(type)) {
tableHeader = `
<thead>
<tr>
<td colspan="2">${type}</td>
</tr>
</thead>`
}
lang = determineLanguage(type)
}
let lines = element.html().split('\n')

Expand All @@ -71,7 +81,7 @@ function highlight (description) {
element.parent().after(`<div class="highlight ${lang}">
<div class="ribbon"></div>
<div class="scroller">
<table class="CodeRay">
<table class="CodeRay">${tableHeader}
<tbody>
<tr>
<td class="line-numbers"><pre>${lineNumbers}</pre></td>
Expand Down Expand Up @@ -102,3 +112,7 @@ function determineLanguage (lang) {
function removeHLJSPrefix (string) {
return string.replace(/hljs-/g, '')
}

function isFile (string) {
return /\./.test(string)
}
Loading