.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / pretty-format / build / plugins / lib / markup.js
1 'use strict';
2
3 Object.defineProperty(exports, '__esModule', {
4   value: true
5 });
6 exports.printElementAsLeaf = exports.printElement = exports.printComment = exports.printText = exports.printChildren = exports.printProps = undefined;
7
8 var _escape_html = require('./escape_html');
9
10 var _escape_html2 = _interopRequireDefault(_escape_html);
11
12 function _interopRequireDefault(obj) {
13   return obj && obj.__esModule ? obj : {default: obj};
14 }
15
16 // Return empty string if keys is empty.
17 /**
18  * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
19  *
20  * This source code is licensed under the MIT license found in the
21  * LICENSE file in the root directory of this source tree.
22  *
23  *
24  */
25
26 const printProps = (exports.printProps = (
27   keys,
28   props,
29   config,
30   indentation,
31   depth,
32   refs,
33   printer
34 ) => {
35   const indentationNext = indentation + config.indent;
36   const colors = config.colors;
37   return keys
38     .map(key => {
39       const value = props[key];
40       let printed = printer(value, config, indentationNext, depth, refs);
41
42       if (typeof value !== 'string') {
43         if (printed.indexOf('\n') !== -1) {
44           printed =
45             config.spacingOuter +
46             indentationNext +
47             printed +
48             config.spacingOuter +
49             indentation;
50         }
51         printed = '{' + printed + '}';
52       }
53
54       return (
55         config.spacingInner +
56         indentation +
57         colors.prop.open +
58         key +
59         colors.prop.close +
60         '=' +
61         colors.value.open +
62         printed +
63         colors.value.close
64       );
65     })
66     .join('');
67 });
68
69 // Return empty string if children is empty.
70 const printChildren = (exports.printChildren = (
71   children,
72   config,
73   indentation,
74   depth,
75   refs,
76   printer
77 ) =>
78   children
79     .map(
80       child =>
81         config.spacingOuter +
82         indentation +
83         (typeof child === 'string'
84           ? printText(child, config)
85           : printer(child, config, indentation, depth, refs))
86     )
87     .join(''));
88
89 const printText = (exports.printText = (text, config) => {
90   const contentColor = config.colors.content;
91   return (
92     contentColor.open + (0, _escape_html2.default)(text) + contentColor.close
93   );
94 });
95
96 const printComment = (exports.printComment = (comment, config) => {
97   const commentColor = config.colors.comment;
98   return (
99     commentColor.open +
100     '<!--' +
101     (0, _escape_html2.default)(comment) +
102     '-->' +
103     commentColor.close
104   );
105 });
106
107 // Separate the functions to format props, children, and element,
108 // so a plugin could override a particular function, if needed.
109 // Too bad, so sad: the traditional (but unnecessary) space
110 // in a self-closing tagColor requires a second test of printedProps.
111 const printElement = (exports.printElement = (
112   type,
113   printedProps,
114   printedChildren,
115   config,
116   indentation
117 ) => {
118   const tagColor = config.colors.tag;
119   return (
120     tagColor.open +
121     '<' +
122     type +
123     (printedProps &&
124       tagColor.close +
125         printedProps +
126         config.spacingOuter +
127         indentation +
128         tagColor.open) +
129     (printedChildren
130       ? '>' +
131         tagColor.close +
132         printedChildren +
133         config.spacingOuter +
134         indentation +
135         tagColor.open +
136         '</' +
137         type
138       : (printedProps && !config.min ? '' : ' ') + '/') +
139     '>' +
140     tagColor.close
141   );
142 });
143
144 const printElementAsLeaf = (exports.printElementAsLeaf = (type, config) => {
145   const tagColor = config.colors.tag;
146   return (
147     tagColor.open +
148     '<' +
149     type +
150     tagColor.close +
151     ' …' +
152     tagColor.open +
153     ' />' +
154     tagColor.close
155   );
156 });