Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/problem-utils-browser/src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import {
startLocalHttpServer,
type TestCaseResult,
} from '@exercode/problem-utils';
import sniffHtmlEncoding from 'html-encoding-sniffer';
import type { Page } from 'puppeteer';
import { format } from 'prettier';
import prettierPluginOrganizeAttributes from 'prettier-plugin-organize-attributes';

import { createBrowserPage, capturePngScreenshot, launchBrowser } from './browser.js';
import { createTemporaryDirectory } from './temporaryDirectory.js';
Expand Down Expand Up @@ -258,6 +255,12 @@ async function loadFormattedHtmlForScreenshot(url: string): Promise<string | und
if (!contentType.includes('text/html')) return undefined;

const bytes = new Uint8Array(await response.arrayBuffer());
const [{ default: sniffHtmlEncoding }, { format }, { default: prettierPluginOrganizeAttributes }] =
await Promise.all([
import('html-encoding-sniffer'),
import('prettier'),
import('prettier-plugin-organize-attributes'),
]);
const encoding = sniffHtmlEncoding(bytes, {
transportLayerEncodingLabel: new MIMEType(contentType).params.get('charset') ?? undefined,
defaultEncoding: 'utf8',
Expand Down
Loading