take links and images out of md before conversion to roff

master
Gregory Scheerlinck 8 years ago
parent 69ee34c48e
commit 18154e908b

@ -2,12 +2,13 @@
var remark = require('remark');
var man = require('remark-man');
var remarkUnlink = require('remark-unlink');
var Promise = require('bluebird');
var fsReadFile = Promise.promisify(require('fs').readFile);
var getArticlePath = require('../lib/util').getArticlePath;
var fsWriteFile = Promise.promisify(require('fs').writeFile);
var fsUnlink = Promise.promisify(require('fs').unlink);
var path = require('path');
var getArticlePath = require('./util').getArticlePath;
var tmpFile = path.resolve('./tmp/tmpfile');
@ -15,19 +16,17 @@ exports.convert = convert;
exports.getContents = getContents;
exports.tmpSave = tmpSave;
exports.removeTmp = removeTmp;
exports.processMd = processMd;
function convert(contents, options) {
return remark.use(man, options).process(contents);
}
function getContents(article) {
article.path = getArticlePath(article.path);
return fsReadFile(article.path, 'utf-8').then(function readArticle(contents) {
return {
path: getArticlePath(article.path),
title: article.title,
description: article.description,
contents: contents,
};
article.contents = contents;
return article;
}).catch(function failReadArticle(err) {
console.log('Can\'t read ' + article.path + '. This should never happen. Try refreshing the database?');
console.log('Error: ' + err);
@ -51,3 +50,8 @@ function removeTmp() {
console.log('Error: ', + err);
});
}
function processMd(article) {
article.contents = remark().use(remarkUnlink).process(article.contents);
return article;
}

@ -27,6 +27,10 @@ describe('methods', function() {
it('has a removeTmp function', function() {
expect(fileio.removeTmp).to.be.a('function');
});
it('has a processMd function', function() {
expect(fileio.processMd).to.be.a('function');
});
});
describe('getContents', function() {
@ -113,3 +117,15 @@ describe('removeTmp', function() {
});
});
});
describe('processMd', function() {
var article = {
contents: '[foo](http://www.bar.com)',
};
it('processes the markdown', function() {
var converted = fileio.processMd(article);
expect(converted).to.be.an('object');
expect(converted.contents).to.equal('foo\n');
});
});

Loading…
Cancel
Save