-
Notifications
You must be signed in to change notification settings - Fork 135
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
Added img attribute caching to ExpensiMark #808
Conversation
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.
Thanks for adding the unit tests, that is very reassuring. My main question before approving is to make sure to understand the regex changes
replacement: (_extras, _match, _g1, g2, _g3, g4) => { | ||
if (g4) { | ||
return `![${g4}](${g2})`; | ||
regex: /<img[^><]*src\s*=\s*(['"])(.*?)\1(.*?)>(?![^<][\s\S]*?(<\/pre>|<\/code>))/gi, |
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.
Can you please "breakdown" the regex changes you made here? I see you have taken out the altRegex, but I can also see some other changes in latter part of the regex
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.
- removed
(?:[^><]*alt\s*=\s*(['"])(.*?)\3)?
in favor of(.*?)
to capture all attributes after src (including alt) - simplified closing tag matching (
[^><]*>*
to(.*?)>
and that's pretty much it.
Asked Rushat for testing on this PR https://expensify.slack.com/archives/C02NK2DQWUX/p1727359643953779 |
Co-authored-by: Vit Horacek <36083550+mountiny@users.noreply.github.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.
Thanks! @rushatgabhane have you been able to test it?
yeah, gimme a moment for checklist |
@mjasikowski im not able to build this. Could you please help me out? I tried:
I also tried directly installing the branch to
|
@rushatgabhane I had a similar problem and couldn't figure it out (troubles with |
That worked, thank you! |
@mjasikowski so im having a few issues with opening the image. Steps i followed
Expected: Image loads. I am able to load the image if I don't edit its text. i.e. skip step 3. Screen.Recording.2024-09-28.at.18.mp4 |
@rushatgabhane thanks for testing, I'll take another look on Monday - it may be that we need a small API addition. |
It seems that the API also strips the tags, so that is fixed with https://github.com/Expensify/Web-Expensify/pull/43729 |
alright, understood |
@rushatgabhane the backend PR is now deployed to production, so this is no longer held and ready for testing |
WebScreen.Recording.2024-10-07.at.07.05.34.movMobileScreen.Recording.2024-10-07.at.07.26.15.mov |
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.
LGTM
I will just move this ahead now |
🚀Published to npm in v2.0.97 |
This PR adds caching for additional attributes to the
<img>
tags when converted to and back from Markdown.Due to naming weirdness (current cache fields are named
videoAttributeCache
andcacheVideoAttributes
), new fields were created on theExtras
object:mediaAttributeCachingFn
replacingcacheVideoAttributes
mediaAttributeCache
replacingvideoAttributeCache
Replaced fields are marked as deprecated in JS doc and will be removed after this PR is deployed and NewDot is modified so it doesn't use the deprecated fields anymore.
Logic-wise, only the deprecated properties and the new ones won't ever be used simultanously, hence caching function selection is done by detecting the presence of either deprecated or new fields.
https://github.com/Expensify/Web-Expensify/pull/43729 needs to be merged first for App tests to be doable.
Fixed Issues
Expensify/App#42206
Tests
Added tests to ExpensiMark-HTML-test.js and ExpensiMark-Markdown-test.js to test the conversion logic.
Added tests to ExpensiMark-test.js to test caching function selection logic.
QA
After this is deployed, test in NewDot: