Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
wrapLineLength: 90,
unformatted: "",
contentUnformatted: "pre,code,textarea",
indentInnerHtml: true,
preserveNewLines: true,
maxPreserveNewLines: undefined,
indentHandlebars: false,
endWithNewline: false,
extraLiners: "head, body, /html",
wrapAttributes: "auto"
});
const hasLeadingNewline = originalHtml.startsWith("\n");
const hasTrailingNewline = originalHtml.endsWith("\n");
const newHtml = `${hasLeadingNewline ? "\n" : ""}${vscode.TextDocument.applyEdits(vscTextDocument, edits)}${hasTrailingNewline ? "\n" : ""}`;
const splitted = newHtml.split(/\[#+\]/);
return splitted.map((newText, i) => {
const range = ranges[i];
return { range: { document, ...range }, newText };
});
}
}
function makeVscTextDocument(htmlDocument: HtmlDocument): vscode.TextDocument {
return vscode.TextDocument.create("untitled://embedded.html", "html", 1, htmlDocument.virtualDocument.text);
}
format(document: HtmlDocument, settings: ts.FormatCodeSettings): LitFormatEdit[] {
const parts = document.virtualDocument.getPartsAtOffsetRange({
start: 0,
end: document.virtualDocument.location.end - document.virtualDocument.location.start
});
const ranges = textPartsToRanges(parts);
const originalHtml = parts.map(p => (typeof p === "string" ? p : `[#${"#".repeat(p.getText().length)}]`)).join("");
const vscTextDocument = vscode.TextDocument.create("untitled://embedded.html", "html", 1, originalHtml);
const edits = htmlService.format(vscTextDocument, undefined, {
tabSize: settings.tabSize,
insertSpaces: !!settings.convertTabsToSpaces,
wrapLineLength: 90,
unformatted: "",
contentUnformatted: "pre,code,textarea",
indentInnerHtml: true,
preserveNewLines: true,
maxPreserveNewLines: undefined,
indentHandlebars: false,
endWithNewline: false,
extraLiners: "head, body, /html",
wrapAttributes: "auto"
});