mirror of
https://github.com/foo-dogsquared/asciidoctor-foodogsquared-extensions.git
synced 2025-02-07 06:19:01 +00:00
Add Wikipedia inline macro
This commit is contained in:
parent
1fc5e7c01a
commit
fb35866b30
@ -13,6 +13,7 @@ require_relative 'github-raw-content-include-processor/extension'
|
||||
require_relative 'gitlab-link-inline-macro/extension'
|
||||
require_relative 'gitlab-raw-content-include-processor/extension'
|
||||
require_relative 'chat-block-processor/extension'
|
||||
require_relative 'wikipedia-inline-macro/extension'
|
||||
|
||||
Asciidoctor::Extensions.register do
|
||||
inline_macro ManInlineMacro
|
||||
@ -26,4 +27,6 @@ Asciidoctor::Extensions.register do
|
||||
|
||||
inline_macro GitLabLinkInlineMacro
|
||||
include_processor GitLabRawIncludeProcessor
|
||||
|
||||
inline_macro WikipediaInlineMacro
|
||||
end
|
||||
|
30
lib/asciidoctor/wikipedia-inline-macro/README.adoc
Normal file
30
lib/asciidoctor/wikipedia-inline-macro/README.adoc
Normal file
@ -0,0 +1,30 @@
|
||||
= Wikipedia inline macro
|
||||
:toc:
|
||||
|
||||
|
||||
An inline macro for easily creating Wikipedia links (i.e., `wikipedia.org`).
|
||||
|
||||
|
||||
== Synopsis
|
||||
|
||||
[source, asciidoc]
|
||||
----
|
||||
wikipedia:PAGE[$CAPTION]
|
||||
----
|
||||
|
||||
Where if `$CAPTION` is present, it will be used as the link text.
|
||||
Otherwise, it will just be the page.
|
||||
|
||||
|
||||
== Attributes
|
||||
|
||||
- `lang` is the language domain to be linked into.
|
||||
By default, it is set to `en`.
|
||||
|
||||
|
||||
== Example usage
|
||||
|
||||
- `wikipedia:Diff[]` should link to the link:https://en.wikipedia.org/wiki/Diff[Diff page on English Wikipedia].
|
||||
- `wikipedia:Diff[lang=ja]` should link to the link:https://ja.wikipedia.org/wiki/Diff[Diff page on Japanese Wikipedia].
|
||||
- `wikipedia:Photosynthesis[lang=simple]` should link to the link:https://simple.wikipedia.org/wiki/Photosynthesis[Photosynthesis page on Simple English Wikipedia].
|
||||
- `wikipedia:Diff[diff in Japanese Wikipedia, lang=ja]` should link to the link:https://ja.wikipedia.org/wiki/Diff[Diff page on Japanese Wikipedia] with the `diff in Japanese Wikipedia` as the link text.
|
20
lib/asciidoctor/wikipedia-inline-macro/extension.rb
Normal file
20
lib/asciidoctor/wikipedia-inline-macro/extension.rb
Normal file
@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'uri'
|
||||
|
||||
class WikipediaInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
||||
use_dsl
|
||||
|
||||
named :wikipedia
|
||||
name_positional_attributes 'caption'
|
||||
default_attributes 'lang' => 'en'
|
||||
|
||||
def process(parent, target, attrs)
|
||||
caption = attrs['caption'] || target
|
||||
page = URI.encode_www_form_component target
|
||||
link = %(https://#{attrs['lang']}.wikipedia.org/wiki/#{page})
|
||||
node = create_anchor parent, caption, type: :link, target: link
|
||||
|
||||
create_inline parent, :quoted, node.convert
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user