From f280469e77a8e6d1014e18c2c0ba717e9b15743e Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Fri, 2 Jan 2015 01:30:24 -0400 Subject: [PATCH] Fixes #169. Remove JS-Yaml and use YAML-Front-Matter, resolving conflict --- examples/simple-jsbeautifyrc/markdown/expected/test.md | 4 ---- .../markdown/expected/yaml-front-matter.md | 2 +- lib/langs/markdown-beautify.coffee | 10 +++++----- lib/options.coffee | 2 +- package.json | 1 - 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/examples/simple-jsbeautifyrc/markdown/expected/test.md b/examples/simple-jsbeautifyrc/markdown/expected/test.md index 67d30f0ff..d50ab990d 100644 --- a/examples/simple-jsbeautifyrc/markdown/expected/test.md +++ b/examples/simple-jsbeautifyrc/markdown/expected/test.md @@ -1,7 +1,3 @@ ---- -{} ---- - - item - item - item diff --git a/examples/simple-jsbeautifyrc/markdown/expected/yaml-front-matter.md b/examples/simple-jsbeautifyrc/markdown/expected/yaml-front-matter.md index 203f1be4f..066d0afcd 100644 --- a/examples/simple-jsbeautifyrc/markdown/expected/yaml-front-matter.md +++ b/examples/simple-jsbeautifyrc/markdown/expected/yaml-front-matter.md @@ -10,7 +10,7 @@ pets: - dog - bat match: ! /pattern/gmi -run: ! "function () {\n \n \n \n\n\n}" +run: ! "function () {\n \n}" --- - item diff --git a/lib/langs/markdown-beautify.coffee b/lib/langs/markdown-beautify.coffee index f5230d030..60c7675d0 100644 --- a/lib/langs/markdown-beautify.coffee +++ b/lib/langs/markdown-beautify.coffee @@ -1,7 +1,6 @@ ### Requires http: //johnmacfarlane.net/pandoc/ ### -yamlFront = null fs = null yaml = null allowUnsafeNewFunction = null @@ -26,13 +25,13 @@ getCmd = (inputPath, outputPath, options, cb) -> return cb(err) if err # Parse with YAML front Matter - yamlFront ?= require "yaml-front-matter" + yaml ?= require "yaml-front-matter" # console.log('Parse YAML Front Matter') allowUnsafeNewFunction ?= require("loophole").allowUnsafeNewFunction results = null try allowUnsafeNewFunction -> - results = yamlFront.loadFront(contents) + results = yaml.loadFront(contents) catch e return cb(e) newContents = results.__content # jshint ignore: line @@ -47,10 +46,11 @@ getCmd = (inputPath, outputPath, options, cb) -> completionCallback = (output, callback) -> # console.log('Completion callback!') try - yaml ?= require "js-yaml" # Pre-pend YAML Front Matter to top of Markdown output front = yaml.dump(results) - output = "---\n#{front}---\n\n#{output}" + # Check if there is valid `front` to prepend + if front isnt "{}\n" + output = "---\n#{front}---\n\n#{output}" # console.log('final output!', output) return callback(output) catch e diff --git a/lib/options.coffee b/lib/options.coffee index 9c36eca60..c5e1c91d7 100644 --- a/lib/options.coffee +++ b/lib/options.coffee @@ -118,7 +118,7 @@ module.exports = # console.log "Failed parsing config as JSON: " + configPath # Attempt as YAML try - yaml ?= require("js-yaml") + yaml ?= require("yaml-front-matter") externalOptions = yaml.safeLoad(contents) catch e console.log "Failed parsing config as YAML and JSON: " + configPath diff --git a/package.json b/package.json index a76659ec9..79aaa70d9 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,6 @@ "emissary": "^1.0.0", "extend": "^1.2.1", "js-beautify": "^1.5.4", - "js-yaml": "^3.0.2", "lodash": "2.4.1", "loophole": "^1.0.0", "node-dir": "^0.1.6",