diff --git a/.editorconfig b/.editorconfig index 563987c..77a9976 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,15 +1,15 @@ [*.js] -indent_style = space; -indent_size = 2; -continuation_indent_size = 2; -insert_final_newline = true; -quote_type = single; -space_after_anonymous_functions = true; -space_after_control_statements = true; -spaces_around_operators = true; -trim_trailing_whitespace = true; -spaces_in_brackets = false; -curly_bracket_next_line = true; -indent_brace_style = 1TBS; -end_of_line = lf; -charset = utf-8; +indent_style = space +indent_size = 2 +continuation_indent_size = 2 +insert_final_newline = true +quote_type = single +space_after_anonymous_functions = true +space_after_control_statements = true +spaces_around_operators = true +trim_trailing_whitespace = true +spaces_in_brackets = false +curly_bracket_next_line = true +indent_brace_style = 1TBS +end_of_line = lf +charset = utf-8 diff --git a/.gitignore b/.gitignore index 59d842b..563b266 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,7 @@ node_modules # Users Environment Variables .lock-wscript + +#IntelliJ +.idea + diff --git a/.travis.yml b/.travis.yml index e8af323..16d761e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,14 @@ language: node_js node_js: + - "0.8" - "0.10" -#travis build speed up +before_install: + - '[ "${TRAVIS_NODE_VERSION}" != "0.8" ] || npm install -g npm@1.4.28' + - npm install -g npm@latest + - npm install -g grunt-cli + +#travis build speed up sudo: false cache: directories: diff --git a/Gruntfile.js b/Gruntfile.js index 0d1a1ff..dcd4bda 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,8 +1,6 @@ module.exports = function (grunt) { 'use strict'; - require('shelljs/global'); - var config = { pkg: grunt.file.readJSON('package.json'), concat: { @@ -15,6 +13,15 @@ module.exports = function (grunt) { dest: 'dist/<%= pkg.name %>.js' } }, + comments: { + js: { + options: { + singleline: true, + multiline: true + }, + src: ['<%= concat.dist.dest %>'] + } + }, uglify: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n', @@ -53,43 +60,16 @@ module.exports = function (grunt) { reporter: 'spec' } } - }, - // Client-side tests - mocha: { - test: { - src: ['test/browser.html'], - options: { - run: true - } - } - }, - githooks: { - all: { - 'pre-commit': 'pre-commit' - } } }; grunt.initConfig(config); - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-contrib-jshint'); - grunt.loadNpmTasks('grunt-simple-mocha'); - grunt.loadNpmTasks('grunt-mocha'); - grunt.loadNpmTasks('grunt-jscs'); - grunt.loadNpmTasks('grunt-conventional-changelog'); - grunt.loadNpmTasks('grunt-githooks'); + require('load-grunt-tasks')(grunt); grunt.registerTask('lint', ['jshint', 'jscs']); - grunt.registerTask('test', ['lint', 'mocha', 'simplemocha']); - grunt.registerTask('build', ['test', 'concat', 'uglify']); - grunt.registerTask('pre-commit', ['build', 'add-compressed-to-git']); - - // Add compressed and minified files before committing - grunt.registerTask('add-compressed-to-git', function () { - exec('git add dist/'); - }); + grunt.registerTask('test', ['lint', 'simplemocha']); + grunt.registerTask('build', ['test', 'concat', 'comments', 'uglify']); grunt.registerTask('default', []); }; diff --git a/README.md b/README.md index 809d85b..f2f4f25 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ After including the extension in your application, you just need to enable it in ## Example ```javascript -var converter = new Showdown.converter({extensions: ['prettify']}), +var converter = new showdown.Converter({extensions: ['prettify']}), input = "Here's a simple hello world in javascript:\n" + "\n" + " alert('Hello World!');\n" + @@ -56,5 +56,5 @@ This should output the equivalent to: ``` ## License -These files are distributed under BSD license. For more information, please check the [LICENSE file](https://github.com/showdownjs/prettify-extension/blob/master/LICENSE) in the source code. - +These files are distributed under BSD license. For more information, +please check the [LICENSE file](https://github.com/showdownjs/prettify-extension/blob/master/LICENSE) in the source code. diff --git a/bower.json b/bower.json index 822b97a..a8049bd 100644 --- a/bower.json +++ b/bower.json @@ -1,10 +1,10 @@ { "name": "showdown-prettify", - "description": "Add markdown prettify favor to showdown", + "description": "Add markdown prettify flavor to showdown", "homepage": "https://github.com/showdownjs/prettify-extension", "license": "BSD", "authors": [ - "Estevão Santos (https://github.com/tivie)", + "Estevão Soares dos Santos (https://github.com/tivie)", "Pascal Deschênes (https://github.com/pdeschen)", "Corey Innis (https://github.com/coreyti)", "John Fraser" @@ -22,7 +22,7 @@ }, "main": ["dist/showdown-prettify.js"], "dependencies": { - "showdown": "^0.3.4" + "showdown": "1.0.x" }, "ignore": [ "src/", diff --git a/dist/showdown-prettify.js b/dist/showdown-prettify.js index 6963f5b..1788801 100644 --- a/dist/showdown-prettify.js +++ b/dist/showdown-prettify.js @@ -1,35 +1,25 @@ -/*! showdown-prettify 24-01-2015 */ -// -// Google Prettify -// A showdown extension to add Google Prettify (http://code.google.com/p/google-code-prettify/) -// hints to showdown's HTML output. -// - +/*! showdown-prettify 04-06-2015 */ (function () { - var prettify = function (converter) { + var prettify = function () { return [ { type: 'output', filter: function (source) { - - return source.replace(/(
)?/gi, function (match, pre) {
+          return source.replace(/(]*>)?[\n\s]?]*)>/gi, function (match, pre, codeClass) {
             if (pre) {
-              return '
';
+              return '
';
             } else {
-              return '';
+              return ' ';
             }
           });
         }
       }
     ];
   };
