0.3.1 • Published 10 years ago
article-data v0.3.1
article-data
Extract data from your markdown article
Install
npm install --save article-dataUsage
import extract from './index';
const input = `
# title
_24 july 2015_
desc

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:
textandhtml - date:
text,html,unixandmoment - image:
alt,srcandhtml
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
- get-md-title — get title from markdown article
- get-md-date — get date from markdown article
- get-md-desc — get content from markdown article
- get-md-image — get image from markdown article
- get-md-content — get content from markdown article
License
MIT © Vladimir Starkov