All files / internal / testing / format.ts

100.00% Branches 0/0
100.00% Lines 10/10
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
x33
 
 
x33
x231
 
 
x33
x2256
x5076
x564
x564
x564
x564












// Imports
import { createStreaming } from "@dprint/formatter"

/** HTML formatter. */
const formatter = await createStreaming(fetch("https://lecoq.io/cdn/dprint/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")
}