Repository navigation
Fix/handle img tags - #3640
Fix/handle img tags#3640g14a wants to merge 4 commits into
Conversation
mislav
left a comment
There was a problem hiding this comment.
Thanks for taking this on!
| # install -d ${DESTDIR}${mandir}/man1 | ||
| # install -m644 ./share/man/man1/* ${DESTDIR}${mandir}/man1/ |
There was a problem hiding this comment.
oops my bad yes accidental edit
| "login": "g14a" | ||
| }, | ||
| "authorAssociation": "CONTRIBUTOR", | ||
| "body": "@vilmibm @ampinsk I tried solving this. Issues and PRs look like the following respectively. Does it look okay or can it be better from a design perspective?\n## Issues: \n<img width=\"854\" alt=\"image\" src=\"https://user-images.githubusercontent.com/17702388/113286902-6ea20500-930a-11eb-8860-754107c67b22.png\">\n## PRs:\n<img width=\"854\" alt=\"image\" src=\"https://user-images.githubusercontent.com/17702388/113286974-8c6f6a00-930a-11eb-98da-41e159056438.png\">\nDo you want to take a look at the PR which fixes this?", |
There was a problem hiding this comment.
Since you've only edited the Render function and nothing else in the codebase, let's make a test that exercises only the Render function and not the entire issue view. This test has a lot of setup just to exercise one tiny piece of changed functionality.
|
|
||
| func formatImgTags(content string) string { | ||
| lines := strings.Split(content, "\n") | ||
| re := regexp.MustCompile(`<img[^>]+\bsrc=["']([^"']+)["']`) |
There was a problem hiding this comment.
This part is getting tricky because you're basically doing HTML parsing without writing a full-fledged HTML parser. Note that attribute values such as src=VALUE don't necessarily have to be closed in quotes. Furthermore, images can have text in the alt attribute, which would be important to parse out and preserve. Finally, an <img> tag can be surrounded by regular content (like hello <img src="..."> world!), so we can't just assume that an <img> tag will always be on its own line and that the rest of the content can be discarded. Let's only replace the <img...> portion within the original content with the  syntax and preserve everything else.
There was a problem hiding this comment.
Additionally this doesn't handle image tags in code blocks which was the issue with our initial emoji rendering solution. Overall, I think we should be adding this feature into the upstream glamour library instead of here. @mislav what do you think?
There was a problem hiding this comment.
Oh yeah 🤦 excellent point @samcoe. I do agree that this should be handled at the level that parses Markdown (so, in Glamour) rather than with regexp matching.
There was a problem hiding this comment.
It sounds like the glamour team is uninterested in handling HTML: charmbracelet/glamour#111 (comment)
If that is the case, we may want to consider an alternative to glamour in the long run.
I'm going to mark this PR as a draft so we can continue discussion.
| for i, line := range lines { | ||
| images := re.FindAllStringSubmatch(line, -1) | ||
| for _, element := range images { | ||
| lines[i] = fmt.Sprintf("", element[1]) |
There was a problem hiding this comment.
Instead of the text Image there should be the alt text parsed from the <img> tag. If the alt text was blank, then this text should be blank as well (). This is important for accessibility. A hardcoded alt text that just says Image hurts accessibility because it is not useful.
|
Closing this until we decide on a more holistic approach to this issue. |
This commit renders img tags in issue and pr previews.
Fixes #229