Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export type ViewerUrlOption = Pick<
| 'viewerParam'
| 'base'
| 'outputs'
| 'rootUrl'
>;

export function generateCmykReserveMap({
Expand Down Expand Up @@ -76,6 +77,7 @@ export function getViewerParams(
quick,
viewerParam,
base,
rootUrl,
}: ViewerUrlOption,
{ cmykReserveMapUrl }: { cmykReserveMapUrl?: string } = {},
): string {
Expand All @@ -92,14 +94,14 @@ export function getViewerParams(
if (customStyle) {
const param = isValidUri(customStyle)
? customStyle
: upath.posix.join(base, customStyle);
: new URL(upath.posix.join(base, customStyle), rootUrl).href;
viewerParams += `&style=${escapeParam(param)}`;
}

if (customUserStyle) {
const param = isValidUri(customUserStyle)
? customUserStyle
: upath.posix.join(base, customUserStyle);
: new URL(upath.posix.join(base, customUserStyle), rootUrl).href;
viewerParams += `&userStyle=${escapeParam(param)}`;
}

Expand Down Expand Up @@ -211,7 +213,7 @@ export async function getViewerFullUrl({
sourceUrl === EMPTY_DATA_URI
? undefined // open Viewer start page
: sourceUrl,
{ base, ...config },
{ base, rootUrl, ...config },
{ cmykReserveMapUrl },
);
viewerUrl.hash = '';
Expand Down
28 changes: 28 additions & 0 deletions tests/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,34 @@ describe('vite-plugin-browser', () => {
});
});

it('launches external viewer with custom style URLs', async () => {
const server = (await runCommand(
[
'preview',
'--viewer',
'https://example.com',
'--style',
'theme.css',
'--user-style',
'theme.css',
],
{
cwd: resolveFixture('server'),
config: {
entry: 'main.md',
workspaceDir: '.vs-browser-external-viewer-style',
},
},
)) as ViteDevServer;
assert(server.resolvedUrls);
expect(launchPreviewSpy).toHaveBeenCalledOnce();
const { url } = launchPreviewSpy.mock.calls[0][0];
expect(parseUrlParams(url)).toMatchObject({
style: `${server.resolvedUrls.local[0]}vivliostyle/theme.css`,
userStyle: `${server.resolvedUrls.local[0]}vivliostyle/theme.css`,
});
});

it('launches epub-opf input', async () => {
const server = (await runCommand(
['preview', '../epubs/adaptive/OPS/content.opf'],
Expand Down