Skip to content

Commit 4d78da5

Browse files
authored
fix: exporting pdf style (#223)
1 parent 4497634 commit 4d78da5

File tree

6 files changed

+31
-13
lines changed

6 files changed

+31
-13
lines changed

.changeset/red-spiders-wonder.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@alauda/doom": patch
3+
"@alauda/doom-export": patch
4+
---
5+
6+
fix: exporting pdf style

packages/doom/src/cli/export.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ export const exportCommand = new Command('export')
119119
localStorage.setItem('rspress-visited', '1')
120120
},
121121
],
122-
outlineContainerSelector: '.rspress-doc',
122+
outlineContainerSelector: '.rp-doc',
123+
outlineExcludeSelector: '.rp-toc-exclude *',
123124
},
124125
}
125126

packages/doom/src/plugins/auto-toc/remark-auto-toc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const remarkAutoToc: Plugin<[], Root> = function () {
3232
{
3333
type: 'mdxJsxAttribute',
3434
name: 'className',
35-
value: 'doom-auto-toc rspress-toc-exclude',
35+
value: 'doom-auto-toc rp-toc-exclude',
3636
},
3737
],
3838
children: [

packages/doom/styles/global.scss

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,24 @@ td {
137137
}
138138

139139
@mixin print {
140-
.rspress {
140+
.rp {
141141
&-nav,
142-
&-sidebar-menu,
143-
&-doc-footer {
142+
&-doc-layout__menu,
143+
&-doc-footer,
144+
&-doc-layout__sidebar {
144145
display: none;
145146
}
146147

147-
&-doc-container {
148+
&-doc-layout__doc-container {
148149
padding: 0;
150+
// https://github.com/web-infra-dev/rspress/issues/2909
151+
min-height: unset;
149152
}
150153

151-
&-directive-title::marker {
152-
content: none;
154+
&-toc-item--active .rp-toc-item__text {
155+
color: var(--rp-c-text-2);
153156
}
154157
}
155-
156-
[class^='scroll-to-top_'] {
157-
display: none;
158-
}
159158
}
160159

161160
.print:root {

packages/export/src/html-export-pdf/core/outline.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ export async function getOutlineNodes(
7373
page: Page,
7474
tags: string[],
7575
outlineContainerSelector = '',
76+
outlineExcludeSelector = '',
7677
) {
7778
const preSelector = formatOutlineContainerSelector(outlineContainerSelector)
7879
return await page.evaluate(
79-
([tags, outlineSelector]) => {
80+
([tags, outlineSelector, outlineExcludeSelector]) => {
8081
const tagsToProcess = Array.from(
8182
document.querySelectorAll<HTMLElement>(outlineSelector),
8283
).reverse()
@@ -85,6 +86,7 @@ export async function getOutlineNodes(
8586
depth: -1,
8687
parent: undefined,
8788
}
89+
8890
let currentOutlineNode = root
8991

9092
const linkHolder = document.createElement('div')
@@ -94,6 +96,11 @@ export async function getOutlineNodes(
9496

9597
while (tagsToProcess.length > 0) {
9698
const tag = tagsToProcess.pop()!
99+
100+
if (outlineExcludeSelector && tag.matches(outlineExcludeSelector)) {
101+
continue
102+
}
103+
97104
const orderDepth = tags.indexOf(tag.tagName.toLowerCase())
98105
const dest = encodeURIComponent(tag.id)
99106

@@ -143,6 +150,7 @@ export async function getOutlineNodes(
143150
[
144151
tags,
145152
tags.map((titleItem) => `${preSelector}${titleItem}`).join(','),
153+
outlineExcludeSelector,
146154
] as const,
147155
)
148156
}

packages/export/src/html-export-pdf/core/printer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface PrinterOptions {
3838
emulateMedia?: null | 'screen' | 'print'
3939
enableWarnings?: boolean
4040
outlineContainerSelector?: string
41+
outlineExcludeSelector?: string
4142
}
4243

4344
export class Printer extends EventEmitter {
@@ -58,6 +59,7 @@ export class Printer extends EventEmitter {
5859
private emulateMedia: 'screen' | 'print'
5960
private enableWarnings: boolean
6061
private outlineContainerSelector: string
62+
private outlineExcludeSelector: string
6163

6264
private browser?: Browser
6365
private browserContext?: BrowserContext
@@ -92,6 +94,7 @@ export class Printer extends EventEmitter {
9294
this.emulateMedia = options.emulateMedia ?? 'print'
9395
this.enableWarnings = options.enableWarnings ?? false
9496
this.outlineContainerSelector = options.outlineContainerSelector ?? ''
97+
this.outlineExcludeSelector = options.outlineExcludeSelector ?? ''
9598

9699
if (this.debug) {
97100
this.headless = false
@@ -269,6 +272,7 @@ export class Printer extends EventEmitter {
269272
page,
270273
this.outlineTags,
271274
this.outlineContainerSelector,
275+
this.outlineExcludeSelector,
272276
)
273277
setOutlineNodes(pdfDoc, outlineNodes, this.enableWarnings)
274278
}

0 commit comments

Comments
 (0)