simonhaenisch / md-to-pdf

Hackable CLI tool for converting Markdown files to PDF using Node.js and headless Chrome.
https://www.npmjs.com/md-to-pdf
MIT License
1.16k stars 111 forks source link

feature: Support Github Markdown "Alerts" #310

Open Sajjon opened 3 weeks ago

Sajjon commented 3 weeks ago

Problem:

Seems this (great) tool does not support Github Markdown "alerts", at least not without any extra options?

Solution:

Would be excellent to support it! Since "Alerts" are so fancy and getting traction amongst repos on Github.

simonhaenisch commented 3 weeks ago

Hm might just be an issue with how outdated the marked version I use is 🙈 I've been wanting to update it for a long while. l'll try to get to it this week.

In the meantime you can check whether markedjs/marked actually supports this at all?

Sajjon commented 3 weeks ago

In the meantime you can check whether markedjs/marked actually supports this at all?

Looks like it, see https://github.com/markedjs/marked/issues/3010 which references an extension on marked, https://github.com/bent10/marked-extensions/tree/main/packages/alert

can you use those, extensions on marked??

simonhaenisch commented 2 weeks ago

Yeah you can, but i also have an open issue about it 🙈 (#292)

You'd need to use a md-to-pdf.config.js file (can name it whatever you want) and pass that to the CLI with --config-file ./md-to-pdf.config.js flag, then you can use it to configure marked_extensions, sth like:

const markedAlert = require('marked-alert')

module.exports = {
  // ... other config
  marked_extensions: [markedAlert],
}

But the way marked_extensions is passed to the Marked instance is not aligned with their new .use() API interface, so I can't guarantee this actually works until #292 is solved. Maybe just give it a try and if it doesn't work it gives me some motivation to finally fix this (: