mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-01-31 16:57:56 +00:00
24 lines
549 B
Ruby
24 lines
549 B
Ruby
require 'uri'
|
|
|
|
class GitHubLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
|
use_dsl
|
|
|
|
named :github
|
|
name_positional_attributes 'caption'
|
|
|
|
def process parent, target, attrs
|
|
doc = parent.document
|
|
|
|
text = attrs['caption'] || target
|
|
uri = URI.parse %(https://github.com/#{target})
|
|
|
|
uri.path += %(/tree/#{attrs['rev']}) if attrs['rev']
|
|
uri.path += %(/#{attrs['path']}) if attrs['path']
|
|
|
|
target = uri.to_s
|
|
|
|
doc.register :links, target
|
|
create_anchor parent, text, type: :link, target: target
|
|
end
|
|
end
|