diff options
Diffstat (limited to 'lib/documents.js')
| -rw-r--r-- | lib/documents.js | 54 |
1 files changed, 1 insertions, 53 deletions
diff --git a/lib/documents.js b/lib/documents.js index 8d9b665..a9e53e3 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -1,8 +1,7 @@ -var util = require("util"); - var q = require("q"); var styles = require("./styles"); +var HtmlGenerator = require("./html-generator").HtmlGenerator; exports.DocumentConverter = DocumentConverter; exports.Document = Document; @@ -63,49 +62,6 @@ function DocumentConverter(options) { } } -function HtmlGenerator() { - var stack = []; - var fragments = []; - - function text(value) { - fragments.push(escapeHtml(value)) - } - - function asString() { - popAll(); - return fragments.join(""); - } - - function style(style) { - popAll(); - style.forEach(function(tagName) { - push(tagName); - }); - } - - function push(element) { - stack.push(element); - fragments.push(util.format("<%s>", element)); - } - - function pop() { - var element = stack.pop(); - fragments.push(util.format("</%s>", element)); - } - - function popAll() { - while (stack.length > 0) { - pop(); - } - } - - return { - style: style, - text: text, - asString: asString - }; -} - function Document(children) { return { type: "document", @@ -134,11 +90,3 @@ function Text(value) { value: value }; } - -function escapeHtml(value) { - return value - .replace(/&/g, '&') - .replace(/"/g, '"') - .replace(/</g, '<') - .replace(/>/g, '>'); -} |
