From 1c4c894029539dd339247fa032b0e0620636c012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Soares=20dos=20Santos?= Date: Sat, 24 Jan 2015 16:05:54 +0000 Subject: [PATCH] initial code commit --- .editorconfig | 15 +++++ .jscs.json | 90 ++++++++++++++++++++++++++++ .jshintrc | 28 +++++++++ .travis.yml | 9 +++ Gruntfile.js | 95 ++++++++++++++++++++++++++++++ README.md | 62 ++++++++++++++++++- bower.json | 34 +++++++++++ dist/showdown-prettify.js | 39 ++++++++++++ dist/showdown-prettify.js.map | 1 + dist/showdown-prettify.min.js | 4 ++ dist/showdown-prettify.min.js.map | 1 + package.json | 45 ++++++++++++++ src/prettify.js | 36 ++++++++++++ test/browser.html | 61 +++++++++++++++++++ test/cases/basic.html | 6 ++ test/cases/basic.md | 5 ++ test/issues/.gitkeep | 1 + test/node.js | 98 +++++++++++++++++++++++++++++++ 18 files changed, 627 insertions(+), 3 deletions(-) create mode 100644 .editorconfig create mode 100644 .jscs.json create mode 100644 .jshintrc create mode 100644 .travis.yml create mode 100644 Gruntfile.js create mode 100644 bower.json create mode 100644 dist/showdown-prettify.js create mode 100644 dist/showdown-prettify.js.map create mode 100644 dist/showdown-prettify.min.js create mode 100644 dist/showdown-prettify.min.js.map create mode 100644 package.json create mode 100644 src/prettify.js create mode 100644 test/browser.html create mode 100644 test/cases/basic.html create mode 100644 test/cases/basic.md create mode 100644 test/issues/.gitkeep create mode 100644 test/node.js diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..563987c --- /dev/null +++ b/.editorconfig @@ -0,0 +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; diff --git a/.jscs.json b/.jscs.json new file mode 100644 index 0000000..f3d0acb --- /dev/null +++ b/.jscs.json @@ -0,0 +1,90 @@ +{ + "validateIndentation": 2, + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "try", + "catch" + ], + "requireOperatorBeforeLineBreak": true, + "requireCamelCaseOrUpperCaseIdentifiers": true, + "validateIndentation": 2, + "validateQuoteMarks": "'", + "disallowMultipleLineStrings": true, + "disallowMixedSpacesAndTabs": true, + "disallowTrailingWhitespace": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "requireMultipleVarDecl": true, + "disallowKeywordsOnNewLine": ["else"], + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "return", + "try", + "catch" + ], + "requireSpaceBeforeBinaryOperators": [ + "=", + "+=", + "-=", + "*=", + "/=", + "%=", + "<<=", + ">>=", + ">>>=", + "&=", + "|=", + "^=", + "+=", + "+", + "-", + "*", + "/", + "%", + "<<", + ">>", + ">>>", + "&", + "|", + "^", + "&&", + "||", + "===", + "==", + ">=", + "<=", + "<", + ">", + "!=", + "!==" + ], + "requireSpaceAfterBinaryOperators": true, + "requireSpacesInConditionalExpression": true, + "requireSpaceBeforeBlockStatements": true, + "requireSpacesInForStatement": true, + "requireLineFeedAtFileEnd": true, + "requireSpacesInFunctionExpression": { + "beforeOpeningCurlyBrace": true + }, + "requireSpacesInAnonymousFunctionExpression": { + "beforeOpeningRoundBrace": true, + "beforeOpeningCurlyBrace": true + }, + "disallowSpacesInsideObjectBrackets": "all", + "disallowSpacesInsideArrayBrackets": "all", + "disallowSpacesInsideParentheses": true, + "validateJSDoc": { + "checkParamNames": true, + "requireParamTypes": true + }, + "disallowMultipleLineBreaks": true, + "disallowNewlineBeforeBlockStatements": true +} diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..0dfea06 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,28 @@ +{ + "node": true, + "browser": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": "nofunc", + "newcap": true, + "noarg": true, + "quotmark": "single", + "undef": false, + "unused": true, + "strict": true, + "trailing": true, + "smarttabs": true, + "onevar": true, + "globals": { + "angular": true, + "module": true, + "define": true, + "window": true, + "showdown": true + } +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e8af323 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: node_js +node_js: + - "0.10" + +#travis build speed up +sudo: false +cache: + directories: + - node_modules diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..0d1a1ff --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,95 @@ +module.exports = function (grunt) { + 'use strict'; + + require('shelljs/global'); + + var config = { + pkg: grunt.file.readJSON('package.json'), + concat: { + options: { + banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n', + sourceMap: true + }, + dist: { + src: ['src/*.js'], + dest: 'dist/<%= pkg.name %>.js' + } + }, + uglify: { + options: { + banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n', + sourceMap: true + }, + dist: { + files: { + 'dist/<%= pkg.name %>.min.js': ['<%= concat.dist.dest %>'] + } + } + }, + jshint: { + files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'] + }, + jscs: { + options: { + config: '.jscs.json', + files: [ + 'Gruntfile.js', + 'src/**/*.js', + 'test/**/*.js' + ] + } + }, + changelog: { + options: {} + }, + //Server-side tests + simplemocha: { + test: { + src: 'test/node.js', + options: { + globals: ['should'], + timeout: 3000, + ignoreLeaks: false, + 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'); + + 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('default', []); +}; diff --git a/README.md b/README.md index aa1a2a7..2f8f21b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,60 @@ -prettify -======== +Showdown's Prettify Extension +========================== + +[![Build Status](https://travis-ci.org/showdownjs/prettify-extension)](https://travis-ci.org/showdownjs/prettify-extension.svg) [![npm version](https://badge.fury.io/js/showdown-prettify.svg)](http://badge.fury.io/js/showdown-prettify) [![npm version](https://badge.fury.io/bo/showdown-prettify.svg)](http://badge.fury.io/bo/showdown-prettify) + +------ + +**An extension to add [Google Prettify](http://code.google.com/p/google-code-prettify/) hints to [showdown](https://github.com/showdownjs/showdown)'s HTML output ** + + +## Installation + +### With [npm](http://npmjs.org) + + npm install showdown-prettify + +### With [bower](http://bower.io/) + + bower install showdown-prettify + +### Manual + +You can also [download the latest release zip or tarball](https://github.com/showdownjs/prettify-extension/releases) and include it in your webpage, after showdown: + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/cases/basic.html b/test/cases/basic.html new file mode 100644 index 0000000..161f83f --- /dev/null +++ b/test/cases/basic.html @@ -0,0 +1,6 @@ +

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/basic.md b/test/cases/basic.md new file mode 100644 index 0000000..38974e6 --- /dev/null +++ b/test/cases/basic.md @@ -0,0 +1,5 @@ +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/issues/.gitkeep b/test/issues/.gitkeep new file mode 100644 index 0000000..0982a78 --- /dev/null +++ b/test/issues/.gitkeep @@ -0,0 +1 @@ +#a bogus file used to keep the issues directory when committing \ No newline at end of file diff --git a/test/node.js b/test/node.js new file mode 100644 index 0000000..6d69a1f --- /dev/null +++ b/test/node.js @@ -0,0 +1,98 @@ +(function () { + 'use strict'; + + require('chai').should(); + + var fs = require('fs'), + extension = require('../src/prettify.js'), + showdown = require('showdown'), + converter = new showdown.converter({extensions: [extension]}), + cases = fs.readdirSync('test/cases/') + .filter(filter()) + .map(map('test/cases/')), + issues = fs.readdirSync('test/issues/') + .filter(filter()) + .map(map('test/issues/')); + + // Register prettify extension + //showdown.extensions.prettify = prettify; + + ///////////////////////////////////////////////////////////////////////////// + // Test cases + // + describe('Prettify Extension simple testcases', function () { + for (var i = 0; i < cases.length; ++i) { + it(cases[i].name, assertion(cases[i])); + } + }); + + describe('Prettify Extension issues testcase', function () { + for (var i = 0; i < issues.length; ++i) { + it(issues[i].name, assertion(issues[i])); + } + }); + + ///////////////////////////////////////////////////////////////////////////// + // Test cases + // + function filter() { + return function (file) { + var ext = file.slice(-3); + return (ext === '.md'); + }; + } + + function map(dir) { + return function (file) { + var name = file.replace('.md', ''), + htmlPath = dir + name + '.html', + html = fs.readFileSync(htmlPath, 'utf8'), + mdPath = dir + name + '.md', + md = fs.readFileSync(mdPath, 'utf8'); + + return { + name: name, + input: md, + expected: html + }; + }; + } + + //Normalize input/output + function normalize(testCase) { + + // Normalize line returns + testCase.expected = testCase.expected.replace(/\r/g, ''); + testCase.actual = testCase.actual.replace(/\r/g, ''); + + // Ignore all leading/trailing whitespace + testCase.expected = testCase.expected.split('\n').map(function (x) { + return x.trim(); + }).join('\n'); + testCase.actual = testCase.actual.split('\n').map(function (x) { + return x.trim(); + }).join('\n'); + + // Remove extra lines + testCase.expected = testCase.expected.trim(); + + // Convert whitespace to a visible character so that it shows up on error reports + testCase.expected = testCase.expected.replace(/ /g, '·'); + testCase.expected = testCase.expected.replace(/\n/g, '•\n'); + testCase.actual = testCase.actual.replace(/ /g, '·'); + testCase.actual = testCase.actual.replace(/\n/g, '•\n'); + + return testCase; + + } + + function assertion(testCase) { + return function () { + testCase.actual = converter.makeHtml(testCase.input); + testCase = normalize(testCase); + + // Compare + testCase.actual.should.equal(testCase.expected); + }; + } +})();