mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-01-31 04:58:07 +00:00
Add custom extension for package indices
This commit is contained in:
parent
d4e3e70e6f
commit
50a9c33f8c
@ -15,6 +15,7 @@ require_relative 'gitlab-raw-content-include-processor/extension'
|
|||||||
require_relative 'chat-block-processor/extension'
|
require_relative 'chat-block-processor/extension'
|
||||||
require_relative 'git-blob-include-processor/extension'
|
require_relative 'git-blob-include-processor/extension'
|
||||||
require_relative 'wikipedia-inline-macro/extension'
|
require_relative 'wikipedia-inline-macro/extension'
|
||||||
|
require_relative 'package-indices-link-macro/extension'
|
||||||
|
|
||||||
Asciidoctor::Extensions.register do
|
Asciidoctor::Extensions.register do
|
||||||
inline_macro ManInlineMacro
|
inline_macro ManInlineMacro
|
||||||
@ -33,4 +34,8 @@ Asciidoctor::Extensions.register do
|
|||||||
preprocessor GitContentBranchAttributePreprocessor
|
preprocessor GitContentBranchAttributePreprocessor
|
||||||
|
|
||||||
inline_macro WikipediaInlineMacro
|
inline_macro WikipediaInlineMacro
|
||||||
|
|
||||||
|
inline_macro CtanLinkInlineMacro
|
||||||
|
inline_macro PypiLinkInlineMacro
|
||||||
|
inline_macro CratesIOLinkInlineMacro
|
||||||
end
|
end
|
||||||
|
56
lib/asciidoctor/package-indices-link-macro/extension.rb
Normal file
56
lib/asciidoctor/package-indices-link-macro/extension.rb
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# I'm fairly sure this could be programmed since Ruby has nice metaprogramming
|
||||||
|
# capabilities. Though, we'll be keeping it manually defining classes for now
|
||||||
|
# for initial versions since there could be additional features for each macro.
|
||||||
|
|
||||||
|
class CtanLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
||||||
|
use_dsl
|
||||||
|
|
||||||
|
named :ctan
|
||||||
|
name_positional_attributes 'caption'
|
||||||
|
|
||||||
|
def process(parent, target, attrs)
|
||||||
|
doc = parent.document
|
||||||
|
text = attrs['caption'] || target
|
||||||
|
url = %(https://ctan.org/pkg/#{target})
|
||||||
|
|
||||||
|
doc.register :links, url
|
||||||
|
|
||||||
|
create_anchor parent, text, type: :link, target: url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class PypiLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
||||||
|
use_dsl
|
||||||
|
|
||||||
|
named :pypi
|
||||||
|
name_positional_attributes 'caption'
|
||||||
|
|
||||||
|
def process(parent, target, attrs)
|
||||||
|
doc = parent.document
|
||||||
|
text = attrs['caption'] || target
|
||||||
|
url = %(https://pypi.org/project/#{target})
|
||||||
|
|
||||||
|
doc.register :links, url
|
||||||
|
|
||||||
|
create_anchor parent, text, type: :link, target: url
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class CratesIOLinkInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
||||||
|
use_dsl
|
||||||
|
|
||||||
|
named :cratesio
|
||||||
|
name_positional_attributes 'caption'
|
||||||
|
|
||||||
|
def process(parent, target, attrs)
|
||||||
|
doc = parent.document
|
||||||
|
text = attrs['caption'] || target
|
||||||
|
url = %(https://crates.io/crates/#{target})
|
||||||
|
|
||||||
|
doc.register :links, url
|
||||||
|
|
||||||
|
create_anchor parent, text, type: :link, target: url
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user