Skip to content
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

Whitespace in image paths... #503

Closed
digitalmoksha opened this issue Oct 7, 2017 · 11 comments
Closed

Whitespace in image paths... #503

digitalmoksha opened this issue Oct 7, 2017 · 11 comments

Comments

@digitalmoksha
Copy link

I've opened this issue based on this discussion: https://talk.commonmark.org/t/whitespace-in-image-paths/1121/10

Pointy brackets are no longer allowed in urls, and therefore image paths.

http://spec.commonmark.org/0.24/#example-4553

...

The issue for me is that now it’s much more difficult to add a reference to an image file on disk. It’s very common to have image names that have spaces in them (even macOS creates their screen shots named “Screen Shot 2017-08-05 at 11.07.11 AM.png” for example).

And while we could ask the user to replace each space with a ‘%20’, that seems excessive and unfriendly. I thought enclosing the url in pointy brackets was a workable, if not obscure, way of solving the problem ( I would have preferred to enclose the url in quotation marks, because I think that is more intuitive, but maybe conflicted in other situations).

I would also argue that the usage of Markdown for documents that are not intended to live on the internet is important, from writing your next book and including image/figures, to journaling, taking business notes, etc.

I’m not crazy about the original pointy bracket syntax:

![Alt text](<imgs/Tristachersee pier.jpg> "Tristachersee Pier")

I think using double/single quotes is much more intuitive and consistent with how we include the use of spaces in the title and other places:

![Alt text]("imgs/Tristachersee pier.jpg" "Tristachersee Pier")

However, I don't think the user should be forced to remember how to space-encode a filename. This is what is currently required:

![Alt text](imgs/Tristachersee%20pier.jpg "Tristachersee Pier")
@Crissov
Copy link
Contributor

Crissov commented Oct 20, 2017

If I understand correctly, whitespaces inside URLs enclosed by angular brackets have been disallowed recently to be more consistent with autolinks where they have never been allowed. Maybe a better solution would have been to require angular brackets inside autolinks to make whitespace allowed in its URL. This would of course result in double brackets:

