Add full options attribute for SWHID inline macro

This commit is contained in:
Gabriel Arazas 2023-05-06 15:22:27 +08:00
parent 1c1deb96eb
commit 627ccd3f20
2 changed files with 14 additions and 3 deletions

View File

@ -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.

View File

@ -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