2

Is there anyway to link to an external file (non http url) in GitLab Flavored Markdown?

  • e.g. HTML equivalent would be <a href="file:///my/file/path">link text</a>
  • e.g. MediaWiki equivalent would be [[file:///my/file/path link text]]
Matt
  • 1,928
  • 24
  • 44
  • 1
    The [sanitation filter](http://www.rubydoc.info/gems/html-pipeline/HTML/Pipeline/SanitizationFilter#ANCHOR_SCHEMES-constant) used by GitLab seems to filter out any file:// links / unsupported anchor schemes. – swalex Jun 02 '15 at 12:30
  • That actually really clears it up. I wonder if they'd accept a pull-request modifying that... – Matt Jun 02 '15 at 15:46

2 Answers2

2

The file:// protocol is not included in the sanitation filter whitelist referenced by gitlab in the documentation.

You could manually edit embedded/service/gitlab-rails/lib/gitlab/markdown.rb in your gitlab installation, add the protocol to the whitelist yourself and restart gitlab after that to apply the changes (just insert the line with the leading +):

  whitelist = HTML::Pipeline::SanitizationFilter::WHITELIST
  whitelist[:attributes][:all].push('class', 'id')
  whitelist[:elements].push('span')
+ whitelist[:protocols]['a']['href'] = ['file'].concat(whitelist[:protocols]['a']['href'])

  # Remove the rel attribute that the sanitize gem adds, and remove the
  # href attribute if it contains inline javascript

but this is probably not the best idea, because it will cause occasional headaches when upgrading the gitlab installation.

And the desired file:// links will still not open as expected without additional configuration steps or addon installations on the client side (see here).

Community
  • 1
  • 1
swalex
  • 3,885
  • 3
  • 28
  • 33
  • Never knew Chrome wouldn't link to local file links. I was going to try this until I read that.. I don't think I can convince people in my office to all install a browser extension. :) Thanks a lot for answering though! – Matt Jun 03 '15 at 02:52
0

The normal markdown hyperlink syntax should work: [file description](file:///test/location/file)

Serban Constantin
  • 3,316
  • 1
  • 18
  • 20
  • I had no luck with this. It treats it like a relative url, e.g. ```http://myBaseUrl:9090/software/proj/blob/master/file:///test/location/file``` – Matt Mar 12 '15 at 19:17
  • In MediaWiki, file links are explicitly disabled by default (http://www.mediawiki.org/wiki/Extension:FileLink). I bet the same is true for GitLab markdown. – Geoff Mar 19 '15 at 15:10
  • Hmm, I wasn't able to find anything to this effect. In fact, the most relevant thing google returns searching for "gitlab markdown enable file link extension" is this page. :( @Geoff – Matt Apr 16 '15 at 15:59
  • I should note that the file paths I was trying to add aren't relative to the web-directory, but fully absolute paths (mostly on shares on other computers) – Matt Apr 16 '15 at 16:00