diff --git a/lib/asciidoctor/gitlab-link-inline-macro/README.adoc b/lib/asciidoctor/gitlab-link-inline-macro/README.adoc index cdf7277..eba094e 100644 --- a/lib/asciidoctor/gitlab-link-inline-macro/README.adoc +++ b/lib/asciidoctor/gitlab-link-inline-macro/README.adoc @@ -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. diff --git a/lib/asciidoctor/gitlab-link-inline-macro/extension.rb b/lib/asciidoctor/gitlab-link-inline-macro/extension.rb index bf92e81..6d40e26 100644 --- a/lib/asciidoctor/gitlab-link-inline-macro/extension.rb +++ b/lib/asciidoctor/gitlab-link-inline-macro/extension.rb @@ -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