Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updating to use yaml #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
],
"dependencies": {
"define-property": "^2.0.2",
"js-yaml": "^3.11.0",
"yaml": "^2.1.1",
"kind-of": "^6.0.2",
"section-matter": "^1.0.0",
"strip-bom-string": "^1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/sections.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const { parse } = require('yaml');
const matter = require('..');
const str = fs.readFileSync(path.join(__dirname, 'fixtures', 'sections.md'));

const file = matter(str, {
section: function(section, file) {
if (typeof section.data === 'string' && section.data.trim() !== '') {
section.data = yaml.safeLoad(section.data);
section.data = parse(section.data);
}
section.content = section.content.trim() + '\n';
}
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ function parseMatter(file, options) {
// get the raw front-matter block
file.matter = str.slice(0, closeIndex);

// fix trailing '\r' on windows
if (file.matter.endsWith('\r')) {
file.matter = file.matter.slice(0, -1);
}

const block = file.matter.replace(/^\s*#[^\n]+/gm, '').trim();
if (block === '') {
file.isEmpty = true;
Expand Down
6 changes: 3 additions & 3 deletions lib/engines.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const yaml = require('js-yaml');
const { parse, stringify } = require('yaml');

/**
* Default engines
Expand All @@ -13,8 +13,8 @@ const engines = exports = module.exports;
*/

engines.yaml = {
parse: yaml.safeLoad.bind(yaml),
stringify: yaml.safeDump.bind(yaml)
parse,
stringify
};

/**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"test": "mocha"
},
"dependencies": {
"js-yaml": "^3.13.1",
"kind-of": "^6.0.2",
"section-matter": "^1.0.0",
"strip-bom-string": "^1.0.0"
"strip-bom-string": "^1.0.0",
"yaml": "^2.1.1"
},
"devDependencies": {
"ansi-green": "^0.1.1",
Expand Down
4 changes: 2 additions & 2 deletions test/parse-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
'use strict';

var assert = require('assert');
var YAML = require('js-yaml');
var { parse } = require('yaml');
var matter = require('..');

describe('custom parser:', function() {
it('should allow a custom parser to be registered:', function() {
var actual = matter.read('./test/fixtures/lang-yaml.md', {
parser: function customParser(str, opts) {
try {
return YAML.safeLoad(str, opts);
return parse(str, opts);
} catch (err) {
throw new SyntaxError(err);
}
Expand Down