markdown-utils
Advanced tools
Comparing version 0.4.0 to 0.5.0
477
index.js
@@ -10,2 +10,477 @@ /*! | ||
module.exports = require('./lib/index'); | ||
var isNumber = require('is-number'); | ||
var slice = require('array-slice'); | ||
var listitem = require('list-item'); | ||
/** | ||
* Create a markdown-formatted anchor link from the given values. | ||
* | ||
* ```js | ||
* utils.anchor('embed', 'assemble/handlebars-helpers/lib/code.js', 25, 'v0.6.0'); | ||
* //=> [embed](https://github.com/assemble/handlebars-helpers/blob/v0.6.0/lib/helpers/code.js#L25) | ||
* ``` | ||
* | ||
* @name anchor | ||
* @param {String} `anchor` | ||
* @param {String} `href` | ||
* @param {String} `title` | ||
* @api public | ||
*/ | ||
exports.anchor = function anchor(text, repo, line, branch) { | ||
return '[' + text + '](' + format(repo, branch, line) + ')'; | ||
}; | ||
function format(str, branch, line) { | ||
var segs = str.split(/[\\\/]/); | ||
var repo = slice(segs, 0, 2).join('/'); | ||
var rest = slice(segs, 2).join('/'); | ||
if (isNumber(branch)) { | ||
line = branch; | ||
branch = 'master'; | ||
} | ||
var res = 'https://github.com/'; | ||
res += (repo + '/blob/' + branch + '/' + rest); | ||
res += (line ? '#L' + line : ''); | ||
return res; | ||
} | ||
/** | ||
* Create a markdown-formatted badge. | ||
* | ||
* ```js | ||
* utils.badge(alt, img_url, url); | ||
* //=> [![Build Status](https://travis-ci.org/jonschlinkert/template.svg)](https://travis-ci.org/jonschlinkert/template) | ||
* ``` | ||
* | ||
* @name badge | ||
* @param {String} `alt` | ||
* @param {String} `img_url` | ||
* @param {String} `url` | ||
* @api public | ||
*/ | ||
exports.badge = function badge(alt, img_url, url) { | ||
return exports.link(exports.image(alt, img_url), url); | ||
}; | ||
/** | ||
* Create a markdown-formatted blockquote. | ||
* | ||
* ```js | ||
* utils.blockquote('This is a blockquote'); | ||
* //=> '> This is a blockquote' | ||
* ``` | ||
* | ||
* @name blockquote | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.blockquote = function blockquote(str) { | ||
return '> ' + str; | ||
}; | ||
/** | ||
* Create a markdown-formatted `<code></code>` snippet. | ||
* | ||
* ```js | ||
* utils.code('var foo = bar;'); | ||
* //=> '`var foo = bar;`' | ||
* ``` | ||
* | ||
* @name code | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.code = function code(str) { | ||
return '`' + str + '`'; | ||
}; | ||
/** | ||
* Create markdown-formatted `<del></del>`. | ||
* | ||
* ```js | ||
* utils.del('text'); | ||
* //=> '~~text~~' | ||
* ``` | ||
* | ||
* @name del | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.del = function del(str) { | ||
return '~~' + str + '~~'; | ||
}; | ||
/** | ||
* Create a markdown-formatted em. | ||
* | ||
* ```js | ||
* utils.em('This is emphasized'); | ||
* //=> '_This is emphasized_' | ||
* ``` | ||
* | ||
* @name em | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.em = function em(str) { | ||
return '_' + str + '_'; | ||
}; | ||
/** | ||
* Create a markdown-formatted heading. | ||
* | ||
* ```js | ||
* utils.h(1, 'This is a heading'); | ||
* //=> '# This is a heading' | ||
* ``` | ||
* | ||
* @name h | ||
* @param {String} `str` | ||
* @param {Number} `level` | ||
* @api public | ||
*/ | ||
exports.h = function h(level, str) { | ||
return exports.heading(str, level); | ||
}; | ||
/** | ||
* Create a markdown-formatted h1 heading. | ||
* | ||
* ```js | ||
* utils.h1('This is a heading'); | ||
* //=> '# This is a heading' | ||
* ``` | ||
* | ||
* @name h1 | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.h1 = function h1(str) { | ||
return '# ' + str; | ||
}; | ||
/** | ||
* Create a markdown-formatted h2 heading. | ||
* | ||
* ```js | ||
* utils.h2('This is a heading'); | ||
* //=> '## This is a heading' | ||
* ``` | ||
* | ||
* @name h2 | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.h2 = function h2(str) { | ||
return '## ' + str; | ||
}; | ||
/** | ||
* Create a markdown-formatted h3 heading. | ||
* | ||
* ```js | ||
* utils.h3('This is a heading'); | ||
* //=> '### This is a heading' | ||
* ``` | ||
* | ||
* @name h3 | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.h3 = function h3(str) { | ||
return '### ' + str; | ||
}; | ||
/** | ||
* Create a markdown-formatted h4 heading. | ||
* | ||
* ```js | ||
* utils.h4('This is a heading'); | ||
* //=> '#### This is a heading' | ||
* ``` | ||
* | ||
* @name h4 | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.h4 = function h4(str) { | ||
return '#### ' + str; | ||
}; | ||
/** | ||
* Create a markdown-formatted h5 heading. | ||
* | ||
* ```js | ||
* utils.h5('This is a heading'); | ||
* //=> '##### This is a heading' | ||
* ``` | ||
* | ||
* @name h5 | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.h5 = function h5(str) { | ||
return '##### ' + str; | ||
}; | ||
/** | ||
* Create a markdown-formatted h6 heading. | ||
* | ||
* ```js | ||
* utils.h6('This is a heading'); | ||
* //=> '###### This is a heading' | ||
* ``` | ||
* | ||
* @name h6 | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.h6 = function h6(str) { | ||
return '###### ' + str; | ||
}; | ||
/** | ||
* Create a markdown-formatted heading. | ||
* | ||
* ```js | ||
* utils.heading('This is a heading', 1); | ||
* //=> '# This is a heading' | ||
* ``` | ||
* | ||
* @name heading | ||
* @param {String} `str` | ||
* @param {Number} `level` | ||
* @api public | ||
*/ | ||
exports.heading = function heading(str, level) { | ||
return exports['h' + (level || 1)](str); | ||
}; | ||
/** | ||
* Create a markdown-formatted horizontal rule. | ||
* | ||
* ```js | ||
* utils.hr(); | ||
* //=> '***' | ||
* ``` | ||
* | ||
* @name hr | ||
* @param {String} `str` Alternate string to use. Default is `***` to avoid collision with `---` which is used for front matter. | ||
* @api public | ||
*/ | ||
exports.hr = function hr(str) { | ||
return str || '***'; | ||
}; | ||
/** | ||
* Create a markdown-formatted image from the given values. | ||
* | ||
* ```js | ||
* utils.image(alt, src); | ||
* //=> ![Build Status](https://travis-ci.org/jonschlinkert/template.svg) | ||
* | ||
* utils.image(alt, src, title); | ||
* //=> ![Build Status](https://travis-ci.org/jonschlinkert/template.svg "This is title of image!") | ||
* ``` | ||
* | ||
* @name image | ||
* @param {String} `alt` | ||
* @param {String} `src` | ||
* @param {String} `title` | ||
* @api public | ||
*/ | ||
exports.image = function image(alt, src, title) { | ||
title = title ? ' "' + title + '"' : ''; | ||
return '![' + alt + '](' + src + title + ')'; | ||
}; | ||
/** | ||
* Create a markdown-formatted link from the given values. | ||
* | ||
* ```js | ||
* utils.link('fs-utils', 'https://github.com/assemble/fs-utils', 'hover title'); | ||
* //=> [fs-utils](https://github.com/assemble/fs-utils "hover title") | ||
* ``` | ||
* | ||
* @name link | ||
* @param {String} `anchor` | ||
* @param {String} `href` | ||
* @param {String} `title` | ||
* @api public | ||
*/ | ||
exports.link = function link(anchor, href, title) { | ||
title = title ? ' "' + title + '"' : ''; | ||
return '[' + anchor + '](' + href + title + ')'; | ||
}; | ||
/** | ||
* Pass an array of list-item objects to generate a formatted list | ||
* or table of contents. Uses [list-item] for generating the actual | ||
* items. | ||
* | ||
* | ||
* ```js | ||
* var list = [ | ||
* {text: 'This is item 1', lvl: 0}, | ||
* {text: 'This is item 2', lvl: 0}, | ||
* {text: 'This is item 3', lvl: 0}, | ||
* {text: 'This is sub-item A', lvl: 2}, | ||
* {text: 'This is sub-item B', lvl: 2}, | ||
* {text: 'This is sub-item C', lvl: 2}, | ||
* ]; | ||
* list([{text: 'This is a list item', lvl: 0}]); | ||
* | ||
* // Results in | ||
* // '- This is item 1' | ||
* // '- This is item 2' | ||
* // '- This is item 3' | ||
* // ' * This is sub-item A' | ||
* // ' * This is sub-item B' | ||
* // ' * This is sub-item C' | ||
* ``` | ||
* | ||
* @name .list | ||
* @param {Array} `list` Array of item objects with `text` and `lvl` properties | ||
* @property {String} `text` [list] The text for the list item. | ||
* @property {Number} `lvl` [list] The level of the list item to be used for indenting the list. | ||
* @param {Object} `opts` Options to pass to [list-item]. | ||
* @param {Function} `fn` pass a function [expand-range] to modify the bullet for an item as it's generated. | ||
* @api public | ||
*/ | ||
exports.list = require('bullets'); | ||
/** | ||
* Returns a function to generate a plain-text/markdown list-item, | ||
* allowing options to be cached for subsequent calls. | ||
* | ||
* ```js | ||
* var li = listitem(options); | ||
* | ||
* li(0, 'Level 0 list item'); | ||
* //=> '- Level 0 list item' | ||
* | ||
* li(1, 'Level 1 list item'); | ||
* //=> ' * Level 1 list item' | ||
* | ||
* li(2, 'Level 2 list item'); | ||
* //=> ' + Level 2 list item' | ||
* ``` | ||
* | ||
* @name .li | ||
* @param {String} `options` | ||
* @option {Boolean} [options] `nobullet` Pass true if you only want the list iten and identation, but no bullets. | ||
* @option {String} [options] `indent` The amount of leading indentation to use. default is ` `. | ||
* @option {String|Array} [options] `chars` If a string is passed, [expand-range] will be used to generate an array of bullets (visit [expand-range] to see all options.) Or directly pass an array of bullets, numbers, letters or other characters to use for each list item. Default `['-', '*', '+', '~']` | ||
* @param {Function} `fn` pass a function [expand-range] to modify the bullet for an item as it's generated. See the [examples]. | ||
* @api public | ||
*/ | ||
exports.li = function li(str, lvl, opts, fn) { | ||
return listitem(opts, fn)(lvl, str); | ||
}; | ||
/** | ||
* Create a markdown-formatted `<pre><code></code></pre>` snippet with or without lang. | ||
* | ||
* ```js | ||
* utils.pre('var foo = bar;'); | ||
* ``` | ||
* Results in: | ||
* | ||
* <pre> | ||
* ```js | ||
* var foo = bar; | ||
* ``` | ||
* </pre> | ||
* | ||
* @name pre | ||
* @param {String} `str` | ||
* @param {String} `language` | ||
* @api public | ||
*/ | ||
exports.pre = function pre(str, language) { | ||
var code = '```' + language; | ||
code += '\n'; | ||
code += str; | ||
code += '\n'; | ||
code += '```'; | ||
return code; | ||
}; | ||
/** | ||
* Create a markdown-formatted reference link from the given values. | ||
* | ||
* ```js | ||
* utils.reference('template', 'https://github/jonschlinkert/template', 'Make stuff!'); | ||
* //=> [template]: https://github/jonschlinkert/template "Make stuff!" | ||
* ``` | ||
* | ||
* @name reference | ||
* @param {String} `id` | ||
* @param {String} `url` | ||
* @param {String} `title` | ||
* @api public | ||
*/ | ||
exports.reference = function reference(id, url, title) { | ||
title = title ? ' "' + title + '"' : ''; | ||
return '[' + id + ']: ' + url + title; | ||
}; | ||
/** | ||
* Create markdown-formatted bold text. | ||
* | ||
* ```js | ||
* utils.strong('This is bold'); | ||
* //=> '**This is bold**' | ||
* ``` | ||
* | ||
* @name strong | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.strong = function strong(str) { | ||
return '**' + str + '**'; | ||
}; | ||
/** | ||
* Create a markdown-formatted todo item. | ||
* | ||
* ```js | ||
* utils.todo('this is a todo.'); | ||
* //=> '- [ ] this is a todo' | ||
* | ||
* utils.todo('this is a completed todo.', true); | ||
* //=> '- [x] this is a todo' | ||
* ``` | ||
* | ||
* @name todo | ||
* @param {String} `str` | ||
* @api public | ||
*/ | ||
exports.todo = function todo(str, checked) { | ||
return (checked ? '- [x] ' : '- [ ] ') + str; | ||
}; | ||
{ | ||
"name": "markdown-utils", | ||
"description": "Micro-utils for creating markdown snippets.", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"homepage": "https://github.com/jonschlinkert/markdown-utils", | ||
@@ -10,7 +10,13 @@ "author": { | ||
}, | ||
"repository": "jonschlinkert/markdown-utils", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/jonschlinkert/markdown-utils.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jonschlinkert/markdown-utils/issues" | ||
}, | ||
"license": "MIT", | ||
"license": { | ||
"type": "MIT", | ||
"url": "https://github.com/jonschlinkert/markdown-utils/blob/master/LICENSE" | ||
}, | ||
"files": [ | ||
@@ -30,3 +36,2 @@ "index.js", | ||
"bullets": "^0.1.1", | ||
"export-files": "^1.1.0", | ||
"is-number": "^1.1.0", | ||
@@ -33,0 +38,0 @@ "list-item": "^0.1.2" |
@@ -1,9 +0,5 @@ | ||
# markdown-utils [![NPM version](https://badge.fury.io/js/markdown-utils.svg)](http://badge.fury.io/js/markdown-utils) | ||
# markdown-utils [![NPM version](https://badge.fury.io/js/markdown-utils.svg)](http://badge.fury.io/js/markdown-utils) [![Build Status](https://travis-ci.org/jonschlinkert/markdown-utils.svg)](https://travis-ci.org/jonschlinkert/markdown-utils) | ||
> Micro-utils for creating markdown snippets. | ||
## Related | ||
* [remarkable](https://github.com/jonschlinkert/remarkable): Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in one. | ||
* [markdown-toc](https://github.com/jonschlinkert/markdown-toc): Generate a markdown TOC (table of contents) with Remarkable. | ||
## Install with [npm](npmjs.org) | ||
@@ -15,3 +11,16 @@ | ||
## Table of Contents | ||
<!-- toc --> | ||
- [Usage](#usage) | ||
- [API](#api) | ||
- [Related](#related) | ||
- [Running tests](#running-tests) | ||
- [Contributing](#contributing) | ||
- [Author](#author) | ||
- [License](#license) | ||
<!-- tocstop --> | ||
## Usage | ||
@@ -24,3 +33,3 @@ | ||
## API | ||
### [.anchor](./lib/anchor.js#L21) | ||
### [.anchor](./index.js#L29) | ||
@@ -38,3 +47,3 @@ Create a markdown-formatted anchor link from the given values. | ||
### [.badge](./lib/badge.js#L21) | ||
### [.badge](./index.js#L62) | ||
@@ -52,3 +61,3 @@ Create a markdown-formatted badge. | ||
### [.blockquote](./lib/blockquote.js#L16) | ||
### [.blockquote](./index.js#L79) | ||
@@ -64,3 +73,3 @@ Create a markdown-formatted blockquote. | ||
### [.code](./lib/code.js#L16) | ||
### [.code](./index.js#L96) | ||
@@ -76,3 +85,3 @@ Create a markdown-formatted `<code></code>` snippet. | ||
### [.del](./lib/del.js#L16) | ||
### [.del](./index.js#L113) | ||
@@ -88,3 +97,3 @@ Create markdown-formatted `<del></del>`. | ||
### [.em](./lib/em.js#L16) | ||
### [.em](./index.js#L130) | ||
@@ -100,4 +109,16 @@ Create a markdown-formatted em. | ||
### [.h1](./lib/h1.js#L16) | ||
### [.h](./index.js#L148) | ||
Create a markdown-formatted heading. | ||
* `str` **{String}** | ||
* `level` **{Number}** | ||
```js | ||
utils.h(1, 'This is a heading'); | ||
//=> '# This is a heading' | ||
``` | ||
### [.h1](./index.js#L165) | ||
Create a markdown-formatted h1 heading. | ||
@@ -112,3 +133,3 @@ | ||
### [.h2](./lib/h2.js#L16) | ||
### [.h2](./index.js#L182) | ||
@@ -124,3 +145,3 @@ Create a markdown-formatted h2 heading. | ||
### [.h3](./lib/h3.js#L16) | ||
### [.h3](./index.js#L199) | ||
@@ -136,3 +157,3 @@ Create a markdown-formatted h3 heading. | ||
### [.h4](./lib/h4.js#L16) | ||
### [.h4](./index.js#L216) | ||
@@ -148,3 +169,3 @@ Create a markdown-formatted h4 heading. | ||
### [.h5](./lib/h5.js#L16) | ||
### [.h5](./index.js#L233) | ||
@@ -160,3 +181,3 @@ Create a markdown-formatted h5 heading. | ||
### [.h6](./lib/h6.js#L16) | ||
### [.h6](./index.js#L250) | ||
@@ -172,3 +193,3 @@ Create a markdown-formatted h6 heading. | ||
### [.heading](./lib/heading.js#L17) | ||
### [.heading](./index.js#L268) | ||
@@ -185,3 +206,3 @@ Create a markdown-formatted heading. | ||
### [.hr](./lib/hr.js#L16) | ||
### [.hr](./index.js#L285) | ||
@@ -197,3 +218,3 @@ Create a markdown-formatted horizontal rule. | ||
### [.image](./lib/image.js#L21) | ||
### [.image](./index.js#L307) | ||
@@ -214,5 +235,4 @@ Create a markdown-formatted image from the given values. | ||
### [.link](./index.js#L327) | ||
### [.link](./lib/link.js#L18) | ||
Create a markdown-formatted link from the given values. | ||
@@ -229,3 +249,3 @@ | ||
### [list](https://github.com/jonschlinkert/bullets/blob/master/index.js#L55) | ||
### [.list](./index.js#L368) | ||
@@ -247,3 +267,3 @@ Pass an array of list-item objects to generate a formatted list or table of contents. Uses [list-item] for generating the actual items. | ||
]; | ||
bullets([{text: 'This is a list item', lvl: 0}]); | ||
list([{text: 'This is a list item', lvl: 0}]); | ||
@@ -259,3 +279,3 @@ // Results in | ||
### [listitem](https://github.com/jonschlinkert/list-item/blob/master/index.js#L45) | ||
### [.li](./index.js#L396) | ||
@@ -284,3 +304,3 @@ Returns a function to generate a plain-text/markdown list-item, allowing options to be cached for subsequent calls. | ||
### [.pre](./lib/pre.js#L23) | ||
### [.pre](./index.js#L420) | ||
@@ -304,4 +324,5 @@ Create a markdown-formatted `<pre><code></code></pre>` snippet with or without lang. | ||
</pre> | ||
### [.reference](./lib/reference.js#L18) | ||
### [.reference](./index.js#L444) | ||
Create a markdown-formatted reference link from the given values. | ||
@@ -318,3 +339,3 @@ | ||
### [.strong](./lib/strong.js#L16) | ||
### [.strong](./index.js#L462) | ||
@@ -330,3 +351,3 @@ Create markdown-formatted bold text. | ||
### [.todo](./lib/todo.js#L19) | ||
### [.todo](./index.js#L482) | ||
@@ -346,2 +367,6 @@ Create a markdown-formatted todo item. | ||
## Related | ||
* [remarkable](https://github.com/jonschlinkert/remarkable): Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in one. | ||
* [markdown-toc](https://github.com/jonschlinkert/markdown-toc): Generate a markdown TOC (table of contents) with Remarkable. | ||
## Running tests | ||
@@ -354,3 +379,2 @@ Install dev dependencies. | ||
## Contributing | ||
@@ -372,2 +396,2 @@ Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/markdown-utils/issues) | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 01, 2015._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on March 13, 2015._ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
20509
4
434
370
0
4
1
- Removedexport-files@^1.1.0
- Removedarr-diff@2.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarr-map@1.0.0(transitive)
- Removedarray-unique@0.2.1(transitive)
- Removedbraces@1.8.5(transitive)
- Removedexpand-brackets@0.1.5(transitive)
- Removedexport-files@1.3.0(transitive)
- Removedextend-shallow@1.1.4(transitive)
- Removedextglob@0.3.2(transitive)
- Removedfilename-regex@2.0.1(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfor-own@0.1.5(transitive)
- Removedglob-base@0.3.0(transitive)
- Removedglob-parent@2.0.0(transitive)
- Removedis-dotfile@1.0.3(transitive)
- Removedis-equal-shallow@0.1.3(transitive)
- Removedis-extendable@0.1.1(transitive)
- Removedis-extglob@1.0.0(transitive)
- Removedis-glob@1.1.32.0.1(transitive)
- Removedis-posix-bracket@0.1.1(transitive)
- Removedis-primitive@2.0.0(transitive)
- Removedkind-of@1.1.0(transitive)
- Removedmicromatch@2.3.11(transitive)
- Removednormalize-path@2.1.1(transitive)
- Removedobject.omit@2.0.1(transitive)
- Removedparse-glob@3.0.4(transitive)
- Removedpreserve@0.2.0(transitive)
- Removedregex-cache@0.4.4(transitive)
- Removedremove-trailing-separator@1.1.0(transitive)