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

Is there a way to stop the ampersand symbol from being converted to html in a URL? #39

Closed
treble37 opened this issue Mar 9, 2013 · 7 comments
Assignees

Comments

@treble37
Copy link

treble37 commented Mar 9, 2013

So it looks like kramdown automatically converts the "&" symbol into its proper HTML "&"....It even does this in an Amazon affiliate URL for example. Is there a way to get it to stop doing this at least in this kramdown markup:

 [some link] (a href="http://www.amazon.com/blah&...") ?
@treble37
Copy link
Author

treble37 commented Mar 9, 2013

The Amazon url's seem to redirect to the correct item even with the converted "&amp"... now I'm curious as to why Kramdown converts the ampersands in a URL instead of leaving them alone.

@ghost
Copy link

ghost commented Mar 9, 2013

It is correct behavior for kramdown to encode ampersands.
ref

@treble37
Copy link
Author

treble37 commented Mar 9, 2013

svnpenn, now I'm a bit confused...the doc you pointed to says "When writing the same URL in a plain text email message or in the location bar of your browser, you would use "&" and not "&"."....Kramdown is converting it to the HTML "&amp" in the clickable URL....

@ghost
Copy link

ghost commented Mar 9, 2013

No.

$ kramdown <<< '[some link](http://amazon.com?foo=111&bar=222)'
<p><a href="http://amazon.com?foo=111&amp;bar=222">some link</a></p>

@ghost ghost assigned gettalong Mar 9, 2013
@gettalong
Copy link
Owner

@svnpenn is correct.

Values of all attributes in (X)HTML must be correctly formatted so that no problems arise. Modern browsers are able to recover from basic errors but it is better to be on the safe side.

As stated on W3C's HTML documentation the href attribute of an <a> tag must contain a %URI string which is defined as containing CDATA. There you will find that character entities must be decoded, hence a lone ampersand must only occur as &amp;.

As a general rule: In HTML text and attribute values all <, > and & must only occur as entities (i.e. &lt;, &gt; and &amp;).

@treble37
Copy link
Author

treble37 commented Mar 9, 2013

Thanks gettalong and svnpenn I learned something new...I missed this part in svnpenn's ref: "With HTML, the browser translates "&" to "&" so the Web server would only see "&" and not "&" in the query string of the request." -- I saw the "&amp" in the Firefox browser bar but didn't realize that the webserver was seeing "&" as it should.

@gettalong
Copy link
Owner

You are welcome! It could have been a problem with kramdown, so better safe than sorry 😄

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

2 participants