Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alt tags for images (my solution included) #124

Open
JBJBEnoit opened this issue Jul 16, 2024 · 0 comments
Open

Alt tags for images (my solution included) #124

JBJBEnoit opened this issue Jul 16, 2024 · 0 comments

Comments

@JBJBEnoit
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant