Skip to content

Commit

Permalink
Using baseDirectory path to resolve relative files in the context of …
Browse files Browse the repository at this point in the history
…a plugin.
  • Loading branch information
gajus committed Oct 1, 2015
1 parent 3b89641 commit dafc154
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/gitdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var Gitdown = {},
Parser = require('./parser.js'),
fs = require('fs'),
path = require('path'),
Promise = require('bluebird'),
_ = require('lodash');

Expand Down Expand Up @@ -218,6 +219,7 @@ Gitdown.read = function (input) {
};

gitdown.setConfig({
baseDirectory: process.cwd(),
headingNesting: {
enabled: true
},
Expand All @@ -243,11 +245,22 @@ Gitdown.read = function (input) {
* @return {Gitdown}
*/
Gitdown.readFile = function (fileName) {
var input = fs.readFileSync(fileName, {
var gitdown,
input;

fileName = path.resolve(__dirname, fileName);

input = fs.readFileSync(fileName, {
encoding: 'utf8'
});

return Gitdown.read(input);
gitdown = Gitdown.read(input);

gitdown.setConfig({
baseDirectory: path.dirname(fileName)
});

return gitdown;
};

/**
Expand Down

0 comments on commit dafc154

Please sign in to comment.