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/include-processor.adoc | |
| parent | cd241bc19e5016468e24104f949f0d18f207c69b (diff) | |
rearchitect modules and filenames and drop asciidoctor folder under docs
Diffstat (limited to 'docs/modules/extensions/pages/include-processor.adoc')
| -rw-r--r-- | docs/modules/extensions/pages/include-processor.adoc | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/docs/modules/extensions/pages/include-processor.adoc b/docs/modules/extensions/pages/include-processor.adoc new file mode 100644 index 00000000..8dbdd8e0 --- /dev/null +++ b/docs/modules/extensions/pages/include-processor.adoc @@ -0,0 +1,49 @@ += Include Processor Extension Example +:navtitle: Include Processor + +Purpose:: +Include a file from a URI. + +TIP: Asciidoctor supports including content from a URI out of the box if you set the `allow-uri-read` attribute (not available if the safe mode is `secure`). + +== sample-with-uri-include.adoc + +``` +:source-highlighter: coderay + +.Gemfile +[source,ruby] +---- +\include::https://raw.githubusercontent.com/asciidoctor/asciidoctor/master/Gemfile[] +---- +``` + +== UriIncludeProcessor + +```ruby +require 'asciidoctor' +require 'asciidoctor/extensions' +require 'open-uri' + +class UriIncludeProcessor < Asciidoctor::Extensions::IncludeProcessor + def handles? target + (target.start_with? 'http://') or (target.start_with? 'https://') + end + + def process doc, reader, target, attributes + content = (open target).readlines + reader.push_include content, target, target, 1, attributes + reader + end +end +``` + +== Usage + +```ruby +Asciidoctor::Extensions.register do + include_processor UriIncludeProcessor +end + +Asciidoctor.convert_file 'sample-with-uri-include.adoc', :safe => :safe +``` |
