Module Asciidoctor::Helpers
In: lib/asciidoctor/helpers.rb

Methods

Constants

REGEXP_ENCODE_URI_CHARS = /[^\w\-.!~*';:@=+$,()\[\]]/   Matches the characters in a URI to encode

Public Class methods

Public: Retrieves the basename of the filename, optionally removing the extension, if present

filename - The String file name to process. drop_ext - A Boolean flag indicating whether to drop the extension

           or an explicit String extension to drop (default: nil).

Examples

  Helpers.basename('images/tiger.png', true)
  # => "tiger"

  Helpers.basename('images/tiger.png', '.png')
  # => "tiger"

Returns the String filename with leading directories removed and, if specified, the extension removed

Public: Normalize the data to prepare for parsing

Delegates to Helpers#normalize_lines_from_string if data is a String. Delegates to Helpers#normalize_lines_array if data is a String Array.

returns a String Array of normalized lines

Public: Normalize the array of lines to prepare them for parsing

Force encodes the data to UTF-8 and removes trailing whitespace from each line.

If a BOM is present at the beginning of the data, a best attempt is made to encode from the specified encoding to UTF-8.

data - a String Array of lines to normalize

returns a String Array of normalized lines

Public: Normalize the String and split into lines to prepare them for parsing

Force encodes the data to UTF-8 and removes trailing whitespace from each line. Converts the data to a String Array.

If a BOM is present at the beginning of the data, a best attempt is made to encode from the specified encoding to UTF-8.

data - a String of lines to normalize

returns a String Array of normalized lines

Internal: Require the specified library using Kernel#require.

Attempts to load the library specified in the first argument using the Kernel#require. Rescues the LoadError if the library is not available and passes a message to Kernel#raise if on_failure is :abort or Kernel#warn if on_failure is :warn to communicate to the user that processing is being aborted or functionality is disabled, respectively. If a gem_name is specified, the message communicates that a required gem is not installed.

name - the String name of the library to require. gem_name - a Boolean that indicates whether this library is provided by a RubyGem,

             or the String name of the RubyGem if it differs from the library name
             (default: true)

on_failure - a Symbol that indicates how to handle a load failure (:abort, :warn, :ignore) (default: :abort)

returns The return value of Kernel#require if the library is available and can be, or was previously, loaded. Otherwise, Kernel#raise is called with an appropriate message if on_failure is :abort. Otherwise, Kernel#warn is called with an appropriate message and nil returned if on_failure is :warn. Otherwise, nil is returned.

Public: Removes the file extension from filename and returns the result

filename - The String file name to process

Examples

  Helpers.rootname('part1/chapter1.adoc')
  # => "part1/chapter1"

Returns the String filename with the file extension removed

Public: Encode a String for inclusion in a URI.

str - the String to URI encode

Returns the String with all URI reserved characters encoded.

Public: Efficiently retrieves the URI prefix of the specified String

Uses the Asciidoctor::UriSniffRx regex to match the URI prefix in the specified String (e.g., http://), if present.

str - the String to check

returns the string URI prefix if the string is a URI, otherwise nil

Public: Efficiently checks whether the specified String resembles a URI

Uses the Asciidoctor::UriSniffRx regex to check whether the String begins with a URI prefix (e.g., http://). No validation of the URI is performed.

str - the String to check

returns true if the String is a URI, false if it is not

[Validate]