Skip to content

Commit

Permalink
Export PDF through print. (#1065)
Browse files Browse the repository at this point in the history
Add print button for markdown panel
  • Loading branch information
ruibinx authored Aug 28, 2024
1 parent fed9965 commit bddb1b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
18 changes: 17 additions & 1 deletion plugs/markdown/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export async function updateMarkdownPreview() {
},
});
const customStyles = await editor.getUiOption("customStyles");
const toolbar = renderToolbar();
await editor.showPanel(
"rhs",
2,
Expand All @@ -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);
Expand Down
20 changes: 19 additions & 1 deletion web/styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,22 @@ body {
padding: 0;
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;
}

0 comments on commit bddb1b5

Please sign in to comment.