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.15k stars 110 forks source link

feature: embedded instagram posts #233

Open invisiblegaudi opened 1 year ago

invisiblegaudi commented 1 year ago

Problem:

Related to #122

When outputting HTML, it is desirable to embed instagram posts rather than have a link to them taking the reader away from the page.

Solution:

I would like to have a flag e.g. --embed-socials to add the necessary HTML and js to embed any urls to instagram posts

invisiblegaudi commented 1 year ago

willing to do the work for this

simonhaenisch commented 1 year ago

Two ideas to solve this without having to do any changes to md-to-pdf:

const renderer = {
  link(string href, string title, string text) {
    const url = new URL(href)

    if (url.hostname === 'instagram.com') {
      // do sth fancy here that returns html to embed the post, could even fetch the html content here
      return <div>...</div>
    }

    return false // default renderer kicks in
  }
}

For the latter one it would be really useful to finally finish the stuff around the marked.use API, i.e. allowing to configure Marked plugins/extensions via the config, which is mainly about finishing #228 and #140. Sadly I didn't really find any time to work on it (I also don't have any sponsors for this project so it's hard for me to justify spending much time on it).

invisiblegaudi commented 1 year ago

Ok, i'll have a dig around and see if I can locate a suitable renderer, i.e. option 2. Save that, I can come up with a custom script i.e. option 1... there isn't any mention of a script config entry in the docs, maybe there should be? Also, a template for such a script would be useful, if I go with 1, maybe I can provide this

simonhaenisch commented 1 year ago

You're right, it's missing from the docs, but it's there in the types:

https://github.com/simonhaenisch/md-to-pdf/blob/95502c5b15aa56d781af00610c1a86fd6ee9405a/src/lib/config.ts#L85-L90

Using --script flag should also work (same as --stylesheet/stylesheet option).