diff options
| author | Sarah White <graphitefriction@gmail.com> | 2020-12-18 16:56:51 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-18 16:56:51 -0700 |
| commit | fffa2ed16cd1be9f7f6bb7356e1eda83d47fc972 (patch) | |
| tree | 0dda9ef8df40bbe8087b66bfadaee5cf948d1571 /docs/modules/extensions/pages/include-processor.adoc | |
| parent | 47c5bf28ee16f598bff7f31901437c3a193ee685 (diff) | |
| parent | 717a1cbd6b7c9af192325b76d96ae5e86aeeb595 (diff) | |
merge PR #3880
resolves #3861 import Asciidoctor docs from asciidoctor.org/docs
Diffstat (limited to 'docs/modules/extensions/pages/include-processor.adoc')
| -rw-r--r-- | docs/modules/extensions/pages/include-processor.adoc | 52 |
1 files changed, 52 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..ee1a220a --- /dev/null +++ b/docs/modules/extensions/pages/include-processor.adoc @@ -0,0 +1,52 @@ += 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,asciidoc] +.... +:source-highlighter: coderay + +.Gemfile +[source,ruby] +---- +\include::https://raw.githubusercontent.com/asciidoctor/asciidoctor/master/Gemfile[] +---- +.... + +== UriIncludeProcessor + +[source,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 + +[source,ruby] +---- +Asciidoctor::Extensions.register do + include_processor UriIncludeProcessor +end + +Asciidoctor.convert_file 'sample-with-uri-include.adoc', safe: :safe +---- |
