You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
956 B

4 years ago
////
Included in:
- user-manual: Extensions: Inline macro processor example
////
Purpose::
Create an inline macro named `man` that links to a man page.
.sample-with-man-link.adoc
```
See man:gittutorial[7] to get started.
```
.ManpageInlineMacro
```ruby
require 'asciidoctor'
require 'asciidoctor/extensions'
class ManInlineMacro < Asciidoctor::Extensions::InlineMacroProcessor
use_dsl
named :man
name_positional_attributes 'volnum'
def process parent, target, attrs
text = manname = target
suffix = ''
target = %(#{manname}.html)
suffix = if (volnum = attrs['volnum'])
"(#{volnum})"
else
nil
end
parent.document.register :links, target
%(#{(create_anchor parent, text, type: :link, target: target).convert}#{suffix})
end
end
```
.Usage
```ruby
Asciidoctor::Extensions.register do
inline_macro ManInlineMacro
end
Asciidoctor.convert_file 'sample-with-man-link.adoc', :safe => :safe
```