Alt tags for images (my solution included)
Opened this issue · 0 comments
Hi, thanks for this awesome package. I noticed when using it that it does not grab the alt text from the Word doc into the HTML img element, so I edited the code to do so.
In the DocumentParser.parsePicture() method, at line 1080, I changed the result object to include an altText prop:
var result = { type: dom_1.DomType.Image, src: "", cssStyle: {}, altText: "" };
... then at line 1086 I added the following three lines to grab the alt text from the .docx file:
var nvPicPr = xml_parser_1.default.element(elem, "nvPicPr"); var cNvPr = xml_parser_1.default.element(nvPicPr, "cNvPr"); result.altText = xml_parser_1.default.attr(cNvPr, "descr");
Finally, in the HtmlRenderer.renderImage() method at line 3088, I added the new prop in the call to createElement():
let result = this.createElement("img", {alt: elem.altText});
Hopefully, this is something you can use! Thanks again!