Extract data from your markdown article
JavaScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.babelrc
.editorconfig
.gitignore
.npmignore
.travis.yml
README.md
index.js
package.json
test.js

README.md

article-data

NPM version Build Status Coveralls Status Dependency Status

Extract data from your markdown article

Install

npm install --save article-data

Usage

import extract from 'article-data';

const input = `
# title

_24 july 2015_

desc

![alt](http://yo.io/)

content1

content2`;

const article = extract(input, 'D MMMM YYYY', 'en');
article.title.text;    // title
article.date.text;     // 24 july 2015
article.desc.text;     // desc
article.image.src;     // http://yo.io/
article.content.html;  // <p>desc</p>
                       // <p><img src="http://yo.io/" alt="" /></p>
                       // <p>content1</p>
                       // <p>content2</p>

API

extract(input, dateFormat, dateLocale)

Return object { title, date, desc, image, content }.

I hope that all fields have self-explanatory names. Anyway, desc and content should be explained further: desc — first paragraph without date, content input without title and date. All the fields are objects with such fields:

  • title, desc, content: text and html
  • date: text, html, unix and moment
  • image: alt, src and html

Also everything in returned object has node field, which is an AST node, see commonmark API.

input

Required
Type: String

Markdown string.

dateFormat

Required
Type: String

Momentjs format for date, e.g. D MMMM YYYY.

dateLocale

Required
Type: String

One of 83 available in momentjs locales, e.g. en or fr.

Related

License

MIT © Vladimir Starkov