Use ?plain=1 for range links to GitHub markups

GitHub markups are by default rendered by [1], which doesn't map
original line anchors into the previews.

[1] https://github.com/github/markup
This commit is contained in:
Frederick Zhang
2023-03-29 15:38:59 +11:00
committed by Tim Pope
parent cad60fe382
commit ee69335de1

View File

@@ -296,6 +296,8 @@ endfunction
" Section: Fugitive :GBrowse support " Section: Fugitive :GBrowse support
" https://github.com/github/markup
let s:markup_exts = ['markdown', 'mdown', 'mkdn', 'md', 'textile', 'rdoc', 'org', 'creole', 'mediawiki', 'wiki', 'rst', 'asciidoc', 'adoc', 'asc', 'pod']
function! rhubarb#FugitiveUrl(...) abort function! rhubarb#FugitiveUrl(...) abort
if a:0 == 1 || type(a:1) == type({}) if a:0 == 1 || type(a:1) == type({})
let opts = a:1 let opts = a:1
@@ -323,6 +325,9 @@ function! rhubarb#FugitiveUrl(...) abort
elseif get(opts, 'type', '') ==# 'blob' || opts.path =~# '[^/]$' elseif get(opts, 'type', '') ==# 'blob' || opts.path =~# '[^/]$'
let escaped_commit = substitute(commit, '#', '%23', 'g') let escaped_commit = substitute(commit, '#', '%23', 'g')
let url = root . '/blob/' . escaped_commit . '/' . path let url = root . '/blob/' . escaped_commit . '/' . path
if get(opts, 'line1') > 0 && index(s:markup_exts, fnamemodify(path, ':e')) >= 0
let url .= '?plain=1'
endif
if get(opts, 'line2') > 0 && get(opts, 'line1') == opts.line2 if get(opts, 'line2') > 0 && get(opts, 'line1') == opts.line2
let url .= '#L' . opts.line1 let url .= '#L' . opts.line1
elseif get(opts, 'line1') > 0 && get(opts, 'line2') > 0 elseif get(opts, 'line1') > 0 && get(opts, 'line2') > 0