-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix: alt error mix with height/width #730
Conversation
More granular detection of alt and resize in image
can you run |
quartz/plugins/transformers/ofm.ts
Outdated
const dims = alias?.match(/^\d+(x\d+)?|\|\d+(x\d+)/) ? alias.match(/^\d+(x\d+)?|\|\d+(x\d+)/)![0] : "" | ||
const alt = alias?.replace(dims, "")?.trim() |
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.
This would allow you to capture all the possible things in one match and return easier to identify groups.
const imgregex = new RegExp(
// Test future changes https://rubular.com/r/KK6cVpqABINEfQ
// Look for alt
'^' + // Start from the beginning
'(?<alt>' + // Start a named group for alt
'(?!^\d+$)' + // This look ahead makes sure this isn't just digits
'.*?' + // This searches for any character lazily.
')?' + // Close the group. The '?' means it may not be there.
// Search for digits
'(' + // Group the digits together
'\|?' + // It may be proceeded by a pipe
'\s+?' + // Handle any number of spaces after
'(?<width>\d+)' + // Start a name group for width
'(x(?<height>\d+))?' + // Height would require a 'x'. The '?' means it may not be given
')?' + // Close the digits w/ a '?' becuase it could only be alt text.
'$' // Look until the end of the line
)
const matches= alias?.match(imgregex)
const width = matches.width ||= "auto"
const height= matches.height ||= "auto"
const alt= matches.alt ||= "auto"
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.
Failed to process content/Compendium/Ambre Loiseau.md
: Invalid regular expression: /^(?(?!^d+$).*?)?(|?s?+(?d+)(x(?d+))?)?$/: Nothing to repeat
Tested in JS console and same error appear. Seams the regex have some problem in TS/JS
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.
@HeyItsGilbert ruby has a different regex engine from js, you might need to modify it (and test on https://regex101.com/)
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.
Regex is valid but looks like capture groups aren't supported. https://www.regular-expressions.info/javascript.html
I'll give a different version when I have some time to update it.
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.
Capture group are supported: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Named_capturing_group
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.
Seems this: https://regex101.com/r/lKh0xu/1 should works
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.
This might be because I escaped characters to support /.../
syntax. That may not be needed for new RegEsp()
.
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.
I think I found it. https://regex101.com/r/C8jPll/1
'\s?+' + // Handle any number of spaces after
Should be.
'\s+?' + // Handle any number of spaces after
The +?
combo makes it 0 or more
and the ?
makes it optional. I think Javascript didn't like the alternative while other languages accept it. I updated the code above.
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.
This regex would allow a single match and returns capture groups. The rubular links shows a few test cases we tried on discord.
superseded by 211f95c |
Hello, this doesn't fix the current issue and the alt continue to be considered as width… |
More granular detection of alt and resize in image
This was previously discuted into the discord troubleshooting channel.
Normally it shoulds support and detect size and alt text.