From 68020109f0ddb806c1e9330c4f2792392ffc00a6 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 11 Mar 2023 16:42:24 +0800 Subject: [PATCH] Add GitHub inline macro with `issue` attribute --- lib/asciidoctor/github-link-inline-macro/README.adoc | 8 ++++++++ lib/asciidoctor/github-link-inline-macro/extension.rb | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/asciidoctor/github-link-inline-macro/README.adoc b/lib/asciidoctor/github-link-inline-macro/README.adoc index 4762028..d1c6cb5 100644 --- a/lib/asciidoctor/github-link-inline-macro/README.adoc +++ b/lib/asciidoctor/github-link-inline-macro/README.adoc @@ -23,6 +23,10 @@ There are optional attributes for this macro. - `path` is the filepath to be linked within the repo. +- `issue` accepts the issue number to be linked in the GitHub repo. +Take note `issue` is exclusive to other attributes and has more precedence. +For example, if `issue` and `rev` are both present, the link for issue will be the result. + == Example usage @@ -31,3 +35,7 @@ There are optional attributes for this macro. - `github:NixOS/nixpkgs[nixpkgs nixos-unstable branch, rev=nixos-unstable]` should link to the link:https://github.com/NixOS/nixpkgs/tree/nixos-unstable[NixOS unstable branch of nixpkgs] with a custom link text. - `github:errata-ai/vale[Vale v2.3.0 README, path=README.md, rev=v2.3.0]` should link to the link:https://github.com/errata-ai/vale/blob/v2.3.0/README.md[README of Vale v2.3.0]. + +- `github:neovim/neovim[Neovim cannot open large files properly, issue=614]` should link to https://github.com/neovim/neovim/issues/614[an issue of Neovim]. + +- `github:neovim/neovim[Neovim cannot open large files properly, issue=614, rev=master]` should still link to https://github.com/neovim/neovim/issues/614[an issue of Neovim] since `issue` has more precedence over `rev`. diff --git a/lib/asciidoctor/github-link-inline-macro/extension.rb b/lib/asciidoctor/github-link-inline-macro/extension.rb index be840c4..0194f0b 100644 --- a/lib/asciidoctor/github-link-inline-macro/extension.rb +++ b/lib/asciidoctor/github-link-inline-macro/extension.rb @@ -14,8 +14,12 @@ class GitHubLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor 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'] + if attrs.key? 'issue' + uri.path += %(/issues/#{attrs['issue']}) + else + uri.path += %(/tree/#{attrs['rev']}) if attrs.key? 'rev' + uri.path += %(/#{attrs['path']}) if attrs.key? 'path' + end target = uri.to_s