Atom/Core URL handler support for Markdown inside Datatip #16888
Comments
This is due to dompurify removing unsafe links in this block of code in render = (text, filePath, callback) ->
roaster ?= require 'roaster'
options =
sanitize: false
breaks: atom.config.get('markdown-preview.breakOnSingleNewline')
# Remove the <!doctype> since otherwise marked will escape it
# https://github.com/chjj/marked/issues/354
text = text.replace(/^\s*<!doctype(\s+.*)?>\s*/i, '')
roaster text, options, (error, html) ->
return callback(error) if error?
html = createDOMPurify().sanitize(html, {ALLOW_UNKNOWN_PROTOCOLS: atom.config.get('markdown-preview.allowUnsafeProtocols')})
html = resolveImagePaths(html, filePath)
callback(null, html.trim()) If you check "Allow Unsafe Protocols" in the markdown-preview options, // allow external protocol handlers in URL attributes (default is false)
// by default only http, https, ftp, ftps, tel, mailto, callto, cid and xmpp are allowed.
var clean = DOMPurify.sanitize(dirty, {ALLOW_UNKNOWN_PROTOCOLS: true});
// allow specific protocols handlers in URL attributes (default is false)
// by default only http, https, ftp, ftps, tel, mailto, callto, cid and xmpp are allowed.
// Default RegExp: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;
var clean = DOMPurify.sanitize(dirty, {ALLOWED_URI_REGEXP: /^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp|xxx):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i;}); [Edit] This is only for the markdown-preview part of this bug; the datatips are handled separately. |
@BinaryMuse i think the setting |
@BinaryMuse hmm... maybe my atom core URL is in incorrect format. The URL I'm trying is: |
I still can't get Atom core URLs to work from MD preview even after setting the prefernce |
I was looking for the exact format too according to #15935 it's:
|
@UziTech I have tried encoding the file path and it again only works from the OS, i.e. Mac OSX URL in the Text Editor, right-click |
You are correct. It does seem to work with hyperlink-hyperclick. After a bit of research it looks like the "Open link" explicitly only works with http/https links https://github.com/atom/link/blob/add8170e69c84e1ea438e22b6a023a32f6582eaf/lib/link.js#L28 And markdown-preview doesn't seem to work with anything other than http or https (I tried |
@UziTech Thanks very much for the info! I think there is enough info for me to attempt a patch :-) |
I added a PR for language-hyperlink to include |
Looks like I found the right solution for the problem. Wonder if anyone can merge this PR #16940 ? |
@daviwil Would you mind checking this out? |
This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks! |
Prerequisites
[ X] * Reproduced the problem in Safe Mode: https://flight-manual.atom.io/hacking-atom/sections/debugging/#using-safe-mode
[ X] * Followed all applicable steps in the debugging guide: https://flight-manual.atom.io/hacking-atom/sections/debugging/
[ X] * Checked the FAQs on the message board for common solutions: https://discuss.atom.io/c/faq
[ X] * Checked that your issue isn't already filed: https://github.com/issues?utf8=✓&q=is%3Aissue+user%3Aatom
[ X] * Checked that there is not already an Atom package that provides the described functionality: https://atom.io/packages
Description
MD preview and MD datatips (hovers) don't support
atom/core
URL handlers from #15935. Would be useful if I want to provide source code links inside the datatip (hover)Steps to Reproduce
[This is a link](atom://core/open/file?filename=<path to file>)
http://www.bbc.com
the link would workExpected behavior:
The file specified by its path open in Atom text editor
Actual behavior:
Core URLs not supported
Reproduces how often:
100%
Versions
All verions up to 1.25-beta2
Additional Details
Looking for directions... What to look at if I am to provide a patch for this
The text was updated successfully, but these errors were encountered: