From 2fe4743a1303ca5dcba4018519a044e9de8e11db Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 10 Jan 2015 17:17:09 -0800 Subject: Made 'options' a parameter of the renderer constructors... as opposed to the 'render' function. Added a 'colors' parameter for the ast renderer. --- js/lib/html.js | 7 ++++--- js/lib/index.js | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'js/lib') diff --git a/js/lib/html.js b/js/lib/html.js index 9cb1676..9f0c4e3 100644 --- a/js/lib/html.js +++ b/js/lib/html.js @@ -21,7 +21,7 @@ var tag = function(name, attrs, selfclosing) { var reHtmlTag = /\<[^>]*\>/; -var renderNodes = function(block, options) { +var renderNodes = function(block) { var attrs; var info_words; @@ -48,7 +48,7 @@ var renderNodes = function(block, options) { } }; - options = options || {}; + var options = this.options; while ((event = walker.next())) { entering = event.entering; @@ -250,7 +250,7 @@ var replaceUnsafeChar = function(s) { var reNeedsEscaping = /[&<>"]/; // The HtmlRenderer object. -function HtmlRenderer(){ +function HtmlRenderer(options){ return { // default options: softbreak: '\n', // by default, soft breaks are rendered as newlines in HTML @@ -267,6 +267,7 @@ function HtmlRenderer(){ return s; } }, + options: options || {}, render: renderNodes }; } diff --git a/js/lib/index.js b/js/lib/index.js index d0532c6..22a2184 100755 --- a/js/lib/index.js +++ b/js/lib/index.js @@ -13,11 +13,15 @@ var util = require('util'); -var renderAST = function(tree) { - return util.inspect(tree.toAST(), {depth: 20}) + '\n'; -}; - module.exports.Node = require('./node'); module.exports.DocParser = require('./blocks'); module.exports.HtmlRenderer = require('./html'); -module.exports.ASTRenderer = renderAST; +module.exports.ASTRenderer = function(options) { + return { + render: function(tree) { + return util.inspect(tree.toAST(), null, 20, + this.options.colors) + '\n'; + }, + options: options || {} + }; +} -- cgit v1.2.3