prettify-markdown
Advanced tools
+57
| # prettify-markdown [](http://badge.fury.io/js/prettify-markdown) | ||
| > Prettify, format or beautify your markdown. Whatever you want to call it, this does that. Used on hundreds of projects by verb. | ||
| ## Install with [npm](npmjs.org) | ||
| ```bash | ||
| npm i prettify-markdown --save | ||
| ``` | ||
| Currently this does very basic, naive formatting focusing on headings and whitespace control. | ||
| This was just externalized from [verb], where this case was used on hundreds of projects to format API documentation. As basic as it is, this has gotten the job done pretty consistently. | ||
| ## Usage | ||
| ```js | ||
| var prettify = require('prettify-markdown'); | ||
| ``` | ||
| ## Related projects | ||
| * [markdown-toc](https://github.com/jonschlinkert/markdown-toc): Generate a markdown TOC (table of contents) with Remarkable. | ||
| * [remarkable](https://github.com/jonschlinkert/remarkable): Markdown parser, done right. 100% Commonmark support, extensions, syntax plugins, high speed - all in… [more](https://github.com/jonschlinkert/remarkable) | ||
| ## Running tests | ||
| Install dev dependencies: | ||
| ```bash | ||
| npm i -d && npm test | ||
| ``` | ||
| ## Contributing | ||
| Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/prettify-markdown/issues) | ||
| ## Author | ||
| **Jon Schlinkert** | ||
| + [github/jonschlinkert](https://github.com/jonschlinkert) | ||
| + [twitter/jonschlinkert](http://twitter.com/jonschlinkert) | ||
| ## License | ||
| Copyright (c) 2015 Jon Schlinkert | ||
| Released under the MIT license. | ||
| *** | ||
| _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on April 26, 2015._ | ||
| <!-- reflinks generated by verb-reflinks plugin --> | ||
| [assemble]: http://assemble.io | ||
| [template]: https://github.com/jonschlinkert/template | ||
| [verb]: https://github.com/assemble/verb |
+43
-2
@@ -16,5 +16,11 @@ /*! | ||
| } | ||
| var obj = removeBlocks(str); | ||
| str = obj.str; | ||
| str = str.split(/(?:\r\n|\n){3,}/).join('\n\n'); | ||
| str = headings(str); | ||
| str = bolded(str); | ||
| str = addBlocks(str, obj); | ||
| return str.trim(); | ||
@@ -24,3 +30,3 @@ }; | ||
| function headings(str) { | ||
| var re = /^(#{1,6})\s+([^\n]+)\s+/g; | ||
| var re = /^(#{1,6})\s+([^\n]+)\s+/gm; | ||
| return str.replace(re, function (match, $1, $2) { | ||
@@ -32,3 +38,3 @@ return $1 + ' ' + $2 + '\n\n'; | ||
| function bolded(str) { | ||
| var re = /^\s*\*\*([^\n]+)\*\*(?=\n)\s+/g; | ||
| var re = /^\s*\*\*([^\n]+)\*\*(?=\n)\s+/gm; | ||
| return str.replace(re, function (match, $1) { | ||
@@ -38,1 +44,36 @@ return '\n**' + $1 + '**\n\n'; | ||
| } | ||
| function removeBlocks(str) { | ||
| var codeBlocks = gfm(str); | ||
| var len = codeBlocks.length; | ||
| var stash = {}, i = 0; | ||
| if (len > 0) { | ||
| while (len--) { | ||
| var key = '__BLOCK' + (i) + '__'; | ||
| var cur = codeBlocks[i++]; | ||
| stash[key] = cur; | ||
| str = str.split(cur.block).join(key); | ||
| } | ||
| } | ||
| return {str: str, stash: stash}; | ||
| } | ||
| function addBlocks(str, obj) { | ||
| var stash = obj.stash; | ||
| for (var key in stash) { | ||
| var val = stash[key]; | ||
| if (stash.hasOwnProperty(key)) { | ||
| var re = new RegExp('\\s+' + key + '\\s+'); | ||
| var block = '\n\n'; | ||
| block += '```' + val.lang + '\n'; | ||
| block += val.code + '\n'; | ||
| block += '```\n\n'; | ||
| str = str.split(re).join(block); | ||
| } | ||
| } | ||
| return str; | ||
| } |
+2
-2
| { | ||
| "name": "prettify-markdown", | ||
| "description": "Prettify, format or beautify your markdown. Whatever you want to call it, this does that. Used on hundreds of projects by verb.", | ||
| "version": "0.1.0", | ||
| "version": "0.1.1", | ||
| "homepage": "https://github.com/jonschlinkert/prettify-markdown", | ||
@@ -50,2 +50,2 @@ "author": { | ||
| } | ||
| } | ||
| } |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
5641
87.53%4
33.33%61
110.34%1
-50%57
Infinity%