prettier-plugin-mdc 0.1.3 → 0.1.4
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/dist/index.mjs +20 -11
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -108,17 +108,16 @@ function quoteString(value, options) {
|
|
|
108
108
|
const quote = hasPreferred && !hasAlternative ? alternativeQuote : preferredQuote;
|
|
109
109
|
return `${quote}${escapeQuotes(value.replace(/\\/g, "\\\\"), quote)}${quote}`;
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
//#endregion
|
|
113
|
-
//#region src/print.ts
|
|
114
|
-
const { hardline: hardline$1, join } = doc.builders;
|
|
115
|
-
const mapChildren = (path, print) => path.map(print, "children");
|
|
116
111
|
function serializeValue(value, options) {
|
|
117
112
|
if (typeof value === "string") return quoteString(value, options);
|
|
118
113
|
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
119
114
|
const preferredQuote = options.singleQuote ? "'" : "\"";
|
|
120
115
|
return `${preferredQuote}${escapeQuotes(JSON.stringify(value), preferredQuote)}${preferredQuote}`;
|
|
121
116
|
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
//#region src/print.ts
|
|
120
|
+
const { hardline: hardline$1, join } = doc.builders;
|
|
122
121
|
function printAttributes({ attributes }, options) {
|
|
123
122
|
if (!attributes || Object.keys(attributes).length === 0) return "";
|
|
124
123
|
const parts = [];
|
|
@@ -210,14 +209,24 @@ function printContainerComponentWithYamlDoc(path, print, options, yamlDoc) {
|
|
|
210
209
|
parts.push(hardline$1);
|
|
211
210
|
if (yamlDoc.length > 0) parts.push(...yamlDoc);
|
|
212
211
|
if (node.children && node.children.length > 0) {
|
|
212
|
+
const componentStartLine = node.position?.start.line ?? 0;
|
|
213
|
+
let prevEndLine;
|
|
213
214
|
if (yamlDoc.length > 0 && node.rawData) {
|
|
214
|
-
const componentStartLine = node.position?.start.line ?? 0;
|
|
215
215
|
const rawDataNewlines = (node.rawData.match(/\n/g) ?? []).length;
|
|
216
|
-
|
|
217
|
-
|
|
216
|
+
prevEndLine = componentStartLine + 1 + rawDataNewlines;
|
|
217
|
+
} else prevEndLine = componentStartLine;
|
|
218
|
+
const childDocs = [];
|
|
219
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
220
|
+
const child = node.children[i];
|
|
221
|
+
const childStartLine = child.position?.start.line ?? 0;
|
|
222
|
+
if (i > 0) {
|
|
223
|
+
childDocs.push(hardline$1);
|
|
224
|
+
if (childStartLine > prevEndLine + 1) childDocs.push(hardline$1);
|
|
225
|
+
} else if (yamlDoc.length > 0 && node.rawData && childStartLine > prevEndLine + 1) childDocs.push(hardline$1);
|
|
226
|
+
childDocs.push(path.call(print, "children", i));
|
|
227
|
+
prevEndLine = child.position?.end.line ?? prevEndLine;
|
|
218
228
|
}
|
|
219
|
-
|
|
220
|
-
parts.push(join(hardline$1, childDocs));
|
|
229
|
+
parts.push(...childDocs);
|
|
221
230
|
parts.push(hardline$1);
|
|
222
231
|
}
|
|
223
232
|
parts.push(colons);
|
|
@@ -231,7 +240,7 @@ function printComponentContainerSection(path, print) {
|
|
|
231
240
|
const parts = [];
|
|
232
241
|
if (node.name && node.name !== "default") parts.push(`#${node.name}`, hardline$1);
|
|
233
242
|
if (node.children && node.children.length > 0) {
|
|
234
|
-
const childDocs =
|
|
243
|
+
const childDocs = path.map(print, "children");
|
|
235
244
|
parts.push(join(hardline$1, childDocs));
|
|
236
245
|
}
|
|
237
246
|
return parts;
|