PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.16k stars 2.68k forks source link

Add a method to TemplateProcessor for rendering HTML content.Include Image #2547

Open Maybe-U opened 5 months ago

Maybe-U commented 5 months ago

Description

Add a method to TemplateProcessor for rendering HTML content. support image

Fixes 1

coveralls commented 5 months ago

Coverage Status

coverage: 97.192% (-0.03%) from 97.217% when pulling aabbc3cbc0597f479fc087aade64ae1b74755f50 on Maybe-U:feature/render-html into 41cf4ebddb6457ab20552630c27e33e2715dcfe9 on PHPOffice:master.

oleibman commented 5 months ago

@Maybe-U You asked me to review. The code looks okay to me, but I'm really not all that familiar with TemplateProcessor, so it needs someone more knowledgeable to review. However, your test may have a problem. Does it actually attempt to read your external images? If the answer is no, there's no problem. If the answer is yes, I'll add some more comments.

Maybe-U commented 5 months ago

@Maybe-U You asked me to review. The code looks okay to me, but I'm really not all that familiar with TemplateProcessor, so it needs someone more knowledgeable to review. However, your test may have a problem. Does it actually attempt to read your external images? If the answer is no, there's no problem. If the answer is yes, I'll add some more comments. @oleibman Thank you very much for your response. My test cases only verified the generation of the DOCX file and did not check the actual content. However, in reality, it is possible to read external or local images, so my answer is yes. this is html content

image

this is output docx file

image

@Progi1984 can you review my code thanks you

oleibman commented 5 months ago

My testing indicates that your test does attempt to load image https://t7.baidu.com/it/u=4198287529,2774471735&fm=193&f=GIF and will fail if it is not available; that is probably true of your second image as well. The problem is that external files tend to move or be deleted over time, and, when (not if) that happens, the unit test suite will fail. To avoid this problem, I think you might be able to use AbstractWebServerEmbeddedTest so that the requests are routed to localhost rather than an external site. Again, I'm not all that familiar with it, but there are a lot of tests that use it (e.g. HtmlTest).

Maybe-U commented 5 months ago

My testing indicates that your test does attempt to load image https://t7.baidu.com/it/u=4198287529,2774471735&fm=193&f=GIF and will fail if it is not available; that is probably true of your second image as well. The problem is that external files tend to move or be deleted over time, and, when (not if) that happens, the unit test suite will fail. To avoid this problem, I think you might be able to use AbstractWebServerEmbeddedTest so that the requests are routed to localhost rather than an external site. Again, I'm not all that familiar with it, but there are a lot of tests that use it (e.g. HtmlTest). @oleibman i am Optimize test cases and handle image loading failures in setHtmlBlock function please have a review thanks!