-
-  // Client-side export
-  if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) {
-    window.Showdown.extensions.prettify = prettify;
+  if (typeof window !== 'undefined' && window.showdown && window.showdown.extensions) {
+    window.showdown.extensions.prettify = prettify;
   }
-  // Server-side export
     if (typeof module !== 'undefined') {
         module.exports = prettify;
     }
diff --git a/dist/showdown-prettify.js.map b/dist/showdown-prettify.js.map
index f5d6adc..d1db071 100644
--- a/dist/showdown-prettify.js.map
+++ b/dist/showdown-prettify.js.map
@@ -1 +1 @@
-{"version":3,"sources":["..\\src\\prettify.js"],"names":[],"mappings":";AAAA;AAAA,IACI,MAAM,CAAC,QAAQ;AAAA,IACf,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,GAA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com/p/google-code-prettify/)\r\n//  hints to showdown's HTML output.\r\n//\r\n\r\n(function () {\r\n\r\n  var prettify = function (converter) {\r\n    return [\r\n      {\r\n        type:   'output',\r\n        filter: function (source) {\r\n\r\n          return source.replace(/(
)?/gi, function (match, pre) {\r\n            if (pre) {\r\n              return '
';\r\n            } else {\r\n              return '';\r\n            }\r\n          });\r\n        }\r\n      }\r\n    ];\r\n  };\r\n\r\n  // Client-side export\r\n  if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) {\r\n    window.Showdown.extensions.prettify = prettify;\r\n  }\r\n  // Server-side export\r\n    if (typeof module !== 'undefined') {\r\n        module.exports = prettify;\r\n    }\r\n\r\n}());\r\n"]}
\ No newline at end of file
+{"version":3,"sources":["../src/showdown-prettify.js"],"names":[],"mappings":";AAAA,EAAE;AACF,EAAE,EAAE,MAAM,CAAC,QAAQ;AACnB,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE;AAChG,EAAE,EAAE,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;AACpC,EAAE;AACF;AACA,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACd;AACA,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC9B,IAAI,MAAM,CAAC,CAAC;AACZ,MAAM,CAAC;AACP,QAAQ,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;AACzB,QAAQ,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AACnC,UAAU,MAAM,CAAC,MAAM,CAAC,OAAO,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AACzG,YAAY,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AACtB,cAAc,MAAM,CAAC,EAAE,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;AACjF,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC;AACpB,cAAc,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,IAAI;AACnD,YAAY,CAAC;AACb,UAAU,GAAG;AACb,QAAQ,CAAC;AACT,MAAM,CAAC;AACP,IAAI,EAAE;AACN,EAAE,EAAE;AACJ;AACA,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM;AACvB,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;AACvF,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC;AACnD,EAAE,CAAC;AACH,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM;AACvB,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;AACxC,QAAQ,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClC,IAAI,CAAC;AACL;AACA,KAAK","file":"showdown-prettify.js","sourcesContent":["//\n//  Google Prettify\n//  A showdown extension to add Google Prettify (http://code.google.com/p/google-code-prettify/)\n//  hints to showdown's HTML output.\n//\n\n(function () {\n\n  var prettify = function () {\n    return [\n      {\n        type:   'output',\n        filter: function (source) {\n          return source.replace(/(]*>)?[\\n\\s]?]*)>/gi, function (match, pre, codeClass) {\n            if (pre) {\n              return '
';\n            } else {\n              return ' ';\n            }\n          });\n        }\n      }\n    ];\n  };\n\n  // Client-side export\n  if (typeof window !== 'undefined' && window.showdown && window.showdown.extensions) {\n    window.showdown.extensions.prettify = prettify;\n  }\n  // Server-side export\n    if (typeof module !== 'undefined') {\n        module.exports = prettify;\n    }\n\n}());\n"]}
\ No newline at end of file
diff --git a/dist/showdown-prettify.min.js b/dist/showdown-prettify.min.js
index d634081..e486891 100644
--- a/dist/showdown-prettify.min.js
+++ b/dist/showdown-prettify.min.js
@@ -1,4 +1,4 @@
-/*! showdown-prettify 24-01-2015 */
+/*! showdown-prettify 04-06-2015 */
 
-!function(){var a=function(){return[{type:"output",filter:function(a){return a.replace(/(
)?/gi,function(a,b){return b?'
':''})}}]};"undefined"!=typeof window&&window.Showdown&&window.Showdown.extensions&&(window.Showdown.extensions.prettify=a),"undefined"!=typeof module&&(module.exports=a)}();
+!function(){var a=function(){return[{type:"output",filter:function(a){return a.replace(/(]*>)?[\n\s]?]*)>/gi,function(a,b,c){return b?'
":' '})}}]};"undefined"!=typeof window&&window.showdown&&window.showdown.extensions&&(window.showdown.extensions.prettify=a),"undefined"!=typeof module&&(module.exports=a)}();
 //# sourceMappingURL=showdown-prettify.min.js.map
\ No newline at end of file
diff --git a/dist/showdown-prettify.min.js.map b/dist/showdown-prettify.min.js.map
index bd01a83..9433cea 100644
--- a/dist/showdown-prettify.min.js.map
+++ b/dist/showdown-prettify.min.js.map
@@ -1 +1 @@
-{"version":3,"file":"showdown-prettify.min.js","sources":["showdown-prettify.js"],"names":["prettify","type","filter","source","replace","match","pre","window","Showdown","extensions","module","exports"],"mappings":";;CAOC,WAEC,GAAIA,GAAW,WACb,QAEIC,KAAQ,SACRC,OAAQ,SAAUC,GAEhB,MAAOA,GAAOC,QAAQ,mBAAoB,SAAUC,EAAOC,GACzD,MAAIA,GACK,uEAEA,kCASG,oBAAXC,SAA0BA,OAAOC,UAAYD,OAAOC,SAASC,aACtEF,OAAOC,SAASC,WAAWT,SAAWA,GAGhB,mBAAXU,UACPA,OAAOC,QAAUX"}
\ No newline at end of file
+{"version":3,"file":"showdown-prettify.min.js","sources":["showdown-prettify.js"],"names":["prettify","type","filter","source","replace","match","pre","codeClass","window","showdown","extensions","module","exports"],"mappings":";;CACC,WAEC,GAAIA,GAAW,WACb,QAEIC,KAAQ,SACRC,OAAQ,SAAUC,GAChB,MAAOA,GAAOC,QAAQ,sCAAuC,SAAUC,EAAOC,EAAKC,GACjF,MAAID,GACK,0CAA4CC,EAAY,IAExD,mCAOG,oBAAXC,SAA0BA,OAAOC,UAAYD,OAAOC,SAASC,aACtEF,OAAOC,SAASC,WAAWV,SAAWA,GAEhB,mBAAXW,UACPA,OAAOC,QAAUZ"}
\ No newline at end of file
diff --git a/package.json b/package.json
index 65b3ac9..31f2af6 100644
--- a/package.json
+++ b/package.json
@@ -1,15 +1,15 @@
 {
   "name": "showdown-prettify",
-  "version": "0.0.2",
-  "description": "Add markdown prettify favor to showdown",
+  "version": "1.0.0",
+  "description": "Add markdown prettify flavor to showdown",
   "keywords": [
     "markdown",
     "showdown",
     "showdown extension",
     "prettify"
   ],
-  "author": "John Fraser",
-  "license": "BSD",
+  "author": "Estevão Soares dos Santos",
+  "license": "BSD-2-Clause",
   "repository": {
     "type": "git",
     "url": "https://github.com/showdownjs/prettify-extension.git",
@@ -20,26 +20,22 @@
   },
   "main": "./dist/showdown-prettify-extension.js",
   "scripts": {
-    "postinstall": "grunt githooks",
     "test": "grunt test"
   },
   "dependencies": {
-    "showdown": "0.x.x"
+    "showdown": "1.0.x"
   },
   "devDependencies": {
-    "chai": "^1.10.0",
+    "chai": "^2.3.0",
     "grunt": "^0.4.5",
     "grunt-cli": "^0.1.13",
+    "load-grunt-tasks": "^3.2.0",
     "grunt-contrib-concat": "^0.5.0",
     "grunt-contrib-jshint": "^0.10.0",
-    "grunt-contrib-uglify": "^0.7.0",
+    "grunt-contrib-uglify": "^0.6.0",
     "grunt-conventional-changelog": "^1.1.0",
-    "grunt-githooks": "^0.3.1",
     "grunt-jscs": "^1.2.0",
-    "grunt-mocha": "^0.4.11",
     "grunt-simple-mocha": "^0.4.0",
-    "jscs": "^1.10.0",
-    "mocha": "^2.1.0",
-    "shelljs": "^0.3.0"
+    "grunt-stripcomments": "^0.3.1"
   }
 }
diff --git a/src/prettify.js b/src/showdown-prettify.js
similarity index 55%
rename from src/prettify.js
rename to src/showdown-prettify.js
index 69b810a..dddb5a6 100644
--- a/src/prettify.js
+++ b/src/showdown-prettify.js
@@ -6,17 +6,16 @@
 
 (function () {
 
-  var prettify = function (converter) {
+  var prettify = function () {
     return [
       {
         type:   'output',
         filter: function (source) {
-
-          return source.replace(/(
)?/gi, function (match, pre) {
+          return source.replace(/(]*>)?[\n\s]?]*)>/gi, function (match, pre, codeClass) {
             if (pre) {
-              return '
';
+              return '
';
             } else {
-              return '';
+              return ' ';
             }
           });
         }
@@ -25,8 +24,8 @@
   };
 
   // Client-side export
-  if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) {
-    window.Showdown.extensions.prettify = prettify;
+  if (typeof window !== 'undefined' && window.showdown && window.showdown.extensions) {
+    window.showdown.extensions.prettify = prettify;
   }
   // Server-side export
     if (typeof module !== 'undefined') {
diff --git a/test/browser.html b/test/browser.html
deleted file mode 100644
index 0976d34..0000000
--- a/test/browser.html
+++ /dev/null
@@ -1,61 +0,0 @@
-
-
-
-  
-  Mocha Tests
-  
-
-
-
- - -

And @something shouldn't render as a prettify link

- -
- - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/cases/basic.html b/test/cases/basic.html deleted file mode 100644 index 161f83f..0000000 --- a/test/cases/basic.html +++ /dev/null @@ -1,6 +0,0 @@ -

Here's a simple hello world in javascript:

- -
alert('Hello World!');
-
- -

The alert function is a build-in global from window.

diff --git a/test/cases/github-style.html b/test/cases/github-style.html new file mode 100644 index 0000000..2b043f3 --- /dev/null +++ b/test/cases/github-style.html @@ -0,0 +1,8 @@ +

Here's some github code style

+ +
var foo = bar;
+
+    function bazinga() {
+    return 'bazinga!!';
+    }
+
diff --git a/test/cases/github-style.md b/test/cases/github-style.md new file mode 100644 index 0000000..392c137 --- /dev/null +++ b/test/cases/github-style.md @@ -0,0 +1,9 @@ +Here's some github code style + +```js +var foo = bar; + +function bazinga() { + return 'bazinga!!'; +} +``` diff --git a/test/cases/indentation.html b/test/cases/indentation.html new file mode 100644 index 0000000..00f9565 --- /dev/null +++ b/test/cases/indentation.html @@ -0,0 +1,4 @@ +

Here's a simple hello world in javascript:

+ +
alert('Hello World!');
+
diff --git a/test/cases/basic.md b/test/cases/indentation.md similarity index 55% rename from test/cases/basic.md rename to test/cases/indentation.md index 38974e6..5d122c2 100644 --- a/test/cases/basic.md +++ b/test/cases/indentation.md @@ -2,4 +2,3 @@ Here's a simple hello world in javascript: alert('Hello World!'); -The `alert` function is a build-in global from `window`. diff --git a/test/cases/inline.html b/test/cases/inline.html new file mode 100644 index 0000000..02d5993 --- /dev/null +++ b/test/cases/inline.html @@ -0,0 +1 @@ +

Some inline javascript var foo = bar

diff --git a/test/cases/inline.md b/test/cases/inline.md new file mode 100644 index 0000000..191c751 --- /dev/null +++ b/test/cases/inline.md @@ -0,0 +1 @@ +Some inline javascript`var foo = bar` diff --git a/test/node.js b/test/node.js index 6d69a1f..2573631 100644 --- a/test/node.js +++ b/test/node.js @@ -4,9 +4,9 @@ require('chai').should(); var fs = require('fs'), - extension = require('../src/prettify.js'), + extension = require('../src/showdown-prettify.js'), showdown = require('showdown'), - converter = new showdown.converter({extensions: [extension]}), + converter = new showdown.Converter({extensions: [extension]}), cases = fs.readdirSync('test/cases/') .filter(filter()) .map(map('test/cases/')),