All files / internal / testing / format.ts

100.00% Branches 0/0
100.00% Lines 12/12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
x33
x33
 
x33
 
 
x33
x231
 
 
x33
x2288
x5148
x572
x572
x572
x572















// Imports
import { createFromBuffer } from "@dprint/formatter"
import { fromFileUrl } from "@std/path"
// deno-lint-ignore no-external-import
import { readFileSync } from "node:fs"

/** HTML formatter. */
const formatter = createFromBuffer(readFileSync(fromFileUrl(import.meta.resolve("./fixtures/markup_fmt-v0.13.1.wasm"))))
formatter.setConfig({}, { printWidth: 120, closingBracketSameLine: true, closingTagLineBreakForEmpty: "never", preferAttrsSingleLine: true, whitespaceSensitivity: "ignore" })

/** Format HTML. */
export function format(html: string): string {
  const options = { filePath: "test.html", fileText: html }
  return formatter.formatText({ ...options, fileText: formatter.formatText({ ...options, overrideConfig: { printWidth: 0 } }) })
    .split("\n")
    .filter((line) => line)
    .join("\n")
}