Add gitref macro to reference a git hash
With this extension a git hash can be easily referenced. The porters handbook versions chapter uses this extension as an example in the FreeBSD 14.0 version table. An example of use gitref:hash[repository="src|doc|ports",length=hash-longitude] The repository should be src, doc or ports. And if no length it's specified the macro will use 12 characters of the specified hash. PR: 253050 Submitted by: jhb@main
parent
ba631cb51b
commit
fb36cfdfb2
@ -0,0 +1,25 @@
|
||||
require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'
|
||||
|
||||
include ::Asciidoctor
|
||||
|
||||
class GitReferencesMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
||||
use_dsl
|
||||
|
||||
named :gitref
|
||||
|
||||
def process parent, target, attrs
|
||||
hash = target
|
||||
repository = if (repository = attrs['repository'])
|
||||
"#{repository}"
|
||||
else
|
||||
"src"
|
||||
end
|
||||
length = if (length = attrs['length'])
|
||||
length.to_i
|
||||
else
|
||||
12
|
||||
end
|
||||
url = %(https://cgit.freebsd.org/#{repository}/commit/?id=#{hash})
|
||||
%(<a href="#{url}">#{hash[0, length]}</a>)
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
RUBY_ENGINE == 'opal' ? (require 'GitReferencesMacro/extension') : (require_relative 'GitReferencesMacro/extension')
|
||||
|
||||
Asciidoctor::Extensions.register do
|
||||
inline_macro GitReferencesMacro
|
||||
end
|
Loading…
Reference in New Issue