Detalhes do pacote

asciidoctor-external-callout

RayOffiah9.6kMIT1.2.2

Asciidoctor extension that adds support for callouts added outside the listing block.

asciidoc, asciidoctor, callouts, listing

readme (leia-me)

External callouts for Asciidoctor

Description

An Asciidoc extension which adds support for callout tags added outside the listing block.

Motivation

Aside from getting little practice around Ruby and JavaScript, I decided to have a crack at this to help with a problem that comes up at work every so often.

The callout mechanism for Asciidoc works extremely well in 99% of the cases I run into:

[source,ruby]
----
require 'sinatra' #<1>

get '/hi' do #<2> #<3>
  "Hello World!"
end
----
<1> Library import
<2> URL mapping
<3> Response block

Great, but it does mean you have to add commented to the tags to the source code to register the callout in the following block. As I've said, this is fine, 99% of the time, but I've run across a few occasions when adding tags to the source code (either in-line or an included file) can be a little problematic:

  1. Restricted access to the source code: as a humble tech-writer, you might not have access to the included source code to add your own tags.
  2. The source code has to remain runnable but doesn't have a commenting mechanism that works well with Asciidoc (shell scripts and Json files spring to mind.)

A possible Solution

And that's where this extension comes in: it adds support adding tags outside the source listing block, like this:

[source,ruby]
----
require 'sinatra'

get '/hi' do
  "Hello World!"
end
----
. Library import @3
. URL mapping @5
. Response block @5

Rather than tagging the code, you add a location token at the end of a list item, which will then add the tag at the specified line number. Run the source text through Asciidoctor{plus}extension, and it will split the same source block complete with callouts.

Two types of location token are supported:

@number -- This format takes a numeric value indicating the line in the source block where the callout should appear. The callouts will appear at the end of the line. Multiple callouts on the same line will have a single space between them.

@/text/ -- The text between the two slashes will be used in a regex search. A callout will be placed at the end of the first matching line. If you have a large listing, then it may be preferable to use the text search rather than counting all the lines. It may also be preferable to use a smaller listing, as a long listing might mean that your description is a bit too general. Using the text search method means that the location of the callout will move with the line; handy if you're referencing a source file that might get the occasional tweak outside your control.

@/text/g : Works the same as the standard text search; the g flag means that callouts will be added to all the lines that match the search string, instead of just the first one.

@/text/i : This is a case-insensitive search.

@/text/gi : And of course, you can combine the two, though I'm not sure why you'd want to.

You can have multiple callouts on the same line. You can also mix and match numeric and text callout tokens on the same list item. (Though I'm not sure why you would).

Standalone callout lists

You can create a standalone callout list by adding the calloutlist role to an ordered list. This simply styles the list to make it look like a list of callouts, so you can use it as a reference to annoted images etc.

[calloutlist]
. This list can be used to add references to annotated images
. The list will look like a standard callout list.

Installation

Node module

You can include the extension as part of a Node project by running the npm installcommand.

npm install asciidoctor-external-callout

To call it as part of an Asciidoctor conversion, then register the module then register before calling a convert function:

const asciidoctor = require('@asciidoctor/core')()
const registry = asciidoctor.Extensions.create()
require('asciidoctor-external-callout')(registry)

asciidoctor.convertFile('./sample.adoc', {safe: 'safe', standalone: true, extension_registry: registry})

Antora

Install the callout extension as part of the Antora installation. The Node setup is usually the same directory from where you run the antora script.

npm install asciidoctor-external-callout

You will also need to register the extension in the playbook used to generate the site:

  extensions:
    - asciidoctor-external-callout

Formatting

By default, the callout extension will put a single space between callouts that occur on the same line. If you want to adjust this, then you need to create a style that puts a horizontal margin between the callouts:

div.external-callout-block i.conum {
    margin-left: 10px;
    margin-right: 10px;
}

The callout attaches a class called external-callout-block to each source listing it processes. You can use this to differentiate between standard callouts, and callouts written by the extension.

The extension also adds a class called external-callout-list to the list of definitions at the bottom of the source block. (There's probably no need to adjust the styling for this.)

changelog (log de mudanças)

Changelog

Record of bug fixes, enhancements, and changes.

[1.2.2] - 2025-05-04

  • Fixed bug caused the callout to apply all the callout to every line it matched, rather than just the first occurrence.

[1.2.1] – 2022-09-16

Fixed

  • Fixed detection of source blocks that are nested inside other blocks.

[1.2.0] – 2022-07-30

Added

  • If you add the role [calloutlist] to an ordered list then it will be styled to look like a callout list. This allows you to add callouts to annotated images etc.

[1.1.3] – 2022-07-07-16

Fixed

  • The global and case-insensitive flags (ig) are now parsing correctly: using ii or gg will prevent the callout block from being processed. Thanks to Hakim Cassimally for finding the bug.
  • Escaped slash characters were not being processed in the search. Thanks to Hakim Cassimally for finding the bug.
  • [1.1.1] – 2022-06-23

Fixed

  • Fixed regular expression to correctly detect new flags.

[1.1.0] – 2022-06-23

Added

  • The text search now supports a global flag (@/text/g). The g flag will add the callout to all the lines that match the search criteria. Use wisely.
  • Added the i flag for case-insensitive searches: (@/text/i). Again, don't go mad.

[1.0.0] – 2022-06-16

Added

  • Added roles to the source block and the callout list so that CSS folk can pick them out to make style changes (For example, adjusting the gap between callout items in the source code block.)

[0.0.6-beta6] – 2022-06-11

Changed

  • Ordered lists were only processes if they occurred directly beneath a source listing block. This turns out to be quite restrictive and doesn't follow Asciidoc's stance on processing standard callouts, which allows for intermediate blocks to separate the source list from the attached callout list.\ The processor will now allow intermediate blocks to separate the source listing from the ordered list containing callouts.
  • Fixed a few spelling mistakes and a code line where I was picking up a formatted item, rather than a raw item.