Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add scale arg for image export (#1263) #1274

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/slidev/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ function exportOptions<T>(args: Argv<T>) {
type: 'boolean',
describe: 'slide slides slide by slide. Works better with global components, but will break cross slide links and TOC in PDF',
})
.option('scale', {
type: 'number',
describe: 'scale factor for image export',
})
}

function printInfo(
Expand Down
6 changes: 5 additions & 1 deletion packages/slidev/node/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ExportOptions {
* @default false
*/
perSlide?: boolean
scale?: number
}

function addToTree(tree: TocItem[], info: SlideInfo, slideIndexes: Record<number, number>, level = 1) {
Expand Down Expand Up @@ -161,6 +162,7 @@ export async function exportSlides({
executablePath = undefined,
withToc = false,
perSlide = false,
scale = 1,
}: ExportOptions) {
const pages: number[] = parseRangeString(total, range)

Expand All @@ -174,7 +176,7 @@ export async function exportSlides({
// Calculate height for every slides to be in the viewport to trigger the rendering of iframes (twitter, youtube...)
height: perSlide ? height : height * pages.length,
},
deviceScaleFactor: 1,
deviceScaleFactor: scale,
})
const page = await context.newPage()
const progress = createSlidevProgress(!perSlide)
Expand Down Expand Up @@ -449,6 +451,7 @@ export function getExportOptions(args: ExportArgs, options: ResolvedSlidevOption
executablePath,
withToc,
perSlide,
scale,
} = config
outFilename = output || options.data.config.exportFilename || outFilename || `${path.basename(entry, '.md')}-export`
if (outDir)
Expand All @@ -468,6 +471,7 @@ export function getExportOptions(args: ExportArgs, options: ResolvedSlidevOption
executablePath,
withToc: withToc || false,
perSlide: perSlide || false,
scale: scale || 1,
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/types/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface ExportArgs extends CommonArgs {
'executable-path'?: string
'with-toc'?: boolean
'per-slide'?: boolean
scale?: number
}

export interface BuildArgs extends ExportArgs {
Expand Down