magidoc
magidoc copied to clipboard
Support download links
Describe the problem
Hi,
Magidoc can generate custom documentation pages from markdown files. It supports out of the box links to external website or to other pages of the generated documentation. But it does not support adding links to download static files.
In the staticAssets folder, I have a json file (exported Postman collection) and I would like to add in one of the page of my documentation a link to download it. Using the following does not work, the generated link redirect me to the 404 page.
[Postman collection](/postman/example.postman_collection.json)
Describe the proposed solution
I would suggest to use the link title to identify links that should be download links. For example, in case the link title is "download", we can add the download attribute the link instead of the default title attribute.
In practice
[Postman collection](/postman/example.postman_collection.json "download")
would be converted as
<a href="/postman/example.postman_collection.json" download="example.postman_collection.json" class="bx--link">Postman collection</a>
instead of
<a href="/postman/example.postman_collection.json" title="download" class="bx--link">Postman collection</a>
I was able to implement this in the carbon-multi-page template by adapting the file src/lib/components/markdown/text/MarkdownLink.svelte. Not sure if it's the best place to do this (not really a svelte expert) but it works. Let me know if you are interested by a PR for this feature.
Importance
Nice to have
Hi @ddnyer. Thanks for the proposition. I wouldn't mind a PR to add that if you want, but know that this is already possible with the existing set of features.
Magidoc supports inlining HTML inside the markdown. So you could actually only put your anchor as is inside your markdown page and it would be rendered properly.
See this sample markdown:
Some *markdown* to show it works
<p>If you're interested to download postman stuff, you can download them <a href="/postman/example.postman_collection.json" download="example.postman_collection.json" class="bx--link">right here</a>.</p>
Produces this output in the website:
If this solution suites you, feel free to close the issue, otherwise PRs are always welcome!
Hi
It's the first think I tried but without the <p></p> tags and it did not worked very well. It looks to work better with your example, thanks for the tip.
If addind tests of the feature do not take too much time I'll try do push a PR anyway as part of the job is already done.
Awesome, thank you. I tried without the <p> too at first and I got an issue with doubled words. I don't know why that occured, there might be a problem with markedJS or magidoc implementation/usage. I'll look into it when possible
Closing this as this seems to be resolved.