privateOmega / html-to-docx

HTML to DOCX converter
MIT License
373 stars 140 forks source link

TypeError: Cannot read properties of null (reading '2') #211

Open Prashant15062019 opened 1 year ago

Prashant15062019 commented 1 year ago

index.txt

I am getting Type error while converting the HTML text

Env Node v16 OS: Mac Library version: 1.8.0

xgg94 commented 8 months ago

I get the same error, did you find a solution?

Prashant15062019 commented 8 months ago

no but what i did was first convert it to pdf and then to html file

LancerComet commented 4 months ago

This is because during the processing of the image, a certain edge case involving the image's URL occurred, causing the library to treat URLs that are not base64 as base64, such as relative paths starting with /.

The solution is to replace the image's URL with an absolute path, or manually download the image, generate its base64 and use it as the src in the corresponding img element.

LancerComet commented 4 months ago

I see there are some src attributes that start with "/media/" in your index.txt, which cause the exception. You have to convert them into base64 manually.

An example:

image