GithubHelp home page GithubHelp logo

Comments (4)

simonhaenisch avatar simonhaenisch commented on June 15, 2024 1

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).

from md-to-pdf.

invisiblegaudi avatar invisiblegaudi commented on June 15, 2024

willing to do the work for this

from md-to-pdf.

invisiblegaudi avatar invisiblegaudi commented on June 15, 2024

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

from md-to-pdf.

simonhaenisch avatar simonhaenisch commented on June 15, 2024

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).

from md-to-pdf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.