mirror of
https://github.com/foo-dogsquared/website.git
synced 2025-01-30 22:57:59 +00:00
project: init Asciidoctor custom extension
This commit is contained in:
commit
a4b41e8840
58
.gitignore
vendored
Normal file
58
.gitignore
vendored
Normal 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?--*
|
||||
|
7
Gemfile
Normal file
7
Gemfile
Normal file
@ -0,0 +1,7 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'asciidoctor-bibtex'
|
||||
gem 'asciidoctor-rouge'
|
||||
gem 'rouge'
|
||||
|
||||
gemspec
|
47
Gemfile.lock
Normal file
47
Gemfile.lock
Normal file
@ -0,0 +1,47 @@
|
||||
PATH
|
||||
remote: .
|
||||
specs:
|
||||
asciidoctor-custom-extensions (1.0.0)
|
||||
asciidoctor (~> 2.0)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
asciidoctor (2.0.18)
|
||||
asciidoctor-bibtex (0.8.0)
|
||||
asciidoctor (~> 2.0)
|
||||
bibtex-ruby (~> 5.1)
|
||||
citeproc-ruby (~> 1)
|
||||
csl-styles (~> 1)
|
||||
latex-decode (~> 0.2)
|
||||
asciidoctor-rouge (0.4.0)
|
||||
asciidoctor (>= 1.5.6, < 2.1)
|
||||
rouge (>= 2.2, < 4)
|
||||
bibtex-ruby (5.1.6)
|
||||
latex-decode (~> 0.0)
|
||||
citeproc (1.0.10)
|
||||
namae (~> 1.0)
|
||||
citeproc-ruby (1.1.14)
|
||||
citeproc (~> 1.0, >= 1.0.9)
|
||||
csl (~> 1.6)
|
||||
csl (1.6.0)
|
||||
namae (~> 1.0)
|
||||
rexml
|
||||
csl-styles (1.0.1.11)
|
||||
csl (~> 1.0)
|
||||
latex-decode (0.4.0)
|
||||
namae (1.1.1)
|
||||
rexml (3.2.5)
|
||||
rouge (3.30.0)
|
||||
|
||||
PLATFORMS
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
asciidoctor-bibtex
|
||||
asciidoctor-custom-extensions!
|
||||
asciidoctor-rouge
|
||||
rouge
|
||||
|
||||
BUNDLED WITH
|
||||
2.4.6
|
16
asciidoctor-custom-extensions.gemspec
Normal file
16
asciidoctor-custom-extensions.gemspec
Normal file
@ -0,0 +1,16 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'asciidoctor-custom-extensions'
|
||||
s.version = '1.0.0'
|
||||
s.licenses = ['MIT']
|
||||
s.summary = 'My custom Asciidoctor extensions'
|
||||
s.authors = ['Yor Neighme']
|
||||
s.email = 'yor.neighme@example.com'
|
||||
s.metadata = {
|
||||
'bug_tracker_uri' => 'https://example.com/yoruserneighme/website/issues',
|
||||
'source_code_uri' => 'https://example.com/yoruserneighme/website.git'
|
||||
}
|
||||
|
||||
s.files = Dir['*.gemspec', 'lib/**/*']
|
||||
s.required_ruby_version = '>= 2.6'
|
||||
s.add_runtime_dependency 'asciidoctor', '~> 2.0'
|
||||
end
|
10
lib/asciidoctor-custom-extensions.rb
Normal file
10
lib/asciidoctor-custom-extensions.rb
Normal file
@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'asciidoctor'
|
||||
require 'asciidoctor/extensions'
|
||||
|
||||
require_relative './asciidoctor/custom_extensions/swhid_link_inline_macro'
|
||||
|
||||
Asciidoctor::Extensions.register do
|
||||
inline_macro SWHInlineMacro
|
||||
end
|
23
lib/asciidoctor/custom_extensions/swhid_link_inline_macro.rb
Normal file
23
lib/asciidoctor/custom_extensions/swhid_link_inline_macro.rb
Normal file
@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class SWHInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
|
||||
use_dsl
|
||||
|
||||
named :swh
|
||||
name_positional_attributes 'caption'
|
||||
|
||||
def process(parent, target, attrs)
|
||||
doc = parent.document
|
||||
|
||||
# We're only considering `swh:` starting with the scheme version. Also, it
|
||||
# looks nice aesthetically.
|
||||
swhid = target.start_with?('swh:') ? target : %(swh:#{target})
|
||||
swhid_core_identifier = (swhid.split ';').at 0
|
||||
|
||||
text = attrs['caption'] || swhid_core_identifier
|
||||
target = %(https://archive.softwareheritage.org/#{swhid})
|
||||
|
||||
doc.register :links, target
|
||||
create_anchor parent, text, type: :link, target: target
|
||||
end
|
||||
end
|
10
swhid-sample.adoc
Normal file
10
swhid-sample.adoc
Normal file
@ -0,0 +1,10 @@
|
||||
// Should produce a link at https://archive.softwareheritage.org/$SWHID with
|
||||
// '$SWHID_CORE_IDENTIFIER' as the link text.
|
||||
swh:swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2;origin=https://github.com/pop-os/system76-firmware;lines=471-538[]
|
||||
|
||||
// Similar as above but with the link text replaced with 'replacing the caption'.
|
||||
swh:swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2;origin=https://github.com/pop-os/system76-firmware;lines=471-538[replacing the caption]
|
||||
|
||||
// For aesthetic purposes, you could also use the `swh` macro with the `swh:`
|
||||
// cut off from the SWHID.
|
||||
swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2;origin=https://github.com/pop-os/system76-firmware;lines=471-538[]
|
Loading…
Reference in New Issue
Block a user