Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: embedded instagram posts #233

Open
invisiblegaudi opened this issue Jul 29, 2023 · 4 comments
Open

feature: embedded instagram posts #233

invisiblegaudi opened this issue Jul 29, 2023 · 4 comments
Labels

Comments

@invisiblegaudi
Copy link

invisiblegaudi commented Jul 29, 2023

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
Copy link
Author

willing to do the work for this

@simonhaenisch
Copy link
Owner

simonhaenisch commented Jul 30, 2023

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

  • a custom .js script that does the embedding within the page which you either set with the script config, or add to the end of the markdown content (you can just add <script> tag in the markdown); any sync handlers that you attach to the load or DOMContentLoaded event would automatically be awaited; if it's async with network requests, i think it should also work because of this:

    page.waitForNavigation({ waitUntil: 'networkidle0' }),

  • set a custom Marked renderer (https://marked.js.org/using_pro#renderer) to do the transformation, e.g. overwrite the link method, sth like:

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
Copy link
Author

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
Copy link
Owner

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

/**
* List of scripts to load into the page.
*
* @see https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pageaddscripttagoptions
*/
script: FrameAddScriptTagOptions[];

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants