|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | "use strict";
|
|---|
| 2 | function stringifyNode(node, custom) {
|
|---|
| 3 | var type = node.type;
|
|---|
| 4 | var value = node.value;
|
|---|
| 5 | var buf;
|
|---|
| 6 | var customResult;
|
|---|
| 7 | if (custom && (customResult = custom(node)) !== undefined) {
|
|---|
| 8 | return customResult;
|
|---|
| 9 | } else if (type === "word" || type === "space") {
|
|---|
| 10 | return value;
|
|---|
| 11 | } else if (type === "string") {
|
|---|
| 12 | buf = node.quote || "";
|
|---|
| 13 | return buf + value + (node.unclosed ? "" : buf);
|
|---|
| 14 | } else if (type === "comment") {
|
|---|
| 15 | return "/*" + value + (node.unclosed ? "" : "*/");
|
|---|
| 16 | } else if (type === "div") {
|
|---|
| 17 | return (node.before || "") + value + (node.after || "");
|
|---|
| 18 | } else if (Array.isArray(node.nodes)) {
|
|---|
| 19 | buf = stringify(node.nodes, custom);
|
|---|
| 20 | if (type !== "function") {
|
|---|
| 21 | return buf;
|
|---|
| 22 | }
|
|---|
| 23 | return value + "(" + (node.before || "") + buf + (node.after || "") + (node.unclosed ? "" : ")");
|
|---|
| 24 | }
|
|---|
| 25 | return value;
|
|---|
| 26 | }
|
|---|
| 27 | function stringify(nodes, custom) {
|
|---|
| 28 | var result, i;
|
|---|
| 29 | if (Array.isArray(nodes)) {
|
|---|
| 30 | result = "";
|
|---|
| 31 | for(i = nodes.length - 1; ~i; i -= 1){
|
|---|
| 32 | result = stringifyNode(nodes[i], custom) + result;
|
|---|
| 33 | }
|
|---|
| 34 | return result;
|
|---|
| 35 | }
|
|---|
| 36 | return stringifyNode(nodes, custom);
|
|---|
| 37 | }
|
|---|
| 38 | module.exports = stringify;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.