Skip to content

Commit 2ea79c0

Browse files
committed
Combine highlight and html. Fixes #173
1 parent cea83ef commit 2ea79c0

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

lib/highlight.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

lib/output/html.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var File = require('vinyl'),
1010
getTemplate = require('../get_template'),
1111
resolveTheme = require('../resolve_theme'),
1212
helpers = require('../html_helpers'),
13-
highlight = require('../highlight');
13+
hljs = require('highlight.js');
1414

1515
/**
1616
* Make slugg a unary so we can use it in functions
@@ -23,6 +23,31 @@ function slug(input) {
2323
return input ? slugg(input) : '';
2424
}
2525

26+
/**
27+
* Given a string of JavaScript, return a string of HTML representing
28+
* that JavaScript highlighted.
29+
*
30+
* @param {string} example string of javascript
31+
* @returns {string} highlighted html
32+
*/
33+
function highlightString(example) {
34+
return hljs.highlight('js', example).value;
35+
}
36+
37+
/**
38+
* Highlights the contents of the `example` tag.
39+
*
40+
* @name highlight
41+
* @param {Object} comment parsed comment
42+
* @return {Object} comment with highlighted code
43+
*/
44+
function highlight(comment) {
45+
if (comment.examples) {
46+
comment.examples = comment.examples.map(highlightString);
47+
}
48+
return comment;
49+
}
50+
2651
/**
2752
* Formats documentation as HTML.
2853
*

test/lib/highlight.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)