In this section, we are going to introduce support for PDF generation based on the markdown source. Once we've finished, the users of our application should be able to generate PDF output with Cmd + Alt + P on macOS and Ctrl + Alt + P on other systems.
Let's update the code in order to provide PDF output support:
- Edit the Editor.js component so that it supports another keyboard combination:
editor.addCommand(
monaco.KeyMod.CtrlCmd | monaco.KeyMod.Alt | monaco.KeyCode.KEY_P,
() => {
const code = editor.getModel().getValue();
generatePDF(code);
}
);
The generatePDF function implementation should be reasonably easy for you. It resembles the genereateHTML one, but in our case, we're passing pdf as a format attribute.
- Add the following function to the Editor.js code:
const generatePDF = contents => {
if...