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.
37 lines
903 B
37 lines
903 B
4 years ago
|
////
|
||
|
Included in:
|
||
|
|
||
|
- user-manual: Extensions: Postprocessor example
|
||
|
////
|
||
|
|
||
|
Purpose::
|
||
|
Insert copyright text in the footer.
|
||
|
|
||
|
.CopyrightFooterPostprocessor
|
||
|
|
||
|
```ruby
|
||
|
class CopyrightFooterPostprocessor < Asciidoctor::Extensions::Postprocessor
|
||
|
def process document, output
|
||
|
content = (document.attr 'copyright') || 'Copyright Acme, Inc.'
|
||
|
if document.basebackend? 'html'
|
||
|
replacement = %(<div id="footer-text">\\1<br>\n#{content}\n</div>)
|
||
|
output = output.sub(/<div id="footer-text">(.*?)<\/div>/m, replacement)
|
||
|
elsif document.basebackend? 'docbook'
|
||
|
replacement = %(<simpara>#{content}</simpara>\n\\1)
|
||
|
output = output.sub(/(<\/(?:article|book)>)/, replacement)
|
||
|
end
|
||
|
output
|
||
|
end
|
||
|
end
|
||
|
```
|
||
|
|
||
|
.Usage
|
||
|
|
||
|
```
|
||
|
Asciidoctor::Extensions.register do
|
||
|
postprocessor CopyrightFooterPostprocessor
|
||
|
end
|
||
|
|
||
|
Asciidoctor.convert_file 'sample-with-copyright-footer.adoc', :safe => :safe
|
||
|
```
|