<http://absolute.url/with white space#nay>
<<http://absolute.url/with white space#yay>>
[a](http://absolute.url/with white space#nay)
[b](<http://absolute.url/with white space#yay>)
[c](relative.url/with white space#nay)
[d](<relative.url/with white space#yay>)

and then perhaps also

<relative.url#nay>
<<relative.url#yay>>

@Crissov
Copy link
Contributor

Crissov commented Dec 31, 2017

If escaping spaces in link destination was allowed #493, there would be alternative solutions of course:

<http://absolute.url/with\ white\ space#yay>
[e](http://absolute.url/with\ white\ space#yay)
[f](<http://absolute.url/with\ white\ space#yay>)
[g](relative.url/with\ white\ space#yay)
[h](<relative.url/with\ white\ space#yay>)

As spec.txt examples

<relative.url>
<<relative.url>>
<relative.url/with white space>
<relative.url/with\ white\ space>
<<relative.url/with white space>>
<http://absolute.url/with white space>
<http://absolute.url/with\ white\ space>
<<http://absolute.url/with white space>>
[foo](relative.url/with white space)
[foo](relative.url/with\ white\ space)
[foo](<relative.url/with white space>)
[foo](<relative.url/with\ white\ space>)
[foo](http://absolute.url/with white space)
[foo](http://absolute.url/with\ white\ space)
[foo](<http://absolute.url/with white space>)
[foo](<http://absolute.url/with\ white\ space>)
.
<p>
&lt;relative.url>
<a href="relative.url">relative.url</a>
&lt;relative.url/with white space>
<a href="relative.url/with%20white%20space">relative.url/with white space</a>
<a href="relative.url/with%20white%20space">relative.url/with white space</a>
&lt;http://absolute.url/with white space>
<a href="http://absolute.url/with%20white%20space">http://absolute.url/with white space</a>
<a href="http://absolute.url/with%20white%20space">http://absolute.url/with white space</a>
[foo](relative.url/with white space)
<a href="relative.url/with%20white%20space">foo</a>
<a href="relative.url/with%20white%20space">foo</a>
<a href="relative.url/with%20white%20space">foo</a>
[foo](http://absolute.url/with white space)
<a href="http://absolute.url/with%20white%20space">foo</a>
<a href="http://absolute.url/with%20white%20space">foo</a>
<a href="http://absolute.url/with%20white%20space">foo</a>
</p>

@pdeffebach
Copy link

Why are quotation marks not an option?

It seems odd that a local file path link should conform to the standards of a url link. I think new users to markdown would be put off by not being able to include an image with a space in its name.

@Crissov
Copy link
Contributor

Crissov commented Jan 6, 2018

[foo]("url/with white space")

Quotation marks could be another option, but it would be a new syntax variant and could possibly be confused with a link title. Babelmark tells us that this would happen in Markdown.pl and some others that support link destinations being omitted.

Angular brackets and backslash escape, on the other hand, are already part of the syntax and would just need some minor tinkering with to get a solution for this viable use case.

@digitalmoksha
Copy link
Author

What about just making it tolerate spaces? This is what pandoc, kramdown, and even markdown101 do (though not markdown102 for some reason). Babelmark

In other words, whatever comes before the optional link title is the url, minus any trailing spaces. No extra delimiters or syntax needed. We could escape the spaces (like pandoc does) or not.

I think we can still square this with autolinks not supporting spaces. Autolinks don't support alt text, or titles. If you need a basic short form link, you can use an autolink. If you need more flexibility, use a normal link.

These would be all be valid

![Alt text](imgs/Tristachersee pier.jpg "Tristachersee Pier")
![Alt text](imgs/Tristachersee%20pier.jpg "Tristachersee Pier")
![Alt text](imgs/Tristachersee pier.jpg)
![Alt text]("Tristachersee Pier")

@ph21ph
Copy link

ph21ph commented Jan 13, 2018 via email

@digitalmoksha
Copy link
Author

digitalmoksha commented Jan 13, 2018

@ph21ph currently, CommonMark does not support spaces in link urls. So

![Alt text](imgs/Tristachersee pier.jpg "Tristachersee Pier")

generates

<p>
  ![Alt text](imgs/Tristachersee pier.jpg "Tristachersee Pier")
</p>

because it doesn't recognize the space in the url. I'm suggesting that the parser considers the url to be everything from the ( to the either the first " (which would start the title) or the ending )., minus any trailing spaces. This doesn't require adding additional pointy brackets or enclosing the url in " as has been suggested above.

This way we get a proper image/link:

<p>
  <img src="imgs/Tristachersee pier.jpg" alt="Alt text" title="Tristachersee Pier">
</p>

@jgm
Copy link
Member

jgm commented Mar 25, 2018

@digitalmoksha - the problem is that titles need not start with "; they can also be contained in single quotes or parentheses. So I think it's still a good idea to exclude spaces from regular link destinations.

However, I'm convinced that it was a mistake in 0.24 to remove the ability to put spaces inside link destinations inside <..>. The fact that autolinks can't contain spaces is not a compelling enough reason for excluding them in this context, and the fact that image filenames often have spaces in them is a compelling reason for allowing them.

I'm for making the change to allow spaces inside <..> link destinations.

@jgm jgm closed this as completed in 33fb419 Mar 25, 2018
@digitalmoksha
Copy link
Author

@jgm Thank you for making this change, it helps.

It still seems to me though that the title requires some type of delineation - surrounding double quotes, single quotes, or parentheses. So wouldn't it still be possible to consider everything before the those delineators as the url?

In any case, thanks for the fix!

@jgm
Copy link
Member

jgm commented Apr 10, 2018 via email

@Crissov
Copy link
Contributor

Crissov commented Apr 11, 2018

I don’t think dropping title-in-parentheses would make sense nor fit the scope of this project.

Anyway, I’ve said this before, syntax extensions will want to use other characters (that are legal inside an URL) after the link destination without requiring a title. This applies in particular to additional attributes for image links (or more generic embedded media), but different behavior for links with and without a leading exclamation mark ! would fail for reference link definitions which can be shared by both.

[link to image][foo]
![embedded image][foo]

[foo]: foo.png "title"
[foo]: foo.svg "title before explicit size" =300*400
[foo]: foo.svg =300*400
[foo]: foo.svg "" =300*400
[foo]: foo.svg =300*400 "title after explicit size"
[foo]: foo.svg?lang=en =300*400
[foo]: <foo bar.svg> =300*400

(There are deployed flavors of Markdown that support this or a similar syntax for explicit image dimensions.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants