crosstype / node-html-markdown

Fast HTML to markdown converter for NodeJS or the browser
171 stars 28 forks source link

[Feature] Add Cloudflare Support #42

Open nadecancode opened 2 years ago

nadecancode commented 2 years ago

Looks like Cloudflare Worker does not like process, is it possible to remove these queries so it can support Cloudflare Worker?

nonara commented 2 years ago

Looks like process is only used to get env vars.

If you'd like to try a PR, here's what should work:

  1. Create a utility function named tryGetEnvVar that does return process && process.env[varName];

  2. Replace process.env references with calls to the new utility function

Note: for the transform.js file, you'd have to embed the logic directly, as you can't import.

  1. Build a version and try it with CloudFlare

If it works, open a PR and I'll get it through!

SettingDust commented 1 year ago

Can you tell me how you import this lib in your worker? In my knowledge, cf don't support nodejs.

nonara commented 1 year ago

https://blog.cloudflare.com/node-js-support-cloudflare-workers/

Looks like it's a sandbox. They recommend webpack.

I'm wondering if your new build would work as is due to having a browser build.

SettingDust commented 1 year ago

blog.cloudflare.com/node-js-support-cloudflare-workers

Looks like it's a sandbox. They recommend webpack.

I'm wondering if your new build would work as is due to having a browser build.

It's should work if he import the browser bundle

alexturpin commented 11 months ago

I was trying to find something like this for CloudFlare too, but I think the way to go will be through the HTMLRewriter API

TranquilMarmot commented 9 months ago

My PR ☝️ fixes this library to work in Cloudflare workers.

jca41 commented 7 months ago

Would be great to get the above PR merged!

jca41 commented 7 months ago

I've published the above pr (similar changes) here https://www.npmjs.com/package/node-html-markdown-cloudflare, if you can't wait to use this on Cloudflare 😄