tidy-markdown
Advanced tools
Comparing version 0.0.0 to 0.1.0
@@ -1,2 +0,2 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
// Generated by CoffeeScript 1.8.0 | ||
(function() { | ||
@@ -194,3 +194,3 @@ var CODE_REGEX, Entities, IMG_REGEX, LINK_REGEX, delimitCode, fixHeaders, htmlEntities, indent, longestStringInArray, marked, nestContainingTokens, nestingEndTokens, nestingStartTokens, pad, preprocessAST, prettyInlineMarkdown, | ||
* The algorithim assumes that relations between nearby headers are correct and | ||
* The algorithm assumes that relations between nearby headers are correct and | ||
* will try to preserve them. For example, "h1, h3, h3" becomes "h1, h2, h2" | ||
@@ -231,3 +231,3 @@ * rather than "h1, h2, h3". | ||
module.exports = function(dirtyMarkdown) { | ||
var alignment, ast, col, colWidth, i, id, j, link, links, openLooseItem, optionalTitle, out, previousToken, row, token, _i, _j, _k, _l, _len, _len1, _m, _ref, _ref1, _ref2, _ref3, _ref4, _ref5; | ||
var alignment, ast, col, colWidth, i, id, j, line, link, links, openLooseItem, optionalTitle, out, previousToken, row, token, _i, _j, _k, _l, _len, _len1, _len2, _len3, _m, _n, _o, _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7; | ||
ast = marked.lexer(dirtyMarkdown); | ||
@@ -297,2 +297,3 @@ links = ast.links; | ||
for (j = _k = 0, _ref3 = token.cells.length; 0 <= _ref3 ? _k < _ref3 : _k > _ref3; j = 0 <= _ref3 ? ++_k : --_k) { | ||
token.cells[j][i] = token.cells[j][i].trim(); | ||
col.push(token.cells[j][i]); | ||
@@ -319,9 +320,36 @@ } | ||
} | ||
out.push(token.header.join(' | ')); | ||
out.push(token.align.join(' | ')); | ||
_ref5 = token.cells; | ||
for (_m = 0, _len1 = _ref5.length; _m < _len1; _m++) { | ||
row = _ref5[_m]; | ||
out.push(row.join(' | ').trimRight()); | ||
if (token.header.length > 1) { | ||
out.push(token.header.join(' | ').trimRight()); | ||
out.push(token.align.join(' | ')); | ||
_ref5 = token.cells; | ||
for (_m = 0, _len1 = _ref5.length; _m < _len1; _m++) { | ||
row = _ref5[_m]; | ||
out.push(row.join(' | ').trimRight()); | ||
} | ||
} else { | ||
out.push('| ' + token.header[0].trimRight()); | ||
out.push('| ' + token.align[0]); | ||
_ref6 = token.cells; | ||
for (_n = 0, _len2 = _ref6.length; _n < _len2; _n++) { | ||
row = _ref6[_n]; | ||
out.push('| ' + row[0].trimRight()); | ||
} | ||
} | ||
out.push(''); | ||
break; | ||
case 'hr': | ||
if (previousToken != null) { | ||
out.push(''); | ||
} | ||
out.push(token.indent + stringRepeat('-', 80), ''); | ||
break; | ||
case 'html': | ||
_ref7 = token.text.split('\n'); | ||
for (_o = 0, _len3 = _ref7.length; _o < _len3; _o++) { | ||
line = _ref7[_o]; | ||
out.push(line); | ||
} | ||
break; | ||
default: | ||
throw new Error("Unknown Token: " + token.type); | ||
} | ||
@@ -338,2 +366,3 @@ previousToken = token; | ||
} | ||
out.push(''); | ||
out = out.filter(function(val, i, arr) { | ||
@@ -340,0 +369,0 @@ return !(val === '' && arr[i - 1] === ''); |
{ | ||
"name": "tidy-markdown", | ||
"description": "fix ugly markdown.", | ||
"version": "0.0.0", | ||
"version": "0.1.0", | ||
"author": "Sean Lang", | ||
"bin": { | ||
"tidy-markdown": "./bin/index.js" | ||
}, | ||
"dependencies": { | ||
@@ -26,2 +29,3 @@ "html-entities": "^1.0.10", | ||
"main": "lib", | ||
"repository": "git://github.com/slang800/tidy-markdown.git", | ||
"scripts": { | ||
@@ -28,0 +32,0 @@ "test": "mocha" |
# Tidy Markdown | ||
[![Build Status](http://img.shields.io/travis/slang800/tidy-markdown.svg?style=flat-square)](https://travis-ci.org/slang800/tidy-markdown) | ||
[![NPM version](http://img.shields.io/npm/v/tidy-markdown.svg?style=flat-square)](https://www.npmjs.org/package/tidy-markdown) | ||
[![NPM license](http://img.shields.io/npm/l/tidy-markdown.svg?style=flat-square)](https://www.npmjs.org/package/tidy-markdown) | ||
[![Build Status](http://img.shields.io/travis/slang800/tidy-markdown.svg?style=flat-square)](https://travis-ci.org/slang800/tidy-markdown) [![NPM version](http://img.shields.io/npm/v/tidy-markdown.svg?style=flat-square)](https://www.npmjs.org/package/tidy-markdown) [![NPM license](http://img.shields.io/npm/l/tidy-markdown.svg?style=flat-square)](https://www.npmjs.org/package/tidy-markdown) | ||
Beautify Markdown, fixing formatting mistakes and converting basic HTML & Unicode into their Markdown equilivants. Based on the conventions in [Carrot Creative's Markdown Styleguide](https://github.com/carrot/markdown-styleguide) and built on [Marked](https://github.com/chjj/marked). | ||
Beautify Markdown, fixing formatting mistakes and converting basic HTML & Unicode into their Markdown equivalents. Based on the conventions in [Carrot Creative's Markdown Styleguide](https://github.com/carrot/markdown-styleguide) and built on [Marked](https://github.com/chjj/marked). | ||
## Install | ||
Tidy Markdown is an [npm](npmjs.org) package, so it can be installed like this: | ||
```bash | ||
npm install tidy-markdown -g | ||
``` | ||
## CLI | ||
Tidy Markdown includes a simple CLI. It (currently) takes no arguments and operates entirely over STDIN/STDOUT. For example: | ||
```bash | ||
$ echo "# a header #" | tidy-markdown | ||
# a header | ||
``` | ||
Or using a file: | ||
```bash | ||
$ tidy-markdown < ./ugly-markdown | ||
# Some markdown | ||
Lorem ipsum dolor adipiscing | ||
- one | ||
- two | ||
- three | ||
``` | ||
And, of course, we can output to a file too: | ||
```bash | ||
$ tidy-markdown < ./ugly-markdown > ./clean-markdown | ||
``` | ||
## API | ||
Tidy Markdown only exports one function, that takes one argument (the string of ugly markdown). Here's an example of how it can be used: | ||
```coffee | ||
tidyMarkdown = require 'tidy-markdown' | ||
uglyMarkdown = ''' | ||
# Some markdown # | ||
Lorem ipsum dolor adipiscing | ||
- one | ||
* two | ||
+ three | ||
''' | ||
cleanMarkdown = tidyMarkdown(uglyMarkdown) | ||
console.log cleanMarkdown | ||
``` | ||
which outputs: | ||
```markdown | ||
# Some markdown | ||
Lorem ipsum dolor adipiscing | ||
- one | ||
- two | ||
- three | ||
``` | ||
## Features | ||
- standardize syntatical elements to use a single way of being written (for example, all unordered lists are formatted to start with hyphens, rather than allowing asterisks and/or addition signs to be mixed in). | ||
- standardize syntactical elements to use a single way of being written (for example, all unordered lists are formatted to start with hyphens, rather than allowing asterisks and/or addition signs to be mixed in). | ||
- fix numbering - making ordered lists count naturally from 1 to _n_ and reference links do the same (based on first occurance). | ||
- make headers move from h1 to smaller without gaps (like an `h1` followed by an `h4` would be corrected to an `h1` followed by an `h2`). | ||
- decode Unicode characters that have markdown equilivants (like "…" becomes "..." and "—" becomes "--"). | ||
- decode Unicode characters that have markdown equivalents (like a horizontal ellipsis becomes "..." and an em-dash becomes "--"). | ||
- move long or repeated links into the reference links section. |
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
51304
7
357
75