From c3c7ddbda681cc8f44832b0549bb623d3eace748 Mon Sep 17 00:00:00 2001 From: Sarah White Date: Wed, 18 Nov 2020 15:53:10 -0700 Subject: rearchitect modules and filenames and drop asciidoctor folder under docs --- docs/modules/extensions/nav.adoc | 11 +++ .../extensions/pages/block-macro-processor.adoc | 48 +++++++++++++ docs/modules/extensions/pages/block-processor.adoc | 45 ++++++++++++ .../extensions/pages/compound-block-processor.adoc | 56 +++++++++++++++ .../extensions/pages/docinfo-processor.adoc | 36 ++++++++++ .../extensions/pages/include-processor.adoc | 49 +++++++++++++ docs/modules/extensions/pages/index.adoc | 51 +++++++++++++ .../extensions/pages/inline-macro-processor.adoc | 48 +++++++++++++ docs/modules/extensions/pages/postprocessor.adoc | 33 +++++++++ docs/modules/extensions/pages/preprocessor.adoc | 66 +++++++++++++++++ docs/modules/extensions/pages/register.adoc | 25 +++++++ docs/modules/extensions/pages/tree-processor.adoc | 83 ++++++++++++++++++++++ 12 files changed, 551 insertions(+) create mode 100644 docs/modules/extensions/nav.adoc create mode 100644 docs/modules/extensions/pages/block-macro-processor.adoc create mode 100644 docs/modules/extensions/pages/block-processor.adoc create mode 100644 docs/modules/extensions/pages/compound-block-processor.adoc create mode 100644 docs/modules/extensions/pages/docinfo-processor.adoc create mode 100644 docs/modules/extensions/pages/include-processor.adoc create mode 100644 docs/modules/extensions/pages/index.adoc create mode 100644 docs/modules/extensions/pages/inline-macro-processor.adoc create mode 100644 docs/modules/extensions/pages/postprocessor.adoc create mode 100644 docs/modules/extensions/pages/preprocessor.adoc create mode 100644 docs/modules/extensions/pages/register.adoc create mode 100644 docs/modules/extensions/pages/tree-processor.adoc (limited to 'docs/modules/extensions') diff --git a/docs/modules/extensions/nav.adoc b/docs/modules/extensions/nav.adoc new file mode 100644 index 00000000..e209f801 --- /dev/null +++ b/docs/modules/extensions/nav.adoc @@ -0,0 +1,11 @@ +* xref:index.adoc[] +** xref:register.adoc[] +** xref:preprocessor.adoc[] +** xref:tree-processor.adoc[] +** xref:postprocessor.adoc[] +** xref:docinfo-processor.adoc[] +** xref:block-processor.adoc[] +** xref:compound-block-processor.adoc[] +** xref:block-macro-processor.adoc[] +** xref:inline-macro-processor.adoc[] +** xref:include-processor.adoc[] diff --git a/docs/modules/extensions/pages/block-macro-processor.adoc b/docs/modules/extensions/pages/block-macro-processor.adoc new file mode 100644 index 00000000..df451c43 --- /dev/null +++ b/docs/modules/extensions/pages/block-macro-processor.adoc @@ -0,0 +1,48 @@ += Block Macro Processor Extension Example +:navtitle: Block Macro Processor + +Purpose:: +Create a block macro named `gist` for embedding a gist. + +== sample-with-gist-macro.adoc + +``` +.My Gist +gist::123456[] +``` + +== GistBlockMacro + +```ruby +require 'asciidoctor' +require 'asciidoctor/extensions' + +class GistBlockMacro < Asciidoctor::Extensions::BlockMacroProcessor + use_dsl + + named :gist + + def process parent, target, attrs + title_html = (attrs.has_key? 'title') ? + %(
#{attrs['title']}
\n) : nil + + html = %(
+#{title_html}
+ +
+
) + + create_pass_block parent, html, attrs, subs: nil + end +end +``` + +== Usage + +```ruby +Asciidoctor::Extensions.register do + block_macro GistBlockMacro if document.basebackend? 'html' +end + +Asciidoctor.convert_file 'sample-with-gist.adoc', :safe => :safe +``` diff --git a/docs/modules/extensions/pages/block-processor.adoc b/docs/modules/extensions/pages/block-processor.adoc new file mode 100644 index 00000000..d228642e --- /dev/null +++ b/docs/modules/extensions/pages/block-processor.adoc @@ -0,0 +1,45 @@ += Block Processor Extension Example +:navtitle: Block Processor + +Purpose:: +Register a custom block style named `shout` that uppercases all the words and converts periods to exclamation points. + +== sample-with-shout-block.adoc + +``` +[shout] +The time is now. Get a move on. +``` + +== ShoutBlock + +```ruby +require 'asciidoctor' +require 'asciidoctor/extensions' + +class ShoutBlock < Asciidoctor::Extensions::BlockProcessor + PeriodRx = /\.(?= |$)/ + + use_dsl + + named :shout + on_context :paragraph + name_positional_attributes 'vol' + parse_content_as :simple + + def process parent, reader, attrs + volume = ((attrs.delete 'vol') || 1).to_i + create_paragraph parent, (reader.lines.map {|l| l.upcase.gsub PeriodRx, '!' * volume }), attrs + end +end +``` + +== Usage + +```ruby +Asciidoctor::Extensions.register do + block ShoutBlock +end + +Asciidoctor.convert_file 'sample-with-shout-block.adoc', :safe => :safe +``` diff --git a/docs/modules/extensions/pages/compound-block-processor.adoc b/docs/modules/extensions/pages/compound-block-processor.adoc new file mode 100644 index 00000000..32dea0e4 --- /dev/null +++ b/docs/modules/extensions/pages/compound-block-processor.adoc @@ -0,0 +1,56 @@ += Compound Block Processor Example +:navtitle: Compound Block Processor + +Purpose:: +Register a custom block named `collapsible` that transforms a listing block into a compound block composed of the following: + +* an example block with the collapsible option enabled +* the original listing block +* the listing block is promoted to a source block if a language is specified using the second positional attribute. + +.sample-with-collapsible-block.adoc +[source] +.... +.Show JSON +[collapsible,json] +---- +{ + "foo": "bar" +} +---- +.... + +.collapsible-block.rb +[source,ruby] +---- +class CollapsibleBlock < Asciidoctor::Extensions::BlockProcessor + enable_dsl + on_context :listing + positional_attributes 'language' + + def process parent, reader, attrs + lang = attrs.delete 'language' + attrs['title'] ||= 'Show Listing' + example = create_example_block parent, [], attrs, content_model: :compound + example.set_option 'collapsible' + listing = create_listing_block example, reader.readlines, nil + if lang + listing.style = 'source' + listing.set_attr 'language', lang + listing.commit_subs + end + example << listing + example + end +end + +Asciidoctor::Extensions.register do + block CollapsibleBlock, :collapsible +end +---- + +.Usage + $ asciidoctor -r ./collapsible-block.rb sample-with-collapsible-block.adoc + +NOTE: This extension mimics the builtin `collapsible` option on the example block, but consolidates it to a single block. +The purpose of this extension is to show how to assemble a compound block in an extension. diff --git a/docs/modules/extensions/pages/docinfo-processor.adoc b/docs/modules/extensions/pages/docinfo-processor.adoc new file mode 100644 index 00000000..d5510c1a --- /dev/null +++ b/docs/modules/extensions/pages/docinfo-processor.adoc @@ -0,0 +1,36 @@ += Docinfo Processor Extension Example +:navtitle: Docinfo Processor + +Purpose:: +Appends the Google Analytics tracking code to the bottom of an HTML document. + +== GoogleAnalyticsDocinfoProcessor + +```ruby +class GoogleAnalyticsDocinfoProcessor < Asciidoctor::Extensions::DocinfoProcessor + use_dsl + at_location :footer + def process document + return unless (ga_account_id = document.attr 'google-analytics-account') + %() + end +end +``` + +== Usage + +```ruby +Asciidoctor::Extensions.register do + docinfo_processor GoogleAnalyticsDocinfoProcessor +end + +Asciidoctor.convert_file 'sample.adoc', :safe => :safe, + :attributes => 'UA-ABCXYZ123' +``` 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 +``` diff --git a/docs/modules/extensions/pages/index.adoc b/docs/modules/extensions/pages/index.adoc new file mode 100644 index 00000000..33b35755 --- /dev/null +++ b/docs/modules/extensions/pages/index.adoc @@ -0,0 +1,51 @@ += Extensions +:url-exten-lab: https://github.com/asciidoctor/asciidoctor-extensions-lab + +Extensions are central to the success of AsciiDoc because they open up the language to new use cases. +Asciidoctor provides an extension API that offers a superset of extension points. +As a result, extensions in Asciidoctor are easy to write, powerful, and simple to distribute. + +Asciidoctor also allows extensions to be written using the full power of a programming language (whether it be Ruby, Java, Groovy or JavaScript). +You don't have to shave yaks to get the functionality you want, and you can distribute the extension using defacto-standard packaging mechanisms like RubyGems or JARs. + +== Available extension points + +Asciidoctor provides the following extension points: + +Preprocessor:: +Processes the raw source lines before they are passed to the parser. +See xref:preprocessor.adoc[]. + +Tree processor:: +Processes the [.class]#Asciidoctor::Document# (AST) once parsing is complete. +See xref:tree-processor.adoc[]. + +Postprocessor:: +Processes the output after the document has been converted, but before it's written to disk. +See xref:postprocessor.adoc[]. + +Docinfo Processor:: +Adds additional content to the header or footer regions of the generated document. +See xref:docinfo-processor.adoc[]. + +Block processor:: +Processes a block of content marked with a custom block style (i.e., `[custom]`). (similar to an AsciiDoc filter) +See xref:block-processor.adoc[]. + +Compound block processor:: +Register a custom block named `collapsible` that transforms a listing block into a compound block. +See xref:compound-block-processor.adoc[]. + +Block macro processor:: +Registers a custom block macro and processes it (e.g., `gist::12345[]`). +See xref:block-macro-processor.adoc[]. + +Inline macro processor:: +Registers a custom inline macro and processes it (e.g., `btn:[Save]`). +See xref:inline-macro-processor.adoc[]. + +Include processor:: +Processes the `include::[]` directive. +See xref:include-processor.adoc[]. + +There are additional extension examples in the {url-exten-lab}[Asciidoctor extensions lab^]. 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 +``` diff --git a/docs/modules/extensions/pages/postprocessor.adoc b/docs/modules/extensions/pages/postprocessor.adoc new file mode 100644 index 00000000..712706ea --- /dev/null +++ b/docs/modules/extensions/pages/postprocessor.adoc @@ -0,0 +1,33 @@ += Postprocessor Extension Example +:navtitle: Postprocessor + +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 = %() + output = output.sub(/