-
Notifications
You must be signed in to change notification settings - Fork 160
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
MWPW-123745 SVG alt text #401
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -335,13 +335,24 @@ export async function loadBlock(block) { | |||||
|
||||||
export function decorateSVG(a) { | ||||||
const { textContent, href } = a; | ||||||
const ext = textContent?.substr(textContent.lastIndexOf('.') + 1); | ||||||
const altTextFlagIndex = textContent.indexOf('|'); | ||||||
const sanitizeTextContent = altTextFlagIndex === -1 | ||||||
? textContent | ||||||
: textContent?.slice(0 ,altTextFlagIndex).trim(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor spacing issue. Is your eslint working?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I thought it was. Looks like I need to double check. |
||||||
const ext = sanitizeTextContent?.substring(sanitizeTextContent.lastIndexOf('.') + 1); | ||||||
if (ext !== 'svg') return; | ||||||
|
||||||
const altText = altTextFlagIndex === -1 | ||||||
? '' | ||||||
: textContent.substring(textContent.indexOf('|') + 1).trim(); | ||||||
const textContentUrl = new URL(sanitizeTextContent); | ||||||
const hrefUrl = new URL(href); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. Thanks for the feedback @meganthecoder! |
||||||
const img = document.createElement('img'); | ||||||
img.src = localizeLink(textContent); | ||||||
img.src = localizeLink(sanitizeTextContent); | ||||||
img.alt = altText; | ||||||
const pic = document.createElement('picture'); | ||||||
pic.append(img); | ||||||
if (img.src === href) { | ||||||
if (textContentUrl.pathname === hrefUrl.pathname) { | ||||||
a.parentElement.replaceChild(pic, a); | ||||||
} else { | ||||||
a.textContent = ''; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually verbs are for functions. Would
sanitizedTextContent
be more appropriate?