summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2022-11-27 14:07:25 +0000
committerMichael Williamson <mike@zwobble.org>2023-01-29 11:22:20 +0000
commit61d1492d46d58913db4607aed5b6dc9d0c88f3a9 (patch)
treee7601347fa4c7ca6017dc9f3019f90ff09e55a7c
parent2dcb4fe83b02ade598d777468724b4833dccd4ab (diff)
Remove use of util module
-rw-r--r--lib/writers/html-writer.js45
1 files changed, 22 insertions, 23 deletions
diff --git a/lib/writers/html-writer.js b/lib/writers/html-writer.js
index 16c848f..8fac711 100644
--- a/lib/writers/html-writer.js
+++ b/lib/writers/html-writer.js
@@ -1,4 +1,3 @@
-var util = require("util");
var _ = require("underscore");
exports.writer = writer;
@@ -27,9 +26,9 @@ function prettyWriter() {
var stack = [];
var start = true;
var inText = false;
-
+
var writer = simpleWriter();
-
+
function open(tagName, attributes) {
if (indentedElements[tagName]) {
indent();
@@ -41,7 +40,7 @@ function prettyWriter() {
}
start = false;
}
-
+
function close(tagName) {
if (indentedElements[tagName]) {
indentationLevel--;
@@ -50,29 +49,29 @@ function prettyWriter() {
stack.pop();
writer.close(tagName);
}
-
+
function text(value) {
startText();
var text = isInPre() ? value : value.replace("\n", "\n" + indentation);
writer.text(text);
}
-
+
function selfClosing(tagName, attributes) {
indent();
writer.selfClosing(tagName, attributes);
}
-
+
function insideIndentedElement() {
return stack.length === 0 || indentedElements[stack[stack.length - 1]];
}
-
+
function startText() {
if (!inText) {
indent();
inText = true;
}
}
-
+
function indent() {
inText = false;
if (!start && insideIndentedElement() && !isInPre()) {
@@ -82,13 +81,13 @@ function prettyWriter() {
}
}
}
-
+
function isInPre() {
return _.some(stack, function(tagName) {
return tagName === "pre";
});
}
-
+
return {
asString: writer.asString,
open: open,
@@ -101,39 +100,39 @@ function prettyWriter() {
function simpleWriter() {
var fragments = [];
-
+
function open(tagName, attributes) {
var attributeString = generateAttributeString(attributes);
- fragments.push(util.format("<%s%s>", tagName, attributeString));
+ fragments.push("<" + tagName + attributeString + ">");
}
-
+
function close(tagName) {
- fragments.push(util.format("</%s>", tagName));
+ fragments.push("</" + tagName + ">");
}
-
+
function selfClosing(tagName, attributes) {
var attributeString = generateAttributeString(attributes);
- fragments.push(util.format("<%s%s />", tagName, attributeString));
+ fragments.push("<" + tagName + attributeString + " />");
}
-
+
function generateAttributeString(attributes) {
return _.map(attributes, function(value, key) {
- return util.format(' %s="%s"', key, escapeHtmlAttribute(value));
+ return " " + key + '="' + escapeHtmlAttribute(value) + '"';
}).join("");
}
-
+
function text(value) {
fragments.push(escapeHtmlText(value));
}
-
+
function append(html) {
fragments.push(html);
}
-
+
function asString() {
return fragments.join("");
}
-
+
return {
asString: asString,
open: open,