diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..c6c8b36 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 7586723..0000000 --- a/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "env": { - "node": true, - "browser": true - }, - "rules": { - "quotes": [2, "single"] - } -} diff --git a/.gitignore b/.gitignore index f41859a..97b6375 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ .DS_Store *.log -bower_components/ -build/ -components/ +.nyc_output/ coverage/ node_modules/ -build.js +strip-markdown.js +strip-markdown.min.js diff --git a/.jscs.json b/.jscs.json deleted file mode 100644 index 7345bfb..0000000 --- a/.jscs.json +++ /dev/null @@ -1,143 +0,0 @@ -{ - "plugins": [ - "jscs-jsdoc" - ], - "jsDoc": { - "checkAnnotations": "jsdoc3", - "checkParamNames": true, - "requireParamTypes": true, - "checkRedundantParams": true, - "checkReturnTypes": true, - "checkRedundantReturns": true, - "requireReturnTypes": true, - "checkTypes": "strictNativeCase", - "checkRedundantAccess": true, - "enforceExistence": true, - "requireHyphenBeforeDescription": true - }, - "requireCurlyBraces": [ - "if", - "else", - "for", - "while", - "do", - "try", - "catch" - ], - "requireSpaceAfterKeywords": [ - "if", - "else", - "for", - "while", - "do", - "switch", - "return", - "try", - "catch" - ], - "requireSpaceBeforeBlockStatements": true, - "requireParenthesesAroundIIFE": true, - "requireSpacesInConditionalExpression": true, - "requireSpacesInAnonymousFunctionExpression": { - "beforeOpeningRoundBrace": true, - "beforeOpeningCurlyBrace": true - }, - "requireSpacesInNamedFunctionExpression": { - "beforeOpeningRoundBrace": true, - "beforeOpeningCurlyBrace": true - }, - "requireSpacesInFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "requireBlocksOnNewline": true, - "disallowPaddingNewlinesInBlocks": true, - "disallowEmptyBlocks": true, - "disallowSpacesInsideObjectBrackets": true, - "disallowSpacesInsideArrayBrackets": true, - "disallowSpacesInsideParentheses": true, - "requireSpacesInsideObjectBrackets": "all", - "disallowDanglingUnderscores": true, - "disallowSpaceAfterObjectKeys": true, - "requireCommaBeforeLineBreak": true, - "requireOperatorBeforeLineBreak": [ - "?", - "+", - "-", - "/", - "*", - "=", - "==", - "===", - "!=", - "!==", - ">", - ">=", - "<", - "<=" - ], - "requireSpaceBeforeBinaryOperators": [ - "+", - "-", - "/", - "*", - "=", - "==", - "===", - "!=", - "!==" - ], - "requireSpaceAfterBinaryOperators": [ - "+", - "-", - "/", - "*", - "=", - "==", - "===", - "!=", - "!==" - ], - "disallowSpaceAfterPrefixUnaryOperators": [ - "++", - "--", - "+", - "-", - "~", - "!" - ], - "disallowSpaceBeforePostfixUnaryOperators": [ - "++", - "--" - ], - "disallowImplicitTypeConversion": [ - "numeric", - "boolean", - "binary", - "string" - ], - "requireCamelCaseOrUpperCaseIdentifiers": true, - "disallowKeywords": [ - "with" - ], - "disallowMultipleLineStrings": true, - "disallowMultipleLineBreaks": true, - "validateLineBreaks": "LF", - "validateQuoteMarks": "'", - "disallowMixedSpacesAndTabs": true, - "disallowTrailingWhitespace": true, - "disallowTrailingComma": true, - "disallowKeywordsOnNewLine": [ - "else" - ], - "requireLineFeedAtFileEnd": true, - "maximumLineLength": 78, - "requireCapitalizedConstructors": true, - "safeContextKeyword": "self", - "requireDotNotation": true, - "disallowYodaConditions": true, - "validateJSDoc": { - "checkParamNames": true, - "checkRedundantParams": true, - "requireParamTypes": true - } -} diff --git a/.mdastignore b/.mdastignore deleted file mode 100644 index 68ffb32..0000000 --- a/.mdastignore +++ /dev/null @@ -1 +0,0 @@ -components/ diff --git a/.mdastrc b/.mdastrc deleted file mode 100644 index 95c136a..0000000 --- a/.mdastrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "plugins": [ - "github", - "lint", - "usage", - "yaml-config" - ], - "settings": { - "bullet": "*" - } -} diff --git a/.npmignore b/.npmignore deleted file mode 100644 index ded4142..0000000 --- a/.npmignore +++ /dev/null @@ -1,17 +0,0 @@ -.* -*.log -*.sh -bower_components/ -build/ -components/ -coverage/ -node_modules/ -benchmark.js -build.js -example.js -strip-markdown.js -strip-markdown.min.js -test.js -bower.json -component.json -History.md diff --git a/.travis.yml b/.travis.yml index 5a4bbc0..85fa908 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,24 @@ language: node_js -script: npm run-script test-travis node_js: -- '0.10' - '0.11' -- '0.12' -- iojs -sudo: false -after_script: npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls +- '5.0' +- '6.0' +after_success: +- bash <(curl -s https://codecov.io/bash) +deploy: + - provider: npm + email: tituswormer@gmail.com + api_key: + secure: xRc8HeFR9M5ZSBH4kj7TBDlyeaFpT2EK+4XGcn3x2eKlR4vdj1EQls8qbGdu3YZaQ0Q+AEILOKmsZZBNCiV5IuZjFMQFwMZpMCEC4SpNvmC33Wy6iEbblg+PnU2xWe9EanIuwOSI3XO3Xr5sgXvJaRpg2zhZhvwgFPKuovxinV4= + on: + tags: true + node: '5.0' + - provider: releases + api_key: + secure: aljGeSHmOn4ycz4O4/VGdP+96PNJwUEA7YFDxt9ToUpD6NvvirxJOFWntMpikelwXP3+c6+DIy7RhJgemuniv+Gq9NplNNQV4JF1hwBuEGjg4VSglRBpaP5EeqeWRkrfu5M59X7eywhbvKDJxqWjuY6vkHEXP28/tH/0S6kEujA= + file: + - "strip-markdown.js" + - "strip-markdown.min.js" + on: + tags: true + node: '6.0' diff --git a/benchmark.js b/benchmark.js deleted file mode 100644 index 1c5a054..0000000 --- a/benchmark.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -/* globals suite, bench */ - -/* - * Dependencies. - */ - -var fs = require('fs'); -var summarize = require('summarize-markdown'); -var stripMarkdown = require('./'); -var mdast = require('mdast'); - -/* - * Processor. - */ - -var processor = mdast.use(stripMarkdown); - -/* - * Fixtures. - */ - -var fixture = fs.readFileSync('Readme.md', 'utf-8'); - -/** - * Wrapper for `strip-markdown`. - * - * @param {string} value - * @return {string} - */ -function strip(value) { - return processor.process(value); -} - -/* - * Benchmark. - */ - -suite('This project\'s `Readme.md`', function () { - bench('strip-markdown -- this module', function () { - strip(fixture); - }); - - bench('summarize-markdown', function () { - summarize(fixture); - }); -}); diff --git a/bower.json b/bower.json deleted file mode 100644 index 7cd8210..0000000 --- a/bower.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - "name": "strip-markdown", - "main": "strip-markdown.js", - "description": "Remove markdown formatting", - "license": "MIT", - "keywords": [ - "text", - "markdown", - "plain", - "text" - ], - "repository": { - "type": "git", - "url": "https://github.com/wooorm/strip-markdown.git" - }, - "authors": [ - "Titus Wormer " - ], - "ignore": [ - ".*", - "*.log", - "*.md", - "*.sh", - "build/", - "components/", - "coverage/", - "node_modules/", - "benchmark.js", - "build.js", - "example.js", - "index.js", - "test.js", - "component.json", - "package.json" - ] -} diff --git a/component.json b/component.json deleted file mode 100644 index 02b2946..0000000 --- a/component.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "name": "strip-markdown", - "version": "0.3.1", - "description": "Remove markdown formatting", - "license": "MIT", - "keywords": [ - "text", - "markdown", - "plain", - "text" - ], - "repository": "wooorm/strip-markdown", - "scripts": [ - "index.js" - ] -} diff --git a/example.js b/example.js deleted file mode 100644 index e745f62..0000000 --- a/example.js +++ /dev/null @@ -1,9 +0,0 @@ -// Require dependencies: -var strip = require('./index.js'); -var mdast = require('mdast').use(strip); - -// Process markdown: -var doc = mdast.process('Some *emphasis*, **strongness**, and `code`.'); - -// Yields: -console.log('text', doc); diff --git a/history.md b/history.md deleted file mode 100644 index 41ca171..0000000 --- a/history.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -mdast: - setext: true ---- - - - -0.3.1 / 2015-07-13 -================== - -* Remove peer-dependencies ([8841d3f](https://github.com/wooorm/strip-markdown/commit/8841d3f)) - -0.3.0 / 2015-05-20 -================== - -* Fix example, benchmark, test for changes in mdast ([f7b70f1](https://github.com/wooorm/strip-markdown/commit/f7b70f1), - closes [GH-1](https://github.com/wooorm/strip-markdown/issues/1)) - -* Update mdast ([05c8826](https://github.com/wooorm/strip-markdown/commit/05c8826)) - -* Update browserify, eslint, jscs-jsdoc ([3968425](https://github.com/wooorm/strip-markdown/commit/3968425)) - -0.2.0 / 2015-03-25 -================== - -* Add mdast-github as a dev-dependency ([435f724](https://github.com/wooorm/strip-markdown/commit/435f724)) -* Update `.travis.yml` ([8392fb7](https://github.com/wooorm/strip-markdown/commit/8392fb7)) -* Fix escapes ([99c7183](https://github.com/wooorm/strip-markdown/commit/99c7183)) -* Update for CLI updates in mdast ([0c150dd](https://github.com/wooorm/strip-markdown/commit/0c150dd)) -* Refactor plugin mechanism ([81ef542](https://github.com/wooorm/strip-markdown/commit/81ef542)) -* Refactor variable declarations ([6c1023b](https://github.com/wooorm/strip-markdown/commit/6c1023b)) -* Fix mocha ([2731722](https://github.com/wooorm/strip-markdown/commit/2731722)) -* Remove CLI ([9d3ddc6](https://github.com/wooorm/strip-markdown/commit/9d3ddc6)) -* Update browserify ([75c0df4](https://github.com/wooorm/strip-markdown/commit/75c0df4)) -* Update eslint ([cbaacc1](https://github.com/wooorm/strip-markdown/commit/cbaacc1)) -* Add `build-usage` task to render `example.js` to `Readme.md` ([8d9eccd](https://github.com/wooorm/strip-markdown/commit/8d9eccd)) -* Add `example.js` to lint tasks ([20ddbdd](https://github.com/wooorm/strip-markdown/commit/20ddbdd)) -* Add `example.js` ([b64a5da](https://github.com/wooorm/strip-markdown/commit/b64a5da)) -* Remove `requireMultipleVarDecl` rule from `.jscs.json` ([bf58011](https://github.com/wooorm/strip-markdown/commit/bf58011)) -* Add `mdast-usage` as dev-dependencies ([c8cd725](https://github.com/wooorm/strip-markdown/commit/c8cd725)) - -0.1.1 / 2015-01-26 -================== - -* Fix bug where CLI did not work due to incorrect resolving -* Add `cli.js` to bower ignore - -0.1.0 / 2015-01-25 -================== diff --git a/index.js b/index.js index 1c3447e..921aa9a 100644 --- a/index.js +++ b/index.js @@ -1,200 +1,128 @@ -'use strict'; - /** - * Throw. - * - * @param {string} message + * @author Titus Wormer + * @copyright 2015 Titus Wormer + * @license MIT + * @module strip-markdown + * @fileoverview Remove markdown formatting. */ -function exception(message) { - throw new Error(message); -} -/** - * Return nothing. - * - * @return {null} - */ -function empty() { - return null; -} +/* Expose `strip`. */ +module.exports = strip; -/** - * Return an stringified image. - * - * @param {Image} token - * @return {Node} - */ -function image(token) { - return { - 'type': 'text', - 'value': token.alt || token.title || '' - }; -} - -/** - * Return the concatenation of `token`s children. - * - * @param {Object} token - * @return {Array.} - */ -function children(token) { - return token.children; +/* Attacher. */ +function strip() { + return one; } -/** - * Return the concatenation of `token`s children. - * - * @param {Object} token - * @return {Node} - */ -function paragraph(token) { - return { - 'type': 'paragraph', - 'children': token.children - }; -} - -/** - * Return `token`s value. - * - * @param {Object} token - * @return {Node} - */ -function inline(token) { - return { - 'type': 'text', - 'value': token.value - }; -} - -/* - * Expose modifiers for available node types. - * - * Node types not listed here are not - * changed (but their children are). - */ - +/* Expose modifiers for available node types. + * Node types not listed here are not changed + * (but their children are). */ var map = {}; -map.blockquote = children; -map.list = children; -map.listItem = children; -map.strong = children; -map.emphasis = children; -map.delete = children; -map.link = children; - map.heading = paragraph; - -map.text = inline; -map.inlineCode = inline; - -map.code = empty; -map.html = empty; -map.horizontalRule = empty; -map.table = empty; -map.tableCell = empty; - +map.text = map.inlineCode = text; map.image = image; -/** - * Clean nodes: merges text's. - * - * @param {Array.} values - * @return {Array.} - */ -function clean(values) { - var index = -1; - var length = values.length; - var result = []; - var prev = null; - var value; - - while (++index < length) { - value = values[index]; - - if (prev && 'value' in value && value.type === prev.type) { - prev.value += value.value; - } else { - result.push(value); - prev = value; - } - } +map.blockquote = map.list = map.listItem = map.strong = + map.emphasis = map.delete = map.link = children; - return result; -} +map.code = map.horizontalRule = map.thematicBreak = map.html = + map.table = map.tableCell = empty; -/* - * Define cleaners. - */ +/* One node. */ +function one(node) { + var type = node && node.type; -var strip; -var stripAll; + if (type in map) { + node = map[type](node); + } else if (typeof type !== 'string') { + throw new Error('Invalid type: ' + type); + } -/** - * Strip markdown formatting from a node. - * - * @param {Node} node - * @return {null|Node|Array.} - */ -strip = function (node) { - var type = node && node.type; + if (node) { + if (node.length) { + node = all(node); + } - if (type in map) { - node = map[type](node); - } else if (typeof type !== 'string') { - exception('Invalid type: ' + type); + if (node.children) { + node.children = all(node.children); } + } - if (node) { - if (node.length) { - node = stripAll(node); - } + return node; +} + +/* Multiple nodes. */ +function all(nodes) { + var index = -1; + var length = nodes.length; + var result = []; + var value; - if (node.children) { - node.children = stripAll(node.children); - } + while (++index < length) { + value = one(nodes[index]); + + if (value && value.length) { + result = result.concat(value.map(one)); + } else if (value) { + result.push(value); } + } - return node; -}; + return clean(result); +} /** - * Strip markdown formatting from multiple nodes. + * Clean nodes: merges text's. * - * @param {Array.} nodes + * @param {Array.} values * @return {Array.} */ -stripAll = function (nodes) { - var index = -1; - var length = nodes.length; - var result = []; - var value; - - while (++index < length) { - value = strip(nodes[index]); - - if (value && value.length) { - result = result.concat(value.map(strip)); - } else if (value) { - result.push(value); - } +function clean(values) { + var index = -1; + var length = values.length; + var result = []; + var prev = null; + var value; + + while (++index < length) { + value = values[index]; + + if (prev && 'value' in value && value.type === prev.type) { + prev.value += value.value; + } else { + result.push(value); + prev = value; } + } - return clean(result); -}; + return result; +} -/** - * Attacher - * - * @return {function(Node)} - */ -function attacher() { - return strip; +/* Return an stringified image. */ +function image(token) { + return { + type: 'text', + value: token.alt || token.title || '' + }; } -/* - * Expose `strip`. - */ +/* Return `token`s value. */ +function text(token) { + return {type: 'text', value: token.value}; +} -module.exports = attacher; +/* Return a paragraph. */ +function paragraph(token) { + return {type: 'paragraph', children: token.children}; +} + +/* Return the concatenation of `token`s children. */ +function children(token) { + return token.children; +} + +/* Return nothing. */ +function empty() { + return null; +} diff --git a/package.json b/package.json index bf5bbd1..876a9f5 100644 --- a/package.json +++ b/package.json @@ -9,44 +9,53 @@ "plain", "text" ], - "repository": { - "type": "git", - "url": "https://github.com/wooorm/strip-markdown.git" + "repository": "https://github.com/wooorm/strip-markdown", + "bugs": "https://github.com/wooorm/strip-markdown/issues", + "author": "Titus Wormer (http://wooorm.com)", + "contributors": [ + "Titus Wormer (http://wooorm.com)" + ], + "engines": { + "node": ">=0.11.0" }, - "author": "Titus Wormer ", + "files": [ + "index.js" + ], + "dependencies": {}, "devDependencies": { - "browserify": "^10.0.0", - "eslint": "^0.24.0", + "browserify": "^13.0.0", "esmangle": "^1.0.0", - "istanbul": "^0.3.0", - "jscs": "^1.0.0", - "jscs-jsdoc": "^1.0.0", - "matcha": "^0.6.0", - "mdast": "^0.26.0", - "mdast-github": "^0.3.0", - "mdast-lint": "^0.4.2", - "mdast-usage": "^0.3.0", - "mdast-yaml-config": "^0.2.1", - "mocha": "^2.0.0", - "summarize-markdown": "^0.3.0" + "nyc": "^8.3.0", + "remark": "^6.0.1", + "remark-cli": "^2.0.0", + "remark-preset-wooorm": "^1.0.0", + "tape": "^4.4.0", + "xo": "^0.16.0" }, "scripts": { - "test-api": "mocha --check-leaks test.js", - "test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test.js", - "test-coverage": "istanbul cover _mocha -- test.js", - "test-travis": "npm run test-coveralls", - "test": "npm run test-api", - "lint-api": "eslint index.js", - "lint-benchmark": "eslint --global set,suite,bench benchmark.js", - "lint-test": "eslint --env mocha test.js", - "lint-script": "eslint example.js", - "lint-style": "jscs --reporter inline index.js benchmark.js example.js test.js", - "lint": "npm run lint-api && npm run lint-benchmark && npm run lint-test && npm run lint-script && npm run lint-style", - "make": "npm run lint && npm run test-coverage", - "benchmark": "matcha benchmark.js", - "bundle": "browserify index.js -s stripMarkdown > strip-markdown.js", - "postbundle": "esmangle strip-markdown.js > strip-markdown.min.js", - "build-md": "mdast . --output --quiet", - "build": "npm run bundle && npm run build-md" + "build-md": "remark . --quiet --frail", + "build-bundle": "browserify index.js -s stripMarkdown > strip-markdown.js", + "build-mangle": "esmangle strip-markdown.js > strip-markdown.min.js", + "build": "npm run build-md && npm run build-bundle && npm run build-mangle", + "lint": "xo", + "test-api": "node test", + "test-coverage": "nyc --reporter lcov tape test/index.js", + "test": "npm run build && npm run lint && npm run test-coverage" + }, + "nyc": { + "check-coverage": true, + "lines": 100, + "functions": 100, + "branches": 100 + }, + "xo": { + "space": true, + "ignores": [ + "strip-markdown.js" + ] + }, + "remarkConfig": { + "output": true, + "presets": "wooorm" } } diff --git a/readme.md b/readme.md index 698b6b6..402b36d 100644 --- a/readme.md +++ b/readme.md @@ -1,58 +1,35 @@ -# strip-markdown [![Build Status](https://img.shields.io/travis/wooorm/strip-markdown.svg?style=flat)](https://travis-ci.org/wooorm/strip-markdown) [![Coverage Status](https://img.shields.io/coveralls/wooorm/strip-markdown.svg?style=flat)](https://coveralls.io/r/wooorm/strip-markdown?branch=master) +# strip-markdown [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] -Remove [Markdown](http://daringfireball.net/projects/markdown/syntax) -formatting with [mdast](https://github.com/wooorm/mdast). +Remove Markdown formatting with [**remark**][remark]. -## Installation +This essentially removes everything but paragraphs and text nodes. -[npm](https://docs.npmjs.com/cli/install): +> This is one of the first remark plugins, before prefixing with +> `remark-` got cool. -```bash -npm install strip-markdown -``` - -[Component.js](https://github.com/componentjs/component): - -```bash -component install wooorm/strip-markdown -``` +## Installation -[Bower](http://bower.io/#install-packages): +[npm][npm-install]: ```bash -bower install strip-markdown -``` - -[Duo](http://duojs.org/#getting-started): - -```javascript -var stripMarkdown = require('wooorm/strip-markdown'); -``` - -UMD (globals/AMD/CommonJS) ([uncompressed](strip-markdown.js) and [compressed](strip-markdown.min.js)): - -```html - - - +npm install strip-markdown ``` ## Usage -Require dependencies: +Dependencies: ```javascript var strip = require('strip-markdown'); -var mdast = require('mdast').use(strip); +var remark = require('remark'); +var processor = remark().use(strip); ``` -Process markdown: +Process: ```javascript -var doc = mdast.process('Some *emphasis*, **strongness**, and `code`.'); +var file = processor.process('Some *emphasis*, **strongness**, and `code`.'); +var doc = String(file); ``` Yields: @@ -63,24 +40,32 @@ Some emphasis, strongness, and code. ## API -### [mdast](https://github.com/wooorm/mdast#api).[use](https://github.com/wooorm/mdast#mdastuseplugin)(stripMarkdown) +### `remark().use(strip)` -Modifies **mdast** to expose simple plain-text. +Modifies **remark** to expose plain-text. * Removes `html`, `code`, `horizontalRule`, `table`, and their content; * Render everything else as simple paragraphs without formatting. +* Uses `alt` text for images. -## Benchmark +## License -It’s pretty fast. Slower than **summarize-markdown**, but a lot cooler -(such as supporting images and more). +[MIT][license] © [Titus Wormer][author] -```text - This project's `Readme.md` - 801 op/s » strip-markdown -- this module -2,382 op/s » summarize-markdown -``` + -## License +[travis-badge]: https://img.shields.io/travis/wooorm/to-vfile.svg + +[travis]: https://travis-ci.org/wooorm/to-vfile + +[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/to-vfile.svg + +[codecov]: https://codecov.io/github/wooorm/to-vfile + +[npm-install]: https://docs.npmjs.com/cli/install + +[license]: LICENSE + +[author]: http://wooorm.com -[MIT](LICENSE) © [Titus Wormer](http://wooorm.com) +[remark]: https://github.com/wooorm/remark diff --git a/strip-markdown.js b/strip-markdown.js deleted file mode 100644 index fbf9978..0000000 --- a/strip-markdown.js +++ /dev/null @@ -1,204 +0,0 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.stripMarkdown = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o} - */ -function children(token) { - return token.children; -} - -/** - * Return the concatenation of `token`s children. - * - * @param {Object} token - * @return {Node} - */ -function paragraph(token) { - return { - 'type': 'paragraph', - 'children': token.children - }; -} - -/** - * Return `token`s value. - * - * @param {Object} token - * @return {Node} - */ -function inline(token) { - return { - 'type': 'text', - 'value': token.value - }; -} - -/* - * Expose modifiers for available node types. - * - * Node types not listed here are not - * changed (but their children are). - */ - -var map = {}; - -map.blockquote = children; -map.list = children; -map.listItem = children; -map.strong = children; -map.emphasis = children; -map.delete = children; -map.link = children; - -map.heading = paragraph; - -map.text = inline; -map.inlineCode = inline; - -map.code = empty; -map.html = empty; -map.horizontalRule = empty; -map.table = empty; -map.tableCell = empty; - -map.image = image; - -/** - * Clean nodes: merges text's. - * - * @param {Array.} values - * @return {Array.} - */ -function clean(values) { - var index = -1; - var length = values.length; - var result = []; - var prev = null; - var value; - - while (++index < length) { - value = values[index]; - - if (prev && 'value' in value && value.type === prev.type) { - prev.value += value.value; - } else { - result.push(value); - prev = value; - } - } - - return result; -} - -/* - * Define cleaners. - */ - -var strip; -var stripAll; - -/** - * Strip markdown formatting from a node. - * - * @param {Node} node - * @return {null|Node|Array.} - */ -strip = function (node) { - var type = node && node.type; - - if (type in map) { - node = map[type](node); - } else if (typeof type !== 'string') { - exception('Invalid type: ' + type); - } - - if (node) { - if (node.length) { - node = stripAll(node); - } - - if (node.children) { - node.children = stripAll(node.children); - } - } - - return node; -}; - -/** - * Strip markdown formatting from multiple nodes. - * - * @param {Array.} nodes - * @return {Array.} - */ -stripAll = function (nodes) { - var index = -1; - var length = nodes.length; - var result = []; - var value; - - while (++index < length) { - value = strip(nodes[index]); - - if (value && value.length) { - result = result.concat(value.map(strip)); - } else if (value) { - result.push(value); - } - } - - return clean(result); -}; - -/** - * Attacher - * - * @return {function(Node)} - */ -function attacher() { - return strip; -} - -/* - * Expose `strip`. - */ - -module.exports = attacher; - -},{}]},{},[1])(1) -}); \ No newline at end of file diff --git a/strip-markdown.min.js b/strip-markdown.min.js deleted file mode 100644 index beeade8..0000000 --- a/strip-markdown.min.js +++ /dev/null @@ -1 +0,0 @@ -!function(b,a){typeof exports==='object'&&typeof module!=='undefined'?module.exports=b():typeof define==='function'&&define.amd?define([],b):(typeof window!=='undefined'?a=window:typeof global!=='undefined'?a=global:typeof self!=='undefined'?a=self:a=this,a.stripMarkdown=b())}(function(){return function a(b,c,e){function f(d,k){if(!c[d]){if(!b[d]){var i=typeof require=='function'&&require;if(!k&&i)return i(d,!0);if(g)return g(d,!0);var j=new Error("Cannot find module '"+d+"'");throw j.code='MODULE_NOT_FOUND',j}var h=c[d]={exports:{}};b[d][0].call(h.exports,function(c){var a=b[d][1][c];return f(a?a:c)},h,h.exports,a,b,c,e)}return c[d].exports}var g=typeof require=='function'&&require;for(var d=0;d Hello\n> World\n> !') === 'Hello\nWorld\n!'); - }); - - it('should strip images', function () { - assert(strip('![An image](image.png "test")') === 'An image'); - assert(strip('![](image.png "test")') === 'test'); - assert(strip('![](image.png)') === ''); - }); - - it('should ignore horizontal rules', function () { - assert(strip('Test\n\n---\n\nTest') === 'Test\n\nTest'); - }); +'use strict'; - it('should ignore tables', function () { - assert(strip('| Hello |\n| ----- |\n| World |') === ''); - }); +/* Dependencies. */ +var test = require('tape'); +var remark = require('remark'); +var strip = require('./'); - it('should ignore code', function () { - assert( - strip( - '\talert("hello");\n\n```js\nconsole.log("world");\n```' - ) === '' - ); - }); +function proc(value) { + return remark().use(strip).process(value).toString().trimRight(); +} - it('should ignore html', function () { - assert( - strip( - 'Hello\n' - ) === 'Hello' - ); - }); +/* API. */ +test('stripMarkdown()', function (t) { + t.equal(proc('Alfred'), 'Alfred', 'text'); + t.equal(proc('*Alfred*'), 'Alfred', 'emphasis (1)'); + t.equal(proc('_Alfred_'), 'Alfred', 'emphasis (2)'); + t.equal(proc('**Alfred**'), 'Alfred', 'importance (1)'); + t.equal(proc('__Alfred__'), 'Alfred', 'importance (2)'); + t.equal(proc('~~Alfred~~'), 'Alfred', 'strikethrough'); + t.equal(proc('`Alfred`'), 'Alfred', 'inline code'); + t.equal(proc('[Hello](world)'), 'Hello', 'link'); + t.equal(proc('[**H**ello](world)'), 'Hello', 'importance in link'); + t.equal(proc('Hello.\n\nWorld.'), 'Hello.\n\nWorld.', 'paragraph'); + t.equal(proc('## Alfred'), 'Alfred', 'headings (atx)'); + t.equal(proc('Alfred\n====='), 'Alfred', 'headings (setext)'); + + t.equal( + proc('- Hello\n * World\n + !'), + 'Hello\n\nWorld\n\n!', + 'list item' + ); + + t.equal( + proc('- Hello\n\n- World\n\n- !'), + 'Hello\n\nWorld\n\n!', + 'list' + ); + + t.equal( + proc('> Hello\n> World\n> !'), + 'Hello\nWorld\n!', + 'blockquote' + ); + + t.equal(proc('![An image](image.png "test")'), 'An image', 'image (1)'); + t.equal(proc('![](image.png "test")'), 'test', 'image (2)'); + t.equal(proc('![](image.png)'), '', 'image (3)'); + + t.equal(proc('---'), '', 'thematic break'); + t.equal(proc('| A | B |\n| - | - |\n| C | D |'), '', 'table'); + t.equal(proc('\talert("hello");'), '', 'code (1)'); + t.equal(proc('```js\nconsole.log("world");\n```'), '', 'code (2)'); + t.equal(proc('Hello'), 'Hello', 'html (1)'); + t.equal(proc(''), '', 'html (2)'); + + t.end(); });