PHPWord icon indicating copy to clipboard operation
PHPWord copied to clipboard

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

Open Maybe-U opened this issue 1 year ago • 6 comments

Description

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

Fixes 1

  • https://github.com/PHPOffice/PHPWord/issues/1615
  • https://github.com/PHPOffice/PHPWord/issues/110

Maybe-U avatar Jan 10 '24 10:01 Maybe-U

Coverage Status

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

coveralls avatar Jan 10 '24 10:01 coveralls

@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 avatar Jan 10 '24 17:01 oleibman

@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

Maybe-U avatar Jan 11 '24 03:01 Maybe-U

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 avatar Jan 11 '24 17:01 oleibman

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!

Maybe-U avatar Jan 13 '24 17:01 Maybe-U