Add 'issue' attribute for GitLab link inline macro

This commit is contained in:
Gabriel Arazas 2023-11-01 17:36:11 +08:00
parent 42454be244
commit cf8a942011
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 11 additions and 2 deletions

View File

@ -23,6 +23,9 @@ By default. it doesn't point to anything which should be in the default branch o
- `path` is the filepath to be linked.
- `issue` is the issue to be linked from the repo.
Take note issue has higher precedence so once `domain` and `issue` are both set, it will still link to an issue.
There are settings that is enabled with the link:https://docs.asciidoctor.org/asciidoc/latest/attributes/options/[options attribute].
- `repo` sets the default caption to be the repo part.

View File

@ -20,8 +20,14 @@ class GitLabLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
text = attrs['caption'] || default_caption
uri = URI.parse %(https://#{attrs['domain']}/#{target})
uri.path += %(/-/tree/#{attrs['rev']}) if attrs['rev']
uri.path += %(/#{attrs['path']}) if attrs['path']
if attrs.key? 'issue'
uri.path += %(/-/issues/#{attrs['issue']})
text << "##{attrs['issue']}" if text == target
else
uri.path += %(/-/tree/#{attrs['rev']}) if attrs.key? 'rev'
uri.path += %(/#{attrs['path']}) if attrs.key? 'path'
text << "@#{attrs['rev']}" if attrs.key?('rev') && text == target
end
target = uri.to_s