mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-01-30 22:57:56 +00:00
Add repo
option for GitHub link inline macro
This commit is contained in:
parent
6f3ee231f2
commit
d4e3e70e6f
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user