From 14b59ef33da9682763d013e6a9a963da7dc147b3 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 18 Dec 2013 17:39:56 -0500 Subject: [PATCH 1/2] adding full generated html with @example tag --- test/samples/example-tag.js | 20 +++++++ test/samples/example-tag.jsdoc.html | 91 +++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 test/samples/example-tag.js create mode 100644 test/samples/example-tag.jsdoc.html 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);
+
+
+
+ + From dd654de7376f8746924c7ce6e620c24d02528be5 Mon Sep 17 00:00:00 2001 From: Thorsten Lorenz Date: Wed, 18 Dec 2013 18:18:33 -0500 Subject: [PATCH 2/2] converting
 to '''js, but seems like github
 doesn't interpret it inside html block

---
 lib/adapt-code.js | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 lib/adapt-code.js

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); + +}