-
Notifications
You must be signed in to change notification settings - Fork 529
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
img: add width and height #351
base: lib
Are you sure you want to change the base?
Conversation
This complies with HTML5 standards and let browser plan for the area to reserve to image before they load. If provided, it allows us to enable native browser lazy loading for performance.
I'm not sure whether a |
I'm pretty sure the
In short, this needs to be 1. optional, 2. off by default, and 3. the strategy for getting this information should be customizable so that you can substitute direct filesystem checks/HTTP requests for something appropriate for other use cases. I suggest adding an optional callback to get this data like there is currently It could make sense for the callback to be able to return an arbitrary list of attributes. This would allow other things, for instance adding a srcset attribute with images at various resolutions. |
The remaining question is how the The need for But Markdown has no way for the writer to specify them manually, and even if it had, it is actually cumbersome, which defeats the purpose of Markdown at all. So, all in all, that needs to be done somehow programmatically but, from what you are saying, at least a manual fallback is needed too (and perhaps the relevant Markdown syntax extension). Before going any further in the implementation technicalities, I think that's the first design concern to address. What about something like |
I think whether we have a syntax for expressing width and height in the text is independent of whether we have a way to make that automatic. I'm not sure why one would depend on the other, they are independent issues. All I'm saying is the parser can't decide by itself to fetch files while parsing. This would be unexpected performance-wise and a security risk in many places PHP Markdown is used. So fetching files can't be enabled by default. My suggestion is simply to have a configurable hook to provide the width and height information, as well as other attributes. That hook, a callback function, is not part of PHP Markdown: it's supplied by the "user" of the library and can get the attributes in whatever way the user wants. |
Having an uniform workflow to handle them, if both manual and auto strategies are required, before starting implementation, is saner than jumping head-first into code, and try to retro-fit the manual fallback later. I'm too old to make that mistake again, at least.
That's fair. But I don't understand what other attributes and how they are supposed to be found. Like, for the |
I don't mind discussing a syntax, but I don't see it as a prerequisite. Thinking of it, we already have special attributes blocks in
We could comme with a more elegant syntax for this if needed. Something like
Resized images names often follow a convention, like there could be a thumbnail with a "thumb." prefix or a double-sized version with a "-2x" suffix. Or perhaps a query to a CMS database can tell you what the size of the image is and list all its declinations without having to load any of them (obviously only applicable to URLs managed by your own CMS). Hence the callback: who writes a callback will adapt it to the situation. |
I have found 3 implementations that support
Ok, got it. So I can give it a start if you are ok with this feature (I just don't want to invest time into a dead-end). |
showdown has this syntax too. You can go ahead, syntax & callback. Both are conceptually approved. 👍 |
What about query string in URL? |
@taufik-nurrohman A query string creates the expectation the server will handle the resize, not the browser. While it's true the resize could happen server-side, in pretty much all cases it won't. I'd rather have syntax that does not create such expectations and is also nicer and less heavy. I suppose the image size from this syntax could inform a callback hook ( |
This complies with HTML5 standards and let browser plan for the area to reserve to images before they load.
If provided, it allows us to enable native browser lazy loading for performance.