Permalink
Browse files

Allow setting markdown options in config

  • Loading branch information...
1 parent 9a25916 commit 73e9f69733ce6c6f619758a045782017a650fd8b @laktek committed Sep 15, 2012
@@ -19,6 +19,10 @@ module.exports = {
skip_paths: []
},
+ parser: {
+ markdown: {}
+ },
+
publish: {
generate: true
},
@@ -3,20 +3,20 @@
* Based on Marked - https://github.com/chjj/marked
*/
var marked = require("marked");
+var _ = require("underscore");
module.exports = {
+
+ markedOptions: {},
+
supportedExtensions: [".markdown", ".md"],
parse: function(input, callback){
var self = this;
var output, err;
//set default options
- marked.setOptions({
- gfm: true,
- pedantic: false,
- sanitize: false
- });
+ marked.setOptions(self.markedOptions);
try {
output = marked.parse(input.toString());
@@ -25,6 +25,17 @@ module.exports = {
}
return callback(err, output);
+ },
+
+ setup: function(config) {
+ var self = this;
+ var default_marked_options = { gfm: true, pedantic: false, sanitize: false };
+
+ if (config.parser) {
+ self.markedOptions = _.extend(default_marked_options, config.parser.markdown);
+ } else {
+ self.markedOptions = default_marked_options;
+ }
}
};
View
@@ -21,7 +21,7 @@
, "http-accept" : ">= 0.1.1-3"
, "knox" : ">= 0.0.9"
, "less" : ">= 1.3.0"
- , "marked" : ">= 0.2.3"
+ , "marked" : ">= 0.2.5"
, "mime" : ">= 1.2.5"
, "mustache" : ">= 0.5.2"
, "sftp" : "git://github.com/laktek/node-sftp.git"
@@ -2,4 +2,12 @@ This **is** a *markdown* formatted page.
Isn't it cool?
+Here we try a code block:
+
+```ruby
+ def simple_method
+ puts "Punch is awesome"
+ end
+```
+
~~Nice~~
@@ -2,7 +2,8 @@
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head>
<title></title>
- <link rel="stylesheet" type="text/css" media="screen" href="/assets/all.css">
+ <link rel="stylesheet" type="text/css" media="screen" href="/assets/styles.css">
+<link rel="stylesheet" type="text/css" media="screen" href="/assets/syntax.css">
</head>
<body>
@@ -18,13 +19,21 @@
<p>Isn&#39;t it cool?
</p>
+<p>Here we try a code block:
+
+</p>
+<pre><code class="lang-ruby"> def simple_method
+ puts &quot;Punch is awesome&quot;
+ end</code></pre>
<p>~~Nice~~
</p>
</p>
<p>This is a global value, which is available to all pages</p>
- <script src="/assets/all.js"></script>
+ <script src="/assets/js/jquery.1.8.js"></script>
+<script src="/assets/js/site.js"></script>
+<script src="/assets/js/sample.js"></script>
</body>
</html>
@@ -1,9 +1,29 @@
var markdown_parser = require("../../lib/parsers/markdown.js");
var marked = require("marked");
+describe("setup", function() {
+
+ it("extend the marked options with the options provided in the config", function(){
+ var custom_options = { "gfm": true, "pedantic": true, "sanitize": true }
+ var config = { "parser": { "markdown": custom_options } };
+
+ markdown_parser.setup(config);
+
+ expect(markdown_parser.markedOptions).toEqual(custom_options);
+ });
+
+ it("keep the default marked options when no options are provided in the config", function(){
+ var default_options = { "gfm": true, "pedantic": false, "sanitize": false }
+
+ markdown_parser.setup({});
+
+ expect(markdown_parser.markedOptions).toEqual(default_options);
+ });
+});
+
describe("parsing given content", function() {
- it("calls the callback with the result", function() {
+ it("invoke the callback with the result", function() {
spyOn(marked, "setOptions");
spyOn(marked, "parse").andCallFake(function(input){
@@ -17,7 +37,7 @@ describe("parsing given content", function() {
});
- it("calls the callback with the result", function() {
+ it("invoke the callback with the error on an error", function() {
spyOn(marked, "setOptions");
spyOn(marked, "parse").andCallFake(function(input){

0 comments on commit 73e9f69

Please sign in to comment.