diff --git a/lib/asciidoctor/foodogsquared-extensions.rb b/lib/asciidoctor/foodogsquared-extensions.rb index 312ab27..dac22dc 100644 --- a/lib/asciidoctor/foodogsquared-extensions.rb +++ b/lib/asciidoctor/foodogsquared-extensions.rb @@ -21,11 +21,13 @@ require_relative 'fdroid-link-inline-macro/extension' require_relative 'musicbrainz-link-inline-macro/extension' require_relative 'flathub-link-inline-macro/extension' require_relative 'repology-link-inline-macro/extension' +require_relative 'ietf-rfc-link-inline-macro/extension' OpenURI::Cache.cache_path = '/tmp/open-uri-cache-foodogsquared-website' Asciidoctor::Extensions.register do inline_macro ManInlineMacro + inline_macro IETFRFCLinkInlineMacro block ChatBlock if @document.basebackend? 'html' inline_macro SWHInlineMacro diff --git a/lib/asciidoctor/ietf-rfc-link-inline-macro/README.adoc b/lib/asciidoctor/ietf-rfc-link-inline-macro/README.adoc new file mode 100644 index 0000000..158a8b5 --- /dev/null +++ b/lib/asciidoctor/ietf-rfc-link-inline-macro/README.adoc @@ -0,0 +1,27 @@ += Flathub link inline macro +:toc: + + +A shorthand for linking link:https://datatracker.ietf.org/[IETF RFCs]. + + +== Synopsis + +[source, asciidoc] +---- +rfc:$RFC[$CAPTION] +---- + +Where... + +- `$RFC` is the RFC number. + +- `$CAPTION` is the link text to be used. +By default, it will be `RFC$RFC`. + + +== Example usage + +- `rfc:2136[]` links to the link:https://datatracker.ietf.org/doc/html/rfc2136[RFC2136 (dynamic update)] with the caption `RFC2136`. + +- `rfc:2136[Dynamic DNS updates]` is the same as the previous list item but with the caption text `Dynamic DNS updates`. diff --git a/lib/asciidoctor/ietf-rfc-link-inline-macro/extension.rb b/lib/asciidoctor/ietf-rfc-link-inline-macro/extension.rb new file mode 100644 index 0000000..e846e4d --- /dev/null +++ b/lib/asciidoctor/ietf-rfc-link-inline-macro/extension.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class IETFRFCLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor + use_dsl + + named :rfc + name_positional_attributes 'caption' + + def process(parent, target, attrs) + doc = parent.document + url = %(https://datatracker.ietf.org/doc/html/#{target}) + attrs['caption'] ||= "RFC#{target}" + doc.register :links, url + create_anchor parent, attrs['caption'], type: :link, target: url + end +end