diff options
| author | Sarah White <graphitefriction@gmail.com> | 2020-11-18 15:53:10 -0700 |
|---|---|---|
| committer | Sarah White <graphitefriction@gmail.com> | 2020-12-08 14:32:53 -0700 |
| commit | c3c7ddbda681cc8f44832b0549bb623d3eace748 (patch) | |
| tree | 06d5d290d15b2f71758c40efca08d587e9e691b8 /docs/modules/extensions/pages/inline-macro-processor.adoc | |
| parent | cd241bc19e5016468e24104f949f0d18f207c69b (diff) | |
rearchitect modules and filenames and drop asciidoctor folder under docs
Diffstat (limited to 'docs/modules/extensions/pages/inline-macro-processor.adoc')
| -rw-r--r-- | docs/modules/extensions/pages/inline-macro-processor.adoc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/docs/modules/extensions/pages/inline-macro-processor.adoc b/docs/modules/extensions/pages/inline-macro-processor.adoc new file mode 100644 index 00000000..b8d88b0e --- /dev/null +++ b/docs/modules/extensions/pages/inline-macro-processor.adoc @@ -0,0 +1,48 @@ += Inline Macro Processor Extension Example +:navtitle: Inline Macro Processor + +Purpose:: +Create an inline macro named `man` that links to a manpage. + +== 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 +``` |
