Export PDF through print. (#1065)

Add print button for markdown panel
pull/1081/head
Ruibin Xing 2024-08-28 23:32:29 +08:00 committed by GitHub
parent fed9965a99
commit bddb1b5da9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 2 deletions

View File

@ -35,6 +35,7 @@ export async function updateMarkdownPreview() {
},
});
const customStyles = await editor.getUiOption("customStyles");
const toolbar = renderToolbar();
await editor.showPanel(
"rhs",
2,
@ -45,12 +46,27 @@ export async function updateMarkdownPreview() {
${customStyles ?? ""}
</style>
<div id="root" class="sb-preview">${html}</div>
<div id="root" class="sb-preview">${toolbar}${html}</div>
`,
js,
);
}
function renderToolbar(): string {
return `<div class="sb-markdown-toolbar">
<button onClick="window.print()">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
class="feather feather-printer">
<polyline points="6 9 6 2 18 2 18 9"/>
<path d="M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2"/>
<rect x="6" y="14" width="12" height="8"/>
</svg>
</button>
</div>`;
}
export async function previewClickHandler(e: any) {
const [eventName, arg] = JSON.parse(e);
// console.log("Got click", eventName, arg);

View File

@ -227,3 +227,21 @@ body {
margin: 0;
}
}
.sb-preview {
position: relative;
}
.sb-markdown-toolbar {
position: absolute;
opacity: 0;
transition: opacity 0.2s;
width: 100%;
display: flex;
justify-content: flex-end;
box-sizing: border-box;
}
.sb-markdown-toolbar:hover {
opacity: 1;
}