Skip to content
This repository has been archived by the owner on Mar 11, 2018. It is now read-only.

Commit

Permalink
Drop Gulp dependency, add README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanqing committed Aug 23, 2014
1 parent 7a1f26d commit d1867c7
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.DS_Store
coverage/
node_modules/
npm-debug.log
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -5,7 +5,9 @@ node_js:
- '0.11'

script:
- ./node_modules/.bin/gulp
- npm run-script lint
- npm run-script coverage

after_success:
- npm i coveralls
- cat ./coverage/lcov.info | ./node_modules/.bin/coveralls
42 changes: 42 additions & 0 deletions README.md
@@ -0,0 +1,42 @@
# Hashbrown.js [![npm Version](http://img.shields.io/npm/v/hashbrown.svg?style=flat)](https://www.npmjs.org/package/hashbrown) [![Build Status](https://img.shields.io/travis/yuanqing/hashbrown.svg?style=flat)](https://travis-ci.org/yuanqing/hashbrown) [![Coverage Status](https://img.shields.io/coveralls/yuanqing/hashbrown.svg?style=flat)](https://coveralls.io/r/yuanqing/hashbrown)

> Extract tags inlined within a Markdown string.
## Usage

Hashbrown is an experiment in embedding meta data within running text. It is similar to the concept of the [hashtag](https://support.twitter.com/articles/49309-using-hashtags-on-twitter), only that **the post-processed text is syntactically correct**. This is because the `#(` and `)` markup used to demarcate a tag is removed from the text.

```js
var str = '#( Lorem ipsum! ) Dolor #( sit ) amet!';

hashbrown(str);
/* =>
* {
* text: '<p>Lorem ipsum! Dolor sit amet!</p>\n',
* tags: ['lorem-ipsum', 'sit']
* }
*/
```

A tag is converted to [kebab-case](http://stackoverflow.com/a/12273101/348359) as follows:

1. Discard any character that isn&rsquo;t alphanumeric, whitespace, a dash, or an underscore.
2. Replace whitespace and underscore characters with a dash.

## API

### hashbrown(str)

Parses the given Markdown-formatted `str`, and returns an object containing the processed `text`, and an array of `tags`.

## Installation

Install via [npm](https://www.npmjs.org/package/hashbrown):

```bash
$ npm i --save hashbrown
```

## License

[MIT license](https://github.com/yuanqing/hashbrown/blob/master/LICENSE)
15 changes: 9 additions & 6 deletions index.js
Expand Up @@ -2,11 +2,14 @@

var marked = require('marked');

var dasherise = function(str) {
var kebabCase = function(str) {

return str.toLowerCase()
.replace(/[^\w\s-]/g, '') // remove any non-alphanumeric, whitespace, '_', or '-'
.replace(/[\s_]+/g, '-'); // replace whitespace and '_' with '-'
return str.trim()
.toLowerCase()
.replace(/[^\w\s-]/g, '')
// remove chars that are not alphanumeric, whitespace, '_', or '-'
.replace(/[\s_]+/g, '-');
// replace consecutive whitespace or '_' with a single '-'

};

Expand All @@ -16,8 +19,8 @@ var hashbrown = function(str) {

return {
text: marked(str.replace(/\#\((.+?)\)/g, function (match, tag) {
tags.push(dasherise(tag));
return tag;
tags.push(kebabCase(tag));
return tag.trim();
})),
tags: tags
};
Expand Down
21 changes: 11 additions & 10 deletions package.json
@@ -1,7 +1,7 @@
{
"name": "hashbrown",
"version": "0.0.1",
"description": "Extract embedded tags from Markdown.",
"version": "0.0.2",
"description": "Extract tags inlined within a Markdown string.",
"author": "Lim Yuan Qing",
"license": "MIT",
"repository": {
Expand All @@ -10,16 +10,17 @@
},
"devDependencies": {
"coveralls": "^2.11.1",
"gulp": "^3.8.0",
"gulp-istanbul": "^0.2.1",
"gulp-jasmine": "^0.3.0",
"gulp-jshint": "^1.8.2",
"gulp-plumber": "^0.6.4",
"gulp-rimraf": "^0.1.0",
"jshint-stylish": "^0.4.0",
"matcha": "^0.5.0"
"istanbul": "^0.3.0",
"jasmine-node": "^1.14.5",
"jshint": "^2.5.4",
"jshint-stylish": "^0.4.0"
},
"dependencies": {
"marked": "^0.3.2"
},
"scripts": {
"test": "node_modules/.bin/jasmine-node spec --verbose",
"coverage": "node_modules/.bin/istanbul cover node_modules/.bin/jasmine-node spec",
"lint": "node_modules/.bin/jshint --verbose --reporter node_modules/jshint-stylish/stylish.js ./index.js"
}
}
22 changes: 16 additions & 6 deletions spec/hashbrown.spec.js
Expand Up @@ -3,13 +3,23 @@

var hashbrown = require('..');

describe('hashbrown', function() {
describe('hashbrown(str)', function() {

it('should work', function() {
var str = 'The quick brown #(fox) jumps over the #(lazy dog)!';
expect(hashbrown(str)).toEqual({
text: '<p>The quick brown fox jumps over the lazy dog!</p>\n',
tags: ['fox', 'lazy-dog']
it('extract tags from the given `str`', function() {
expect(hashbrown('#( Lorem ipsum! ) Dolor #( sit ) amet!')).toEqual({
text: '<p>Lorem ipsum! Dolor sit amet!</p>\n',
tags: ['lorem-ipsum', 'sit']
});
expect(hashbrown('#(foo)')).toEqual({
text: '<p>foo</p>\n',
tags: ['foo']
});
});

it('doesn\'t fail when the given `str` has no tags', function() {
expect(hashbrown('foo')).toEqual({
text: '<p>foo</p>\n',
tags: []
});
});

Expand Down

0 comments on commit d1867c7

Please sign in to comment.