diff --git a/lib/adapt-code.js b/lib/adapt-code.js new file mode 100644 index 0000000..1ec8bc3 --- /dev/null +++ b/lib/adapt-code.js @@ -0,0 +1,44 @@ +'use strict'; + +var cheerio = require('cheerio'); + +var go = module.exports = function (html) { + var dom = cheerio('<__wrap__>' + html + ''); + dom.find('pre.prettyprint') + .each(function (idx, x) { + var pre = cheerio(x); + var code = pre.find('code'); + + if (!code) return; + + var src = code.html(); + pre.replaceWith([ + '' + , '```js' + , src + , '```' + , '' + ].join('\n') + ); + }) + return dom.html(); +}; + +// Test +if (!module.parent && typeof window === 'undefined') { + var html = [ + '
Example
' + , '
// contrived example to test code highlighting'
+ , 'var assert = require(\'assert\')'
+ , '  , add = require(\'add\');'
+ , ''
+ , 'var c = add(1, 2);'
+ , 'assert.equal(c, 1 + 2);
' + , ' ' + , ' ' + ].join('\n'); + + var res = go(html); + console.log(res); + +} diff --git a/test/samples/example-tag.js b/test/samples/example-tag.js new file mode 100644 index 0000000..8a8468d --- /dev/null +++ b/test/samples/example-tag.js @@ -0,0 +1,20 @@ + +/** + * Adds a and b and returns the result. + * + * @example + * // contrived example to test code highlighting + * var assert = require('assert') + * , add = require('add'); + * + * var c = add(1, 2); + * assert.equal(c, 1 + 2); + * + * @name add + * @function + * @param {Number} a first number + * @param {Number} b second number + */ +function add(a, b) { + +} diff --git a/test/samples/example-tag.jsdoc.html b/test/samples/example-tag.jsdoc.html new file mode 100644 index 0000000..8eec3c0 --- /dev/null +++ b/test/samples/example-tag.jsdoc.html @@ -0,0 +1,91 @@ + + + + + + + + + + + + +
+

Global

+ +
+
+
+ +

Methods

+ +
+
+

add(a, b)

+
+ +
+
+

Adds a and b and returns the result.

+
+ +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
aNumber +

first number

+
bNumber +

second number

+
+ +
+
Source:
+ +
+
    +
  • example-tag.js, line 2
  • +
+
+
+ +
Example
+
// contrived example to test code highlighting
+var assert = require('assert')
+ , add = require('add');
+
+var c = add(1, 2);
+assert.equal(c, 1 + 2);
+
+
+
+ +