Skip to content

Commit

Permalink
fix($parser): fix jonschlinkert#92
Browse files Browse the repository at this point in the history
  • Loading branch information
fimars committed Mar 8, 2019
1 parent 8a22958 commit c7871db
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,8 @@ function parseMatter(file, options) {
file.empty = file.content;
file.data = {};
} else {

// create file.data by parsing the raw file.matter block
file.data = parse(file.language, file.matter, opts);
file.data = parse(file.language, file.matter.trim(), opts);
}

// update file.content
Expand Down
14 changes: 14 additions & 0 deletions test/matter-windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require('mocha');
var assert = require('assert');
var utils = require('../lib/utils');
var matter = require('..');
var toml = require('toml');

describe('gray-matter (windows carriage returns)', function() {
it('should extract YAML front matter', function() {
Expand Down Expand Up @@ -84,4 +85,17 @@ describe('gray-matter (windows carriage returns)', function() {
assert.equal(actual.content, '-----------name--------------value\r\nfoo');
assert.equal(String(actual.orig), '-----------name--------------value\r\nfoo');
});

it('should parse toml front matter.', function() {
var actual = matter('---toml\r\ntitle = "TOML"\r\ndescription = "Front matter"\r\ncategories = "front matter toml"\r\n---\r\n\r\n# This file has toml front matter!\r\n', {
engines: {
toml: toml.parse.bind(toml)
}
});
console.log(actual);
assert.equal(actual.data.title, 'TOML');
assert(actual.hasOwnProperty('data'));
assert(actual.hasOwnProperty('content'));
assert(actual.hasOwnProperty('orig'));
});
});

0 comments on commit c7871db

Please sign in to comment.