-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Image Resize via Reference #723
Comments
I would do the query string method instead. And use that queries to update the image markup before it is being removed. $data = $Inline['element']['attributes']['src'];
$a = explode('?', $data, 2); // Result: ['.path/to/image.jpg', 'width=72&height=72']
if (isset($a[1])) {
parse_str($a[1], $attr);
$Inline['element']['attributes'] = array_replace($Inline['element']['attributes'], $attr);
$Inline['element']['attributes']['src'] = $a[0];
}
return $Inline; Or use literal attribute syntax using my extension like this:  {width=72 height=72} |
@tovic
I'm looking for ways to extend such syntax of reference image, to something like:
However, if I understood properly, the method you've posted would create an additional syntax for inline images instead for reference images:
If this is indeed the case, unfortunately it doesn't address the issue of the OP.
Do you agree? |
No sir. My code utilize the URL query from the image itself. So, no need to invent new syntax: 1. Inline Image

2. Reference Image
![Markdown Logo][image]
[image]: /md.png?width=100&height=100 "You can still add title here too" It also backward-compatible to other parsers. So, if you decided to use another markdown parser, the automatic [Test Image](./path/to/image.png#100x100) And get the image dimension from: $dimension = explode('#', $Inline['element']['attributes']['src'], 2)[1] ?? "";
if (preg_match('/\d+x\d+/', $dimension)) { ... } |
Ok, this syntax is fine for me too. Moreover, I agree with you that there are several advantages using it instead of the one I posted in the OP. The only thing still not clear to me is what would be your proposal for the alternative reference image? Are you considering something like:
Correct? |
I don’t know. Your style is better IMO. It just that I feel a bit wrong in adding new syntax to the existing markdown syntax. It would be better to create another syntax as a whole, something like defining new prefix for different media: +[foo][bar "100x100"]
-[foo][bar "100x100"]
@[foo][bar "100x100"]
$[foo][bar "100x100"]
&[foo][bar "100x100"]
%[foo][bar "100x100"]
#[foo][bar "100x100"]
~[foo][bar "100x100"]
>[foo][bar "100x100"]
=[foo][bar "100x100"] |
Note: This is not my style. I just copy&paste other's idea. Ok, in that case I'm gonna propose the following syntaxes:
In my opinion, the main advantages of this proposal are:
Question |
The part of the code that seems to be related with this issue is (L1434 IF statement):
According to Regex Online Tester,
Therefore, the focus should be in trying to make this part also recognize patterns like
So far, do you agree? |
So you really want to rollup your language syntax then. Let me give you a clue. The first results of the regex above (the list($id, $sizes) = explode(' ', $matches[1], 2); // First part is the reference ID, second part is for the sizes
$sizes = trim(trim($sizes), '\'"'); // Remove quotes
list($width, $height) = explode('x', $sizes); // Get width and height
// Then you need to put that `$id` (the original reference ID) somewhere to maps the data back to the corresponding placement. Example:
$definition = strtolower($id); |
If you have another syntax proposal, please let me know. As long as is simple and consistent, for me is just fine. I could easily go on with something like:
However, as you mentioned: "Your style is better IMO". Therefore, I just followed your advice. |
I've just replaced the following lines:
With:
This way, the following syntaxes are now working:
Although the code seems to be working fine, it also seems to be overly complicated. |
No it isn’t. It is good. Just maybe you can remove this line as it has been checked in the second if (preg_match('/^\d+x\d+$/', $size)) { ... } |
Was this implemented in https://github.com/erusev/parsedown? |
Parsedown provides a way to reference images:
If you wanna extend Parsedown to also resize the image, you can just append the following snippet at the end of the main code:
Then you can resize images like that:
Question
There are some situations which would also be helpful the following syntax:
Any idea how to include such feature into Parsedown?
The text was updated successfully, but these errors were encountered: