Add repo option for GitHub link inline macro

This commit is contained in:
Gabriel Arazas 2023-05-06 15:22:53 +08:00
parent f89e1d4a85
commit 4f3189ea63
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 12 additions and 2 deletions

View File

@ -30,6 +30,11 @@ For example, if `issue` and `rev` are both present, the link for issue will be t
+
When given no caption, it will update the default caption with `$OWNER/$REPO#$ISSUE`.
You can also change certain behaviors with the link:https://docs.asciidoctor.org/asciidoc/latest/attributes/options/[options attribute].
- `repo` sets the default link text with only the repo.
Pretty useful to quickly refer to the name of the software.
== Example usage

View File

@ -11,7 +11,12 @@ class GitHubLinkInlineMacro < 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://github.com/#{target})
if attrs.key? 'issue'
@ -20,7 +25,7 @@ class GitHubLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
else
uri.path += %(/tree/#{attrs['rev']}) if attrs.key? 'rev'
uri.path += %(/#{attrs['path']}) if attrs.key? 'path'
text << "@#{attrs['rev']}" if text == target
text << "@#{attrs['rev']}" if attrs.key?('rev') && text == target
end
target = uri.to_s