Create IETF RFC link inline macro

This commit is contained in:
Gabriel Arazas 2023-07-06 22:39:16 +08:00
parent 0758726908
commit 0def42d067
3 changed files with 45 additions and 0 deletions

View File

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

View File

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

View File

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