grav
grav copied to clipboard
Markdown links: support for HTML download attribute
It would be great to have the HTML5 “download” attribute for links supported, similar to other attributes like id, target, classes (which I reckon are Grav Markdown features).
[Download a PDF](file.pdf?download=other-filename.pdf)
would result in
<a download="other-filename.pdf" href="file.pdf">Download a PDF</a>
The value is optional.
See the W3C reference on the download attribute
I don’t know if spaces in the desired filename could be possible, maybe by using quotes or hex url character encoding (%20)
Hi @clivebeckett
You can actually do it in a very simple way. Add the download attribute in system.pages.markdown.valid_link_attributes to your system.yaml. By default, you will find here: rel, target, id, class, classes. From the administration panel it is very simple.
The result of your example [Download a PDF](file.pdf?download=other-filename.pdf)
, would be the one you expose in this issue.
Try it and tell us.
Hi @pmoreno-rodriguez
That’s brilliant, thank you! It works indeed with one tiny exception compared to the W3C specs: if I leave the attribute empty (?download
instead of ?download=filename.pdf
), Grav translates it to download="1"
which in turn, at least in Firefox, results in a suggested filename of 1.pdf
. However, that’s a miniscule issue :)
In the meantime I had helped myself with a CSS class force-download
and a small JavaScript, returning the download attribute on every link with that class.
Best, Clive
Well, now I can't think of a situation where I would want to use an empty attribute, but if there is one, and using it without any value, it shouldn't return a 1.
Well, now I can't think of a situation where I would want to use an empty attribute, but if there is one, and using it without any value, it shouldn't return a 1.
Oh, well … an empty download
attribute will use the actual filename of the document, hence it’s less HTML if you wish to just use that name and would be less Markdown to write, too :)