prettier-plugin-astro 0.0.7 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/README.md +4 -2
- package/dist/index.js +867 -0
- package/dist/index.js.map +1 -0
- package/package.json +30 -12
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -10
- package/.eslintrc +0 -9
- package/.github/CODEOWNERS +0 -1
- package/.github/ISSUE_TEMPLATE/---01-bug-report.yml +0 -31
- package/.github/ISSUE_TEMPLATE/---02-feature-request.yml +0 -50
- package/.github/ISSUE_TEMPLATE/---03-documentation.md +0 -7
- package/.github/ISSUE_TEMPLATE/config.yml +0 -8
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -15
- package/.github/workflows/ci.yml +0 -26
- package/.github/workflows/format.yml +0 -29
- package/.github/workflows/release.yml +0 -52
- package/.gitpod.yml +0 -9
- package/.prettierignore +0 -1
- package/.prettierrc.json +0 -7
- package/jsconfig.json +0 -3
- package/src/index.d.ts +0 -9
- package/src/index.js +0 -38
- package/src/options.js +0 -24
- package/src/parse.js +0 -8
- package/src/printer.js +0 -442
- package/src/utils.js +0 -558
- package/test/astro-prettier.test.mjs +0 -123
- package/test/fixtures/in/attribute-with-embedded-expr.astro +0 -6
- package/test/fixtures/in/basic.astro +0 -13
- package/test/fixtures/in/converts-to-shorthand.astro +0 -5
- package/test/fixtures/in/doctype-with-embedded-expr.astro +0 -26
- package/test/fixtures/in/doctype-with-extra-attributes.astro +0 -26
- package/test/fixtures/in/embedded-expr.astro +0 -26
- package/test/fixtures/in/embedded-in-markdown.md +0 -332
- package/test/fixtures/in/expr-and-html-comment.astro +0 -20
- package/test/fixtures/in/frontmatter.astro +0 -18
- package/test/fixtures/in/html-comment.astro +0 -5
- package/test/fixtures/in/maximum-call-stack-size-exceeded.astro +0 -1
- package/test/fixtures/in/preserve-tag-case.astro +0 -5
- package/test/fixtures/in/single-style-element.astro +0 -9
- package/test/fixtures/in/unclosed-tag.astro +0 -42
- package/test/fixtures/in/with-codespans.astro +0 -19
- package/test/fixtures/in/with-indented-sass.astro +0 -20
- package/test/fixtures/in/with-script.astro +0 -5
- package/test/fixtures/in/with-scss.astro +0 -24
- package/test/fixtures/in/with-styles.astro +0 -21
- package/test/fixtures/out/attribute-with-embedded-expr.astro +0 -6
- package/test/fixtures/out/basic.astro +0 -12
- package/test/fixtures/out/converts-to-shorthand.astro +0 -6
- package/test/fixtures/out/doctype-with-embedded-expr.astro +0 -23
- package/test/fixtures/out/doctype-with-extra-attributes.astro +0 -23
- package/test/fixtures/out/embedded-expr.astro +0 -22
- package/test/fixtures/out/embedded-in-markdown.md +0 -336
- package/test/fixtures/out/expr-and-html-comment.astro +0 -5
- package/test/fixtures/out/frontmatter.astro +0 -16
- package/test/fixtures/out/html-comment.astro +0 -5
- package/test/fixtures/out/maximum-call-stack-size-exceeded.astro +0 -2
- package/test/fixtures/out/preserve-tag-case.astro +0 -5
- package/test/fixtures/out/single-style-element.astro +0 -9
- package/test/fixtures/out/unclosed-tag.astro +0 -34
- package/test/fixtures/out/with-codespans.astro +0 -17
- package/test/fixtures/out/with-indented-sass.astro +0 -17
- package/test/fixtures/out/with-script.astro +0 -5
- package/test/fixtures/out/with-scss.astro +0 -21
- package/test/fixtures/out/with-styles.astro +0 -18
- package/test/package.json +0 -3
- package/test/test-utils.mjs +0 -35
package/dist/index.js
ADDED
|
@@ -0,0 +1,867 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var parser = require('@astrojs/parser');
|
|
6
|
+
var _doc = require('prettier/doc');
|
|
7
|
+
var sassFormatter = require('sass-formatter');
|
|
8
|
+
var prettier = require('prettier');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var _doc__default = /*#__PURE__*/_interopDefaultLegacy(_doc);
|
|
13
|
+
|
|
14
|
+
const parse = (text) => parser.parse(text);
|
|
15
|
+
|
|
16
|
+
const options = {
|
|
17
|
+
astroSortOrder: {
|
|
18
|
+
since: '0.0.1',
|
|
19
|
+
category: 'Astro',
|
|
20
|
+
type: 'choice',
|
|
21
|
+
default: 'markup | styles',
|
|
22
|
+
description: 'Sort order for markup, scripts, and styles',
|
|
23
|
+
choices: [
|
|
24
|
+
{
|
|
25
|
+
value: 'markup | styles',
|
|
26
|
+
description: 'markup | styles',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
value: 'styles | markup',
|
|
30
|
+
description: 'styles | markup',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
astroAllowShorthand: {
|
|
35
|
+
since: '0.0.10',
|
|
36
|
+
category: 'Astro',
|
|
37
|
+
type: 'boolean',
|
|
38
|
+
default: true,
|
|
39
|
+
description: 'Enable/disable attribute shorthand if attribute name and expression are the same',
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
const parseSortOrder = (sortOrder) => sortOrder.split(' | ');
|
|
43
|
+
|
|
44
|
+
const blockElementsT = [
|
|
45
|
+
'address',
|
|
46
|
+
'article',
|
|
47
|
+
'aside',
|
|
48
|
+
'blockquote',
|
|
49
|
+
'details',
|
|
50
|
+
'dialog',
|
|
51
|
+
'dd',
|
|
52
|
+
'div',
|
|
53
|
+
'dl',
|
|
54
|
+
'dt',
|
|
55
|
+
'fieldset',
|
|
56
|
+
'figcaption',
|
|
57
|
+
'figure',
|
|
58
|
+
'footer',
|
|
59
|
+
'form',
|
|
60
|
+
'h1',
|
|
61
|
+
'h2',
|
|
62
|
+
'h3',
|
|
63
|
+
'h4',
|
|
64
|
+
'h5',
|
|
65
|
+
'h6',
|
|
66
|
+
'header',
|
|
67
|
+
'hgroup',
|
|
68
|
+
'hr',
|
|
69
|
+
'li',
|
|
70
|
+
'main',
|
|
71
|
+
'nav',
|
|
72
|
+
'ol',
|
|
73
|
+
'p',
|
|
74
|
+
'pre',
|
|
75
|
+
'section',
|
|
76
|
+
'table',
|
|
77
|
+
'ul',
|
|
78
|
+
];
|
|
79
|
+
const blockElements = [...blockElementsT];
|
|
80
|
+
const selfClosingTags = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
|
81
|
+
|
|
82
|
+
const formattableAttributes = [];
|
|
83
|
+
const rootNodeKeys = new Set(['html', 'css', 'module']);
|
|
84
|
+
const isASTNode = (node) => typeof node === 'object' && Object.keys(node).filter((key) => rootNodeKeys.has(key)).length === rootNodeKeys.size;
|
|
85
|
+
const isEmptyTextNode = (node) => {
|
|
86
|
+
return !!node && node.type === 'Text' && getUnencodedText(node).trim() === '';
|
|
87
|
+
};
|
|
88
|
+
const isPreTagContent = (path) => {
|
|
89
|
+
if (!path || !path.stack || !Array.isArray(path.stack))
|
|
90
|
+
return false;
|
|
91
|
+
return path.stack.some((node) => (node.type === 'Element' && node.name.toLowerCase() === 'pre') || (node.type === 'Attribute' && !formattableAttributes.includes(node.name)));
|
|
92
|
+
};
|
|
93
|
+
function isLoneMustacheTag(node) {
|
|
94
|
+
return node !== true && node.length === 1 && node[0].type === 'MustacheTag';
|
|
95
|
+
}
|
|
96
|
+
function isAttributeShorthand(node) {
|
|
97
|
+
return node !== true && node.length === 1 && node[0].type === 'AttributeShorthand';
|
|
98
|
+
}
|
|
99
|
+
function isOrCanBeConvertedToShorthand(node, opts) {
|
|
100
|
+
if (!opts.astroAllowShorthand)
|
|
101
|
+
return false;
|
|
102
|
+
if (isAttributeShorthand(node.value)) {
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
if (isLoneMustacheTag(node.value)) {
|
|
106
|
+
const expression = node.value[0].expression;
|
|
107
|
+
return expression.codeChunks[0] === node.name;
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
function getText(node, opts) {
|
|
112
|
+
return opts.originalText.slice(opts.locStart(node), opts.locEnd(node));
|
|
113
|
+
}
|
|
114
|
+
function getUnencodedText(node) {
|
|
115
|
+
return node.raw || node.data;
|
|
116
|
+
}
|
|
117
|
+
function replaceEndOfLineWith(text, replacement) {
|
|
118
|
+
const parts = [];
|
|
119
|
+
for (const part of text.split('\n')) {
|
|
120
|
+
if (parts.length > 0) {
|
|
121
|
+
parts.push(replacement);
|
|
122
|
+
}
|
|
123
|
+
if (part.endsWith('\r')) {
|
|
124
|
+
parts.push(part.slice(0, -1));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
parts.push(part);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return parts;
|
|
131
|
+
}
|
|
132
|
+
function printRaw(node, originalText, stripLeadingAndTrailingNewline = false) {
|
|
133
|
+
if (!isNodeWithChildren(node)) {
|
|
134
|
+
return '';
|
|
135
|
+
}
|
|
136
|
+
if (node.children.length === 0) {
|
|
137
|
+
return '';
|
|
138
|
+
}
|
|
139
|
+
const firstChild = node.children[0];
|
|
140
|
+
const lastChild = node.children[node.children.length - 1];
|
|
141
|
+
let raw = originalText.substring(firstChild.start, lastChild.end);
|
|
142
|
+
if (!stripLeadingAndTrailingNewline) {
|
|
143
|
+
return raw;
|
|
144
|
+
}
|
|
145
|
+
if (startsWithLinebreak(raw)) {
|
|
146
|
+
raw = raw.substring(raw.indexOf('\n') + 1);
|
|
147
|
+
}
|
|
148
|
+
if (endsWithLinebreak(raw)) {
|
|
149
|
+
raw = raw.substring(0, raw.lastIndexOf('\n'));
|
|
150
|
+
if (raw.charAt(raw.length - 1) === '\r') {
|
|
151
|
+
raw = raw.substring(0, raw.length - 1);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return raw;
|
|
155
|
+
}
|
|
156
|
+
function isNodeWithChildren(node) {
|
|
157
|
+
return node && Array.isArray(node.children);
|
|
158
|
+
}
|
|
159
|
+
function isInlineElement(path, opts, node) {
|
|
160
|
+
return node && node.type === 'Element' && !isBlockElement(node, opts) && !isPreTagContent(path);
|
|
161
|
+
}
|
|
162
|
+
function isBlockElement(node, opts) {
|
|
163
|
+
return node && node.type === 'Element' && opts.htmlWhitespaceSensitivity !== 'strict' && (opts.htmlWhitespaceSensitivity === 'ignore' || blockElements.includes(node.name));
|
|
164
|
+
}
|
|
165
|
+
function isTextNodeStartingWithLinebreak(node, nrLines = 1) {
|
|
166
|
+
return startsWithLinebreak(getUnencodedText(node), nrLines);
|
|
167
|
+
}
|
|
168
|
+
function startsWithLinebreak(text, nrLines = 1) {
|
|
169
|
+
return new RegExp(`^([\\t\\f\\r ]*\\n){${nrLines}}`).test(text);
|
|
170
|
+
}
|
|
171
|
+
function endsWithLinebreak(text, nrLines = 1) {
|
|
172
|
+
return new RegExp(`(\\n[\\t\\f\\r ]*){${nrLines}}$`).test(text);
|
|
173
|
+
}
|
|
174
|
+
function isTextNodeStartingWithWhitespace(node) {
|
|
175
|
+
return node.type === 'Text' && /^\s/.test(getUnencodedText(node));
|
|
176
|
+
}
|
|
177
|
+
function isTextNodeEndingWithWhitespace(node) {
|
|
178
|
+
return node.type === 'Text' && /\s$/.test(getUnencodedText(node));
|
|
179
|
+
}
|
|
180
|
+
function forceIntoExpression(statement) {
|
|
181
|
+
return `(${statement}\n)`;
|
|
182
|
+
}
|
|
183
|
+
function shouldHugStart(node, opts) {
|
|
184
|
+
if (isBlockElement(node, opts)) {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (!isNodeWithChildren(node)) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
const children = node.children;
|
|
191
|
+
if (children.length === 0) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
const firstChild = children[0];
|
|
195
|
+
return !isTextNodeStartingWithWhitespace(firstChild);
|
|
196
|
+
}
|
|
197
|
+
function shouldHugEnd(node, opts) {
|
|
198
|
+
if (isBlockElement(node, opts)) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
if (!isNodeWithChildren(node)) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
const children = node.children;
|
|
205
|
+
if (children.length === 0) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const lastChild = children[children.length - 1];
|
|
209
|
+
return !isTextNodeEndingWithWhitespace(lastChild);
|
|
210
|
+
}
|
|
211
|
+
function canOmitSoftlineBeforeClosingTag(path, opts) {
|
|
212
|
+
return isLastChildWithinParentBlockElement(path, opts);
|
|
213
|
+
}
|
|
214
|
+
function getChildren(node) {
|
|
215
|
+
return isNodeWithChildren(node) ? node.children : [];
|
|
216
|
+
}
|
|
217
|
+
function isLastChildWithinParentBlockElement(path, opts) {
|
|
218
|
+
const parent = path.getParentNode();
|
|
219
|
+
if (!parent || !isBlockElement(parent, opts)) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
const children = getChildren(parent);
|
|
223
|
+
const lastChild = children[children.length - 1];
|
|
224
|
+
return lastChild === path.getNode();
|
|
225
|
+
}
|
|
226
|
+
function trimTextNodeLeft(node) {
|
|
227
|
+
node.raw = node.raw && node.raw.trimLeft();
|
|
228
|
+
node.data = node.data && node.data.trimLeft();
|
|
229
|
+
}
|
|
230
|
+
function trimTextNodeRight(node) {
|
|
231
|
+
node.raw = node.raw && node.raw.trimRight();
|
|
232
|
+
node.data = node.data && node.data.trimRight();
|
|
233
|
+
}
|
|
234
|
+
function findLastIndex(isMatch, items) {
|
|
235
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
236
|
+
if (isMatch(items[i], i)) {
|
|
237
|
+
return i;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return -1;
|
|
241
|
+
}
|
|
242
|
+
function trimChildren(children) {
|
|
243
|
+
let firstNonEmptyNode = children.findIndex((n) => !isEmptyTextNode(n));
|
|
244
|
+
firstNonEmptyNode = firstNonEmptyNode === -1 ? children.length - 1 : firstNonEmptyNode;
|
|
245
|
+
let lastNonEmptyNode = findLastIndex((n, idx) => {
|
|
246
|
+
return !isEmptyTextNode(n);
|
|
247
|
+
}, children);
|
|
248
|
+
lastNonEmptyNode = lastNonEmptyNode === -1 ? 0 : lastNonEmptyNode;
|
|
249
|
+
for (let i = 0; i <= firstNonEmptyNode; i++) {
|
|
250
|
+
const n = children[i];
|
|
251
|
+
if (isTextNode(n)) {
|
|
252
|
+
trimTextNodeLeft(n);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
for (let i = children.length - 1; i >= lastNonEmptyNode; i--) {
|
|
256
|
+
const n = children[i];
|
|
257
|
+
if (isTextNode(n)) {
|
|
258
|
+
trimTextNodeRight(n);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
function isHardline(docToCheck) {
|
|
263
|
+
return docToCheck === prettier.doc.builders.hardline || deepEqual(docToCheck, prettier.doc.builders.hardline);
|
|
264
|
+
}
|
|
265
|
+
function deepEqual(x, y) {
|
|
266
|
+
if (x === y) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
else if (typeof x == 'object' && x != null && typeof y == 'object' && y != null) {
|
|
270
|
+
if (Object.keys(x).length != Object.keys(y).length)
|
|
271
|
+
return false;
|
|
272
|
+
for (var prop in x) {
|
|
273
|
+
if (Object.prototype.hasOwnProperty.call(y, prop)) {
|
|
274
|
+
if (!deepEqual(x[prop], y[prop]))
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function isLine(docToCheck) {
|
|
288
|
+
return (isHardline(docToCheck) ||
|
|
289
|
+
(typeof docToCheck === 'object' && isDocCommand(docToCheck) && docToCheck.type === 'line') ||
|
|
290
|
+
(typeof docToCheck === 'object' && isDocCommand(docToCheck) && docToCheck.type === 'concat' && docToCheck.parts.every(isLine)));
|
|
291
|
+
}
|
|
292
|
+
function isEmptyDoc(doc) {
|
|
293
|
+
if (typeof doc === 'string') {
|
|
294
|
+
return doc.length === 0;
|
|
295
|
+
}
|
|
296
|
+
if (Array.isArray(doc)) {
|
|
297
|
+
return doc.length === 0;
|
|
298
|
+
}
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
function trim(docs, isWhitespace) {
|
|
302
|
+
trimLeft(docs, isWhitespace);
|
|
303
|
+
trimRight(docs, isWhitespace);
|
|
304
|
+
return docs;
|
|
305
|
+
}
|
|
306
|
+
function trimLeft(group, isWhitespace) {
|
|
307
|
+
let firstNonWhitespace = group.findIndex((doc) => !isEmptyDoc(doc) && !isWhitespace(doc));
|
|
308
|
+
if (firstNonWhitespace < 0 && group.length) {
|
|
309
|
+
firstNonWhitespace = group.length;
|
|
310
|
+
}
|
|
311
|
+
if (firstNonWhitespace > 0) {
|
|
312
|
+
const removed = group.splice(0, firstNonWhitespace);
|
|
313
|
+
if (removed.every(isEmptyDoc)) {
|
|
314
|
+
return trimLeft(group, isWhitespace);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
const parts = getParts(group[0]);
|
|
319
|
+
if (parts) {
|
|
320
|
+
return trimLeft(parts, isWhitespace);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function trimRight(group, isWhitespace) {
|
|
325
|
+
let lastNonWhitespace = group.length ? findLastIndex((doc) => !isEmptyDoc(doc) && !isWhitespace(doc), group) : 0;
|
|
326
|
+
if (lastNonWhitespace < group.length - 1) {
|
|
327
|
+
const removed = group.splice(lastNonWhitespace + 1);
|
|
328
|
+
if (removed.every(isEmptyDoc)) {
|
|
329
|
+
return trimRight(group, isWhitespace);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
const parts = getParts(group[group.length - 1]);
|
|
334
|
+
if (parts) {
|
|
335
|
+
return trimRight(parts, isWhitespace);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
function getParts(doc) {
|
|
340
|
+
if (typeof doc === 'object') {
|
|
341
|
+
if (Array.isArray(doc)) {
|
|
342
|
+
return doc;
|
|
343
|
+
}
|
|
344
|
+
if (doc.type === 'fill' || doc.type === 'concat') {
|
|
345
|
+
return doc.parts;
|
|
346
|
+
}
|
|
347
|
+
if (doc.type === 'group') {
|
|
348
|
+
return getParts(doc.contents);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function attachCommentsHTML(node) {
|
|
353
|
+
if (!isNodeWithChildren(node) || !node.children.some(({ type }) => type === 'Comment'))
|
|
354
|
+
return;
|
|
355
|
+
const nodesToRemove = [];
|
|
356
|
+
for (let n = 0; n < node.children.length - 1; n++) {
|
|
357
|
+
if (!node.children[n])
|
|
358
|
+
continue;
|
|
359
|
+
if (node.children[n].type === 'Comment') {
|
|
360
|
+
let next = n + 1;
|
|
361
|
+
while (isEmptyTextNode(node.children[next])) {
|
|
362
|
+
nodesToRemove.push(next);
|
|
363
|
+
next++;
|
|
364
|
+
}
|
|
365
|
+
prettier.util.addLeadingComment(node.children[next], node.children[n]);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
nodesToRemove.reverse();
|
|
369
|
+
nodesToRemove.forEach((index) => {
|
|
370
|
+
node.children.splice(index, 1);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
function dedent$1(input) {
|
|
374
|
+
let minTabSize = Infinity;
|
|
375
|
+
let result = input;
|
|
376
|
+
result = result.replace(/\r\n/g, '\n');
|
|
377
|
+
let char = '';
|
|
378
|
+
for (const line of result.split('\n')) {
|
|
379
|
+
if (!line)
|
|
380
|
+
continue;
|
|
381
|
+
if (line[0] && /^[^\s]/.test(line[0])) {
|
|
382
|
+
minTabSize = 0;
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
const match = line.match(/^(\s+)\S+/);
|
|
386
|
+
if (match) {
|
|
387
|
+
if (match[1] && !char)
|
|
388
|
+
char = match[1][0];
|
|
389
|
+
if (match[1].length < minTabSize)
|
|
390
|
+
minTabSize = match[1].length;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (minTabSize > 0 && Number.isFinite(minTabSize)) {
|
|
394
|
+
result = result.replace(new RegExp(`^${new Array(minTabSize + 1).join(char)}`, 'gm'), '');
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
tabSize: minTabSize === Infinity ? 0 : minTabSize,
|
|
398
|
+
char,
|
|
399
|
+
result,
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function getMarkdownName(script) {
|
|
403
|
+
let defaultMatch;
|
|
404
|
+
while ((defaultMatch = /import\s+([^\s]+)\s+from\s+['|"|`]astro\/components\/Markdown\.astro/g.exec(script))) {
|
|
405
|
+
if (defaultMatch[1])
|
|
406
|
+
return new Set([defaultMatch[1].trim()]);
|
|
407
|
+
}
|
|
408
|
+
let namedMatch;
|
|
409
|
+
while ((namedMatch = /import\s+\{\s*([^}]+)\}\s+from\s+['|"|`]astro\/components/g.exec(script))) {
|
|
410
|
+
if (namedMatch[1] && !namedMatch[1].includes('Markdown'))
|
|
411
|
+
continue;
|
|
412
|
+
const rawImports = namedMatch[1].trim().replace(/^\{/, '').replace(/\}$/, '').trim();
|
|
413
|
+
let importName = 'Markdown';
|
|
414
|
+
for (const spec of rawImports.split(',')) {
|
|
415
|
+
const [original, renamed] = spec.split(' as ').map((s) => s.trim());
|
|
416
|
+
if (original !== 'Markdown')
|
|
417
|
+
continue;
|
|
418
|
+
importName = renamed || original;
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
return new Set([importName]);
|
|
422
|
+
}
|
|
423
|
+
return new Set(['Markdown']);
|
|
424
|
+
}
|
|
425
|
+
function isTextNode(node) {
|
|
426
|
+
return node.type === 'Text';
|
|
427
|
+
}
|
|
428
|
+
function isDocCommand(doc) {
|
|
429
|
+
if (typeof doc === 'string')
|
|
430
|
+
return false;
|
|
431
|
+
if (Array.isArray(doc))
|
|
432
|
+
return false;
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
function isInsideQuotedAttribute(path) {
|
|
436
|
+
const stack = path.stack;
|
|
437
|
+
return stack.some((node) => node.type === 'Attribute' && !isLoneMustacheTag(node.value));
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const { builders: { breakParent, dedent, fill, group, hardline, indent, join, line, literalline, softline }, utils: { removeLines, stripTrailingHardline }, } = _doc__default["default"];
|
|
441
|
+
function printTopLevelParts(node, path, opts, print) {
|
|
442
|
+
let docs = [];
|
|
443
|
+
const normalize = (doc) => [stripTrailingHardline(doc), hardline];
|
|
444
|
+
if (node.module) {
|
|
445
|
+
const subDoc = normalize(path.call(print, 'module'));
|
|
446
|
+
docs.push(subDoc);
|
|
447
|
+
}
|
|
448
|
+
for (const section of parseSortOrder(opts.astroSortOrder)) {
|
|
449
|
+
switch (section) {
|
|
450
|
+
case 'markup': {
|
|
451
|
+
const subDoc = path.call(print, 'html');
|
|
452
|
+
if (!isEmptyDoc(subDoc))
|
|
453
|
+
docs.push(normalize(subDoc));
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
case 'styles': {
|
|
457
|
+
const subDoc = path.call(print, 'css');
|
|
458
|
+
if (!isEmptyDoc(subDoc))
|
|
459
|
+
docs.push(normalize(subDoc));
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
return join(softline, docs);
|
|
465
|
+
}
|
|
466
|
+
function printAttributeNodeValue(path, print, quotes, node) {
|
|
467
|
+
const valueDocs = path.map((childPath) => childPath.call(print), 'value');
|
|
468
|
+
if (!quotes || !formattableAttributes.includes(node.name)) {
|
|
469
|
+
return valueDocs;
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
return indent(group(trim(valueDocs, isLine)));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
function printJS(path, print, name, { forceSingleQuote, forceSingleLine }) {
|
|
476
|
+
path.getValue()[name].isJS = true;
|
|
477
|
+
path.getValue()[name].forceSingleQuote = forceSingleQuote;
|
|
478
|
+
path.getValue()[name].forceSingleLine = forceSingleLine;
|
|
479
|
+
return path.call(print, name);
|
|
480
|
+
}
|
|
481
|
+
function printComment(commentPath, options) {
|
|
482
|
+
return commentPath;
|
|
483
|
+
}
|
|
484
|
+
function print(path, opts, print) {
|
|
485
|
+
var _a, _b;
|
|
486
|
+
const node = path.getValue();
|
|
487
|
+
const isMarkdownSubDoc = opts.parentParser === 'markdown';
|
|
488
|
+
if (!node) {
|
|
489
|
+
return '';
|
|
490
|
+
}
|
|
491
|
+
if (typeof node === 'string') {
|
|
492
|
+
return node;
|
|
493
|
+
}
|
|
494
|
+
if (Array.isArray(node)) {
|
|
495
|
+
return path.map((childPath) => childPath.call(print));
|
|
496
|
+
}
|
|
497
|
+
if (isASTNode(node)) {
|
|
498
|
+
return printTopLevelParts(node, path, opts, print);
|
|
499
|
+
}
|
|
500
|
+
if (!isPreTagContent(path) && !isMarkdownSubDoc) {
|
|
501
|
+
attachCommentsHTML(node);
|
|
502
|
+
}
|
|
503
|
+
switch (node.type) {
|
|
504
|
+
case 'Fragment': {
|
|
505
|
+
const text = getText(node, opts);
|
|
506
|
+
if (text.length === 0) {
|
|
507
|
+
return '';
|
|
508
|
+
}
|
|
509
|
+
if (!isNodeWithChildren(node) || node.children.every(isEmptyTextNode))
|
|
510
|
+
return '';
|
|
511
|
+
const hasInlineComponent = node.children.filter((x) => x.type === 'InlineComponent').length > 0;
|
|
512
|
+
if (text.indexOf('{') === -1 && !hasInlineComponent) {
|
|
513
|
+
node.__isRawHTML = true;
|
|
514
|
+
node.content = text;
|
|
515
|
+
return path.call(print);
|
|
516
|
+
}
|
|
517
|
+
if (!isPreTagContent(path)) {
|
|
518
|
+
trimChildren(node.children);
|
|
519
|
+
const output = trim([path.map(print, 'children')], (n) => isLine(n) ||
|
|
520
|
+
(typeof n === 'string' && n.trim() === '') ||
|
|
521
|
+
n === breakParent);
|
|
522
|
+
if (output.every((doc) => isEmptyDoc(doc))) {
|
|
523
|
+
return '';
|
|
524
|
+
}
|
|
525
|
+
return group([...output, hardline]);
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
return group(path.map(print, 'children'));
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
case 'Text': {
|
|
532
|
+
const rawText = getUnencodedText(node);
|
|
533
|
+
if (isPreTagContent(path)) {
|
|
534
|
+
if (((_a = path.getParentNode()) === null || _a === void 0 ? void 0 : _a.type) === 'Attribute') {
|
|
535
|
+
return replaceEndOfLineWith(rawText, literalline);
|
|
536
|
+
}
|
|
537
|
+
return rawText;
|
|
538
|
+
}
|
|
539
|
+
if (isEmptyTextNode(node)) {
|
|
540
|
+
const hasWhiteSpace = rawText.trim().length < getUnencodedText(node).length;
|
|
541
|
+
const hasOneOrMoreNewlines = /\n/.test(getUnencodedText(node));
|
|
542
|
+
const hasTwoOrMoreNewlines = /\n\r?\s*\n\r?/.test(getUnencodedText(node));
|
|
543
|
+
if (hasTwoOrMoreNewlines) {
|
|
544
|
+
return [hardline, hardline];
|
|
545
|
+
}
|
|
546
|
+
if (hasOneOrMoreNewlines) {
|
|
547
|
+
return hardline;
|
|
548
|
+
}
|
|
549
|
+
if (hasWhiteSpace) {
|
|
550
|
+
return line;
|
|
551
|
+
}
|
|
552
|
+
return '';
|
|
553
|
+
}
|
|
554
|
+
return fill(splitTextToDocs(node));
|
|
555
|
+
}
|
|
556
|
+
case 'Element':
|
|
557
|
+
case 'InlineComponent':
|
|
558
|
+
case 'Slot': {
|
|
559
|
+
const isEmpty = (_b = node.children) === null || _b === void 0 ? void 0 : _b.every((child) => isEmptyTextNode(child));
|
|
560
|
+
const isSelfClosingTag = isEmpty && (node.type !== 'Element' || selfClosingTags.indexOf(node.name) !== -1);
|
|
561
|
+
const attributes = path.map(print, 'attributes');
|
|
562
|
+
if (isSelfClosingTag) {
|
|
563
|
+
return group(['<', node.name, indent(group(attributes)), line, `/>`]);
|
|
564
|
+
}
|
|
565
|
+
try {
|
|
566
|
+
if (node.name.toLowerCase() === '!doctype') {
|
|
567
|
+
const attributesWithLowercaseHTML = attributes.map((attribute) => {
|
|
568
|
+
if (typeof attribute === 'string')
|
|
569
|
+
return attribute;
|
|
570
|
+
if (isDocCommand(attribute))
|
|
571
|
+
return attribute;
|
|
572
|
+
attribute = attribute.map((attrValue) => {
|
|
573
|
+
if (typeof attrValue !== 'string')
|
|
574
|
+
return attrValue;
|
|
575
|
+
if (attrValue.toLowerCase() === 'html') {
|
|
576
|
+
attrValue = attrValue.toLowerCase();
|
|
577
|
+
}
|
|
578
|
+
return attrValue;
|
|
579
|
+
});
|
|
580
|
+
return attribute;
|
|
581
|
+
});
|
|
582
|
+
return group(['<', node.name.toUpperCase(), ...attributesWithLowercaseHTML, `>`]);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
catch (e) {
|
|
586
|
+
console.warn(`error ${e} in the doctype printing`);
|
|
587
|
+
}
|
|
588
|
+
if (node.children) {
|
|
589
|
+
const children = node.children;
|
|
590
|
+
const firstChild = children[0];
|
|
591
|
+
const lastChild = children[children.length - 1];
|
|
592
|
+
let noHugSeparatorStart = softline;
|
|
593
|
+
let noHugSeparatorEnd = softline;
|
|
594
|
+
let hugStart = shouldHugStart(node, opts);
|
|
595
|
+
let hugEnd = shouldHugEnd(node, opts);
|
|
596
|
+
let body;
|
|
597
|
+
if (isEmpty) {
|
|
598
|
+
body =
|
|
599
|
+
isInlineElement(path, opts, node) && node.children.length && isTextNodeStartingWithWhitespace(node.children[0]) && !isPreTagContent(path)
|
|
600
|
+
? () => line
|
|
601
|
+
:
|
|
602
|
+
() => softline;
|
|
603
|
+
}
|
|
604
|
+
else if (isPreTagContent(path)) {
|
|
605
|
+
body = () => printRaw(node, opts.originalText);
|
|
606
|
+
}
|
|
607
|
+
else if (isInlineElement(path, opts, node) && !isPreTagContent(path)) {
|
|
608
|
+
body = () => path.map(print, 'children');
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
body = () => path.map(print, 'children');
|
|
612
|
+
}
|
|
613
|
+
const openingTag = ['<', node.name, indent(group([...attributes, hugStart ? '' : !isPreTagContent(path) && !opts.bracketSameLine ? dedent(softline) : '']))];
|
|
614
|
+
if (hugStart && hugEnd) {
|
|
615
|
+
const huggedContent = [softline, group(['>', body(), `</${node.name}`])];
|
|
616
|
+
const omitSoftlineBeforeClosingTag = isEmpty || canOmitSoftlineBeforeClosingTag(path, opts);
|
|
617
|
+
return group([...openingTag, isEmpty ? group(huggedContent) : group(indent(huggedContent)), omitSoftlineBeforeClosingTag ? '' : softline, '>']);
|
|
618
|
+
}
|
|
619
|
+
if (isPreTagContent(path)) {
|
|
620
|
+
noHugSeparatorStart = '';
|
|
621
|
+
noHugSeparatorEnd = '';
|
|
622
|
+
}
|
|
623
|
+
else {
|
|
624
|
+
let didSetEndSeparator = false;
|
|
625
|
+
if (!hugStart && firstChild && isTextNode(firstChild)) {
|
|
626
|
+
if (isTextNodeStartingWithLinebreak(firstChild) && firstChild !== lastChild && (!isInlineElement(path, opts, node) || isTextNodeEndingWithWhitespace(lastChild))) {
|
|
627
|
+
noHugSeparatorStart = hardline;
|
|
628
|
+
noHugSeparatorEnd = hardline;
|
|
629
|
+
didSetEndSeparator = true;
|
|
630
|
+
}
|
|
631
|
+
else if (isInlineElement(path, opts, node)) {
|
|
632
|
+
noHugSeparatorStart = line;
|
|
633
|
+
}
|
|
634
|
+
trimTextNodeLeft(firstChild);
|
|
635
|
+
}
|
|
636
|
+
if (!hugEnd && lastChild && isTextNode(lastChild)) {
|
|
637
|
+
if (isInlineElement(path, opts, node) && !didSetEndSeparator) {
|
|
638
|
+
noHugSeparatorEnd = line;
|
|
639
|
+
}
|
|
640
|
+
trimTextNodeRight(lastChild);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
if (hugStart) {
|
|
644
|
+
return group([...openingTag, indent([softline, group(['>', body()])]), noHugSeparatorEnd, `</${node.name}>`]);
|
|
645
|
+
}
|
|
646
|
+
if (hugEnd) {
|
|
647
|
+
return group([...openingTag, '>', indent([noHugSeparatorStart, group([body(), `</${node.name}`])]), canOmitSoftlineBeforeClosingTag(path, opts) ? '' : softline, '>']);
|
|
648
|
+
}
|
|
649
|
+
if (isEmpty) {
|
|
650
|
+
return group([...openingTag, '>', body(), `</${node.name}>`]);
|
|
651
|
+
}
|
|
652
|
+
return group([...openingTag, '>', indent([noHugSeparatorStart, body()]), noHugSeparatorEnd, `</${node.name}>`]);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
case 'AttributeShorthand': {
|
|
656
|
+
return node.expression.name;
|
|
657
|
+
}
|
|
658
|
+
case 'Attribute': {
|
|
659
|
+
if (isOrCanBeConvertedToShorthand(node, opts)) {
|
|
660
|
+
return [line, '{', node.name, '}'];
|
|
661
|
+
}
|
|
662
|
+
else {
|
|
663
|
+
if (node.value === true) {
|
|
664
|
+
return [line, node.name];
|
|
665
|
+
}
|
|
666
|
+
const quotes = !isLoneMustacheTag(node.value);
|
|
667
|
+
const attrNodeValue = printAttributeNodeValue(path, print, quotes, node);
|
|
668
|
+
if (quotes) {
|
|
669
|
+
return [line, node.name, '=', '"', attrNodeValue, '"'];
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
return [line, node.name, '=', attrNodeValue];
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
case 'Expression':
|
|
677
|
+
return [];
|
|
678
|
+
case 'MustacheTag':
|
|
679
|
+
return [
|
|
680
|
+
'{',
|
|
681
|
+
printJS(path, print, 'expression', {
|
|
682
|
+
forceSingleLine: isInsideQuotedAttribute(path),
|
|
683
|
+
forceSingleQuote: opts.jsxSingleQuote,
|
|
684
|
+
}),
|
|
685
|
+
'}',
|
|
686
|
+
];
|
|
687
|
+
case 'Spread':
|
|
688
|
+
return [
|
|
689
|
+
line,
|
|
690
|
+
'{...',
|
|
691
|
+
printJS(path, print, 'expression', {
|
|
692
|
+
forceSingleQuote: true,
|
|
693
|
+
forceSingleLine: false,
|
|
694
|
+
}),
|
|
695
|
+
'}',
|
|
696
|
+
];
|
|
697
|
+
case 'Comment':
|
|
698
|
+
return ['<!--', getUnencodedText(node), '-->'];
|
|
699
|
+
case 'CodeSpan':
|
|
700
|
+
return getUnencodedText(node);
|
|
701
|
+
case 'CodeFence': {
|
|
702
|
+
console.debug(node);
|
|
703
|
+
return [node.metadata, hardline, node.data, hardline, '```', hardline];
|
|
704
|
+
}
|
|
705
|
+
default: {
|
|
706
|
+
throw new Error(`Unhandled node type "${node.type}"!`);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
function splitTextToDocs(node) {
|
|
711
|
+
const text = getUnencodedText(node);
|
|
712
|
+
let textLines = text.split(/[\t\n\f\r ]+/);
|
|
713
|
+
let docs = join(line, textLines).parts.filter((s) => s !== '');
|
|
714
|
+
if (startsWithLinebreak(text)) {
|
|
715
|
+
docs[0] = hardline;
|
|
716
|
+
}
|
|
717
|
+
if (startsWithLinebreak(text, 2)) {
|
|
718
|
+
docs = [hardline, ...docs];
|
|
719
|
+
}
|
|
720
|
+
if (endsWithLinebreak(text)) {
|
|
721
|
+
docs[docs.length - 1] = hardline;
|
|
722
|
+
}
|
|
723
|
+
if (endsWithLinebreak(text, 2)) {
|
|
724
|
+
docs = [...docs, hardline];
|
|
725
|
+
}
|
|
726
|
+
return docs;
|
|
727
|
+
}
|
|
728
|
+
function expressionParser(text, parsers, opts) {
|
|
729
|
+
const ast = parsers.babel(text, parsers, opts);
|
|
730
|
+
return { ...ast, program: ast.program.body[0].expression };
|
|
731
|
+
}
|
|
732
|
+
let markdownComponentName = new Set();
|
|
733
|
+
function embed(path, print, textToDoc, opts) {
|
|
734
|
+
if (!opts.__astro)
|
|
735
|
+
opts.__astro = {};
|
|
736
|
+
const node = path.getValue();
|
|
737
|
+
if (!node)
|
|
738
|
+
return null;
|
|
739
|
+
if (node.isJS) {
|
|
740
|
+
try {
|
|
741
|
+
const embeddedopts = {
|
|
742
|
+
parser: expressionParser,
|
|
743
|
+
};
|
|
744
|
+
if (node.forceSingleQuote) {
|
|
745
|
+
embeddedopts.singleQuote = true;
|
|
746
|
+
}
|
|
747
|
+
const docs = textToDoc(forceIntoExpression(getText(node, opts)), embeddedopts);
|
|
748
|
+
return node.forceSingleLine ? removeLines(docs) : docs;
|
|
749
|
+
}
|
|
750
|
+
catch (e) {
|
|
751
|
+
return getText(node, opts);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
if (node.type === 'Script' && node.context === 'setup') {
|
|
755
|
+
markdownComponentName = getMarkdownName(node.content);
|
|
756
|
+
return group(['---', hardline, textToDoc(node.content, { ...opts, parser: 'typescript' }), '---', hardline]);
|
|
757
|
+
}
|
|
758
|
+
if (isTextNode(node)) {
|
|
759
|
+
const parent = path.getParentNode();
|
|
760
|
+
if (parent && parent.type === 'Element' && parent.name === 'script') {
|
|
761
|
+
const formatttedScript = textToDoc(node.data, { ...opts, parser: 'typescript' });
|
|
762
|
+
return stripTrailingHardline(formatttedScript);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
if (node.type === 'Style' || (node.type === 'Element' && node.name === 'style')) {
|
|
766
|
+
let styleTagContent = '';
|
|
767
|
+
if (node.type === 'Style') {
|
|
768
|
+
styleTagContent = node.content.styles;
|
|
769
|
+
}
|
|
770
|
+
else if (node.children) {
|
|
771
|
+
const children = node.children[0];
|
|
772
|
+
styleTagContent = getUnencodedText(children);
|
|
773
|
+
}
|
|
774
|
+
const supportedStyleLangValues = ['css', 'scss', 'sass'];
|
|
775
|
+
let parserLang = 'css';
|
|
776
|
+
if ('attributes' in node) {
|
|
777
|
+
const langAttribute = node.attributes.filter((x) => x.name === 'lang');
|
|
778
|
+
if (langAttribute.length) {
|
|
779
|
+
const styleLang = langAttribute[0].value[0].raw.toLowerCase();
|
|
780
|
+
if (supportedStyleLangValues.includes(styleLang))
|
|
781
|
+
parserLang = styleLang;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
switch (parserLang) {
|
|
785
|
+
case 'css':
|
|
786
|
+
case 'scss': {
|
|
787
|
+
let formattedStyles = textToDoc(styleTagContent, { ...opts, parser: parserLang });
|
|
788
|
+
formattedStyles = stripTrailingHardline(formattedStyles);
|
|
789
|
+
const attributes = path.map(print, 'attributes');
|
|
790
|
+
const openingTag = group(['<style', indent(group(attributes)), softline, '>']);
|
|
791
|
+
return [openingTag, indent([hardline, formattedStyles]), hardline, '</style>'];
|
|
792
|
+
}
|
|
793
|
+
case 'sass': {
|
|
794
|
+
const lineEnding = opts.endOfLine.toUpperCase() === 'CRLF' ? 'CRLF' : 'LF';
|
|
795
|
+
const sassOptions = {
|
|
796
|
+
tabSize: opts.tabWidth,
|
|
797
|
+
insertSpaces: !opts.useTabs,
|
|
798
|
+
lineEnding,
|
|
799
|
+
};
|
|
800
|
+
const { result: raw } = dedent$1(styleTagContent);
|
|
801
|
+
let formattedSassIndented = sassFormatter.SassFormatter.Format(raw, sassOptions).trim();
|
|
802
|
+
const formattedSass = join(hardline, formattedSassIndented.split('\n'));
|
|
803
|
+
const attributes = path.map(print, 'attributes');
|
|
804
|
+
const openingTag = group(['<style', indent(group(attributes)), softline, '>']);
|
|
805
|
+
return [openingTag, indent(group([hardline, formattedSass])), hardline, '</style>'];
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
if (node.type === 'InlineComponent' && markdownComponentName.has(node.name)) {
|
|
810
|
+
let content = printRaw(node, opts.originalText);
|
|
811
|
+
content = content.replace(/\r\n/g, '\n');
|
|
812
|
+
const contentArr = content.split('\n').map((s) => s.trimStart());
|
|
813
|
+
content = contentArr.join('\n');
|
|
814
|
+
let formatttedMarkdown = textToDoc(content, { ...opts, parser: 'markdown' });
|
|
815
|
+
formatttedMarkdown = stripTrailingHardline(formatttedMarkdown);
|
|
816
|
+
const attributes = path.map(print, 'attributes');
|
|
817
|
+
const openingTag = group([`<${node.name}`, indent(group(attributes)), softline, '>']);
|
|
818
|
+
return [openingTag, indent(group([hardline, formatttedMarkdown])), hardline, `</${node.name}>`];
|
|
819
|
+
}
|
|
820
|
+
if (node.__isRawHTML) {
|
|
821
|
+
return textToDoc(node.content, { ...opts, parser: 'html' });
|
|
822
|
+
}
|
|
823
|
+
return null;
|
|
824
|
+
}
|
|
825
|
+
function hasPrettierIgnore(path) {
|
|
826
|
+
const node = path.getNode();
|
|
827
|
+
if (!node || !Array.isArray(node.comments))
|
|
828
|
+
return false;
|
|
829
|
+
const hasIgnore = node.comments.some((comment) => comment.data.includes('prettier-ignore') && !comment.data.includes('prettier-ignore-start') && !comment.data.includes('prettier-ignore-end'));
|
|
830
|
+
return hasIgnore;
|
|
831
|
+
}
|
|
832
|
+
const printer = {
|
|
833
|
+
print,
|
|
834
|
+
printComment,
|
|
835
|
+
embed,
|
|
836
|
+
hasPrettierIgnore,
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
const languages = [
|
|
840
|
+
{
|
|
841
|
+
name: 'astro',
|
|
842
|
+
parsers: ['astro'],
|
|
843
|
+
extensions: ['.astro'],
|
|
844
|
+
vscodeLanguageIds: ['astro'],
|
|
845
|
+
},
|
|
846
|
+
];
|
|
847
|
+
const parsers = {
|
|
848
|
+
astro: {
|
|
849
|
+
parse,
|
|
850
|
+
astFormat: 'astro',
|
|
851
|
+
locStart: (node) => node.start,
|
|
852
|
+
locEnd: (node) => node.end,
|
|
853
|
+
},
|
|
854
|
+
};
|
|
855
|
+
const printers = {
|
|
856
|
+
astro: printer,
|
|
857
|
+
};
|
|
858
|
+
const defaultOptions = {
|
|
859
|
+
tabWidth: 2,
|
|
860
|
+
};
|
|
861
|
+
|
|
862
|
+
exports.defaultOptions = defaultOptions;
|
|
863
|
+
exports.languages = languages;
|
|
864
|
+
exports.options = options;
|
|
865
|
+
exports.parsers = parsers;
|
|
866
|
+
exports.printers = printers;
|
|
867
|
+
//# sourceMappingURL=index.js.map
|