Add custom Asciidoctor extensions to load path

This commit is contained in:
Gabriel Arazas 2023-02-25 12:11:54 +08:00
commit 4201e1c6e8
5 changed files with 108 additions and 0 deletions

58
.gitignore vendored Normal file
View File

@ -0,0 +1,58 @@
### Ruby ###
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/
# Used by dotenv library to load environment variables.
# .env
# Ignore Byebug command history file.
.byebug_history
## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/
## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
# vendor/Pods/
## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/
## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/
# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
# .rubocop-https?--*

View File

@ -0,0 +1,19 @@
Gem::Specification.new do |s|
s.name = 'asciidoctor-foodogsquared-extensions'
s.version = '1.0.0'
s.licenses = ['MIT']
s.summary = "foo-dogsquared's custom Asciidoctor extensions"
s.description = <<-EOF
foo-dogsquared's custom Asciidoctor extensions as a Gem. This is not meant
to be used in production or as a public Gem. This is used since Hugo
doesn't allow loading Asciidoctor extensions with path separators.
EOF
s.authors = ["Gabriel Arazas"]
s.email = "foodogsquared@foodogsquared.one"
s.metadata = { "source_code_uri" => "https://github.com/foo-dogsquared/foo-dogsquared.github.io" }
s.files = Dir["lib/**/*", "*.gemspec"]
s.add_runtime_dependency 'asciidoctor', '~> 2.0'
end

View File

@ -0,0 +1,2 @@
# frozen_string_literal: true
require 'asciidoctor/foodogsquared-extensions'

View File

@ -0,0 +1,7 @@
require 'asciidoctor'
require 'asciidoctor/extensions'
require_relative 'man-inline-macro/extension'
Asciidoctor::Extensions.register do
inline_macro ManInlineMacro
end

View File

@ -0,0 +1,22 @@
class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :man
name_positional_attributes 'volnum'
def process parent, target, attrs
doc = parent.document
text = manname = target
suffix = (volnum = attrs['volnum']) ? %((#{volnum})) : ''
if doc.basebackend? 'html'
target = %(#{manname}#{doc.outfilesuffix})
doc.register :links, target
node = create_anchor parent, text, type: :link, target: target
elsif doc.backend == 'manpage'
node = create_inline parent, :quoted, manname, type: :strong
else
node = create_inline parent, :quoted, manname
end
create_inline parent, :quoted, %(#{node.convert}#{suffix})
end
end