Add repo option for GitLab link inline macro

This commit is contained in:
Gabriel Arazas 2023-05-06 15:22:42 +08:00
parent 627ccd3f20
commit 6f3ee231f2
2 changed files with 10 additions and 1 deletions

View File

@ -23,6 +23,10 @@ By default. it doesn't point to anything which should be in the default branch o
- `path` is the filepath to be linked. - `path` is the filepath to be linked.
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.
== Example usage == Example usage

View File

@ -12,7 +12,12 @@ class GitLabLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
def process(parent, target, attrs) def process(parent, target, attrs)
doc = parent.document doc = parent.document
text = attrs['caption'] || target default_caption = if attrs.key?('repo-option')
target.split('/').at(1)
else
target
end
text = attrs['caption'] || default_caption
uri = URI.parse %(https://#{attrs['domain']}/#{target}) uri = URI.parse %(https://#{attrs['domain']}/#{target})
uri.path += %(/-/tree/#{attrs['rev']}) if attrs['rev'] uri.path += %(/-/tree/#{attrs['rev']}) if attrs['rev']