From 627ccd3f20bb852093d9a2ba3f6a04691fd5a563 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Sat, 6 May 2023 15:22:27 +0800 Subject: [PATCH] Add `full` options attribute for SWHID inline macro --- lib/asciidoctor/swhid-inline-macro/README.adoc | 8 ++++++++ lib/asciidoctor/swhid-inline-macro/extension.rb | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/asciidoctor/swhid-inline-macro/README.adoc b/lib/asciidoctor/swhid-inline-macro/README.adoc index cb1ec23..029b3e4 100644 --- a/lib/asciidoctor/swhid-inline-macro/README.adoc +++ b/lib/asciidoctor/swhid-inline-macro/README.adoc @@ -15,6 +15,14 @@ swh:$SWHID[$CAPTION] If no caption is given, the link text will be the core identifier of the SWHID. +== Attributes + +You can configure certain behavior of the macro with the link:https://docs.asciidoctor.org/asciidoc/latest/attributes/options/[options attribute]. +Here's a list of them... + +- `full` will make the entire SWHID as the default link text. + + == Extra notes You would use like in the following form `swh:swh:1:snp:6ea7d28dfd4789609e0be2b64179fc9c12931beb[]` but you could also cut off `swh:` from the SWHID if you want to (i.e., `swh:1:snp:6ea7d28dfd4789609e0be2b64179fc9c12931beb[]`) to make it aesthetically pleasing. diff --git a/lib/asciidoctor/swhid-inline-macro/extension.rb b/lib/asciidoctor/swhid-inline-macro/extension.rb index b0b4d08..aa0f819 100644 --- a/lib/asciidoctor/swhid-inline-macro/extension.rb +++ b/lib/asciidoctor/swhid-inline-macro/extension.rb @@ -12,9 +12,12 @@ class SWHInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor # We're only considering `swh:` starting with the scheme version. Also, it # looks nice aesthetically. swhid = target.start_with?('swh:') ? target : %(swh:#{target}) - swhid_core_identifier = (swhid.split ';').at 0 - - text = attrs['caption'] || swhid_core_identifier + default_caption = if attrs.key? 'full-option' + swhid + else + swhid.split(';').at(0) + end + text = attrs['caption'] || default_caption target = %(https://archive.softwareheritage.org/#{swhid}) doc.register :links, target