.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / postcss-html / lib / stringify.js
1 "use strict";
2 const cssSyntax = require("./css-syntax");
3
4 function stringify (document, builder) {
5         if (document.source.syntax) {
6                 return document.source.syntax.stringify(document, builder);
7         } else {
8                 const firstOriginalRoot = document.nodes.find(root => root.source && root.source.syntax);
9                 let defaultSyntax;
10                 document.nodes.forEach((root, i) => {
11                         let syntax = root.source && root.source.syntax;
12                         if (syntax) {
13                                 if (root.raws.beforeStart) {
14                                         builder(root.raws.beforeStart, root, "beforeStart");
15                                 }
16                                 defaultSyntax = syntax;
17                         } else {
18                                 if (!i && firstOriginalRoot) {
19                                         builder(firstOriginalRoot.raws.beforeStart, root, "beforeStart");
20                                         firstOriginalRoot.raws.beforeStart = "";
21                                 }
22                                 syntax = defaultSyntax || (
23                                         defaultSyntax = firstOriginalRoot
24                                                 ? firstOriginalRoot.source.syntax
25                                                 : cssSyntax({})
26                                 );
27                         }
28                         if (root.source && root.source.isHTMLAttribute) {
29                                 return syntax.stringify(root, string => {
30                                         builder.apply(
31                                                 null,
32                                                 [
33                                                         string.replace(/[\r\n\t\s]+/g, " "),
34                                                 ].concat(
35                                                         Array.from(arguments).slice(1)
36                                                 )
37                                         );
38                                 });
39                         } else {
40                                 syntax.stringify(root, builder);
41                         }
42                 });
43                 builder(document.raws.afterEnd, document, "afterEnd");
44         }
45 }
46
47 module.exports = stringify;