From 6f3ee231f2e65c3b2ad4491486726af50f520d12 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 6 May 2023 15:22:42 +0800 Subject: [PATCH] Add `repo` option for GitLab link inline macro --- lib/asciidoctor/gitlab-link-inline-macro/README.adoc | 4 ++++ lib/asciidoctor/gitlab-link-inline-macro/extension.rb | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/asciidoctor/gitlab-link-inline-macro/README.adoc b/lib/asciidoctor/gitlab-link-inline-macro/README.adoc index db596db..cdf7277 100644 --- a/lib/asciidoctor/gitlab-link-inline-macro/README.adoc +++ b/lib/asciidoctor/gitlab-link-inline-macro/README.adoc @@ -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. +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 diff --git a/lib/asciidoctor/gitlab-link-inline-macro/extension.rb b/lib/asciidoctor/gitlab-link-inline-macro/extension.rb index 9c84d9e..bf92e81 100644 --- a/lib/asciidoctor/gitlab-link-inline-macro/extension.rb +++ b/lib/asciidoctor/gitlab-link-inline-macro/extension.rb @@ -12,7 +12,12 @@ class GitLabLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor def process(parent, target, attrs) 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.path += %(/-/tree/#{attrs['rev']}) if attrs['rev']