Skip to content

Commit 70fe55b

Browse files
stefanbauerBlair Vanderhoof
authored and
Blair Vanderhoof
committed
add the functionality to add a custom caption (#65)
1 parent 8f7301e commit 70fe55b

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ See http://blairvanderhoof.com/gist-embed/ for all possible ways to use gist-emb
2727
* Including individual files from a gist
2828
* Including specific line numbers from a gist
2929
* Including specific line numbers from a gist and collapse the others
30+
* Add a caption (filename for example) to a gist
3031
* Removing all line numbers from a gist
3132
* Removing the footer from a gist
3233
* Highlight lines from a gist

gist-embed.js

+15
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
id,
3838
url,
3939
file,
40+
caption,
4041
lines,
4142
linesExpanded,
4243
loading,
@@ -53,6 +54,7 @@
5354

5455
id = $elem.data('gist-id') || '';
5556
file = $elem.data('gist-file');
57+
caption = $elem.data('gist-caption');
5658
hideFooterOption = $elem.data('gist-hide-footer') === true;
5759
hideLineNumbersOption = $elem.data('gist-hide-line-numbers') === true;
5860
lines = $elem.data('gist-line');
@@ -225,6 +227,19 @@
225227
}
226228
}
227229

230+
// option to show caption
231+
if (caption) {
232+
var tbody = $responseDiv.find('table tbody');
233+
var row = $('<tr></tr>');
234+
var captionColumn = $('<td></td>')
235+
.attr('style', 'padding: 10px !important; border-bottom: 10px solid white; background-color: #f9f9f9; font-weight: bold;')
236+
.html(caption);
237+
238+
row.append($('<td style="background-color: #f9f9f9; border-bottom: 10px solid white;"></td>'));
239+
row.append(captionColumn);
240+
tbody.prepend(row);
241+
}
242+
228243
// option to remove footer
229244
if (hideFooterOption) {
230245
$responseDiv.find('.gist-meta').remove();

gist-embed.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test.html

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@
6464
<p>Loading a gist with both footer and line numbers removed</p>
6565
<code data-gist-id="5457629" data-gist-hide-footer="true" data-gist-hide-line-numbers="true"></code>
6666

67+
<p>Loading a gist with caption</p>
68+
<code data-gist-id="5457619" data-gist-caption="this/is/a/sample/path/to/file.extension"></code>
69+
70+
<p>Loading a gist with caption with footer removed</p>
71+
<code data-gist-id="5457619" data-gist-hide-footer="true" data-gist-caption="this/is/a/sample/path/to/file.extension"></code>
72+
6773
<p>Loading a gist with multiple files</p>
6874
<code data-gist-id="5457635"></code>
6975

0 commit comments

Comments
 (0)