@asciidoctor/core

2.0.3

The main application interface (API) for Asciidoctor. This API provides methods to parse AsciiDoc content and convert it to various output formats using built-in or third-party converters.

An AsciiDoc document can be as simple as a single line of content, though it more commonly starts with a document header that declares the document title and document attribute definitions. The document header is then followed by zero or more section titles, optionally nested, to organize the paragraphs, blocks, lists, etc. of the document.

By default, the processor converts the AsciiDoc document to HTML 5 using a built-in converter. However, this behavior can be changed by specifying a different backend (e.g., +docbook+). A backend is a keyword for an output format (e.g., DocBook). That keyword, in turn, is used to select a converter, which carries out the request to convert the document to that format.

Asciidoctor
Example
asciidoctor.convertFile('document.adoc', { 'safe': 'safe' }) // Convert an AsciiDoc file

asciidoctor.convert("I'm using *Asciidoctor* version {asciidoctor-version}.", { 'safe': 'safe' }) // Convert an AsciiDoc string

const doc = asciidoctor.loadFile('document.adoc', { 'safe': 'safe' }) // Parse an AsciiDoc file into a document object

const doc = asciidoctor.load("= Document Title\n\nfirst paragraph\n\nsecond paragraph", { 'safe': 'safe' }) // Parse an AsciiDoc string into a document object
Static Members
▸ getCoreVersion()
▸ getRuntime()
▸ convert(input, options)
▸ convertFile(filename, options)
▸ load(input, options)
▸ loadFile(filename, options)
▸ getVersion()
▸ getVersion()
AbstractBlock

Extends AbstractNode

Static Members
▸ append(block)
▸ getTitle()
▸ getCaptionedTitle()
▸ getStyle()
▸ getCaption()
▸ setCaption(caption)
▸ getLevel()
▸ getSubstitutions()
▸ hasSubstitution(substitution)
▸ removeSubstitution(substitution)
▸ hasBlocks()
▸ getBlocks()
▸ getContent()
▸ convert()
▸ findBy(selector?, block?)
▸ getLineNumber()
▸ hasSections()
▸ getSections()
▸ getNumeral()
▸ setNumeral(value)
▸ hasTitle()
Section

Extends AbstractBlock

Static Members
▸ getIndex()
▸ setIndex(value)
▸ getSectionName()
▸ setSectionName(value)
▸ isSpecial()
▸ setSpecial(value)
▸ isNumbered()
▸ getCaption()
▸ getName()
Block
Static Members
▸ getSource()
▸ getSourceLines()
AbstractNode
Static Members
▸ getAttributes()
▸ getAttribute(name, defaultValue, inherit)
▸ hasAttribute(name)
▸ isAttribute(name, expectedValue, inherit)
▸ setAttribute(name, value, overwrite)
▸ removeAttribute(name)
▸ getDocument()
▸ getParent()
▸ isRole(expected)
▸ hasRole(name)
▸ addRole(name)
▸ removeRole(name)
▸ isOption(name)
▸ setOption(name)
▸ getIconUri(name)
▸ getMediaUri(target, assetDirKey)
▸ getImageUri(targetImage, assetDirKey)
▸ getConverter()
▸ readContents(target, options)
▸ readAsset(path, options)
▸ normalizeWebPath(target, start, preserveTargetUri)
▸ normalizeSystemPath(target, start, jail, options)
▸ normalizeAssetPath(assetRef, assetName, autoCorrect)

The Document class represents a parsed AsciiDoc document.

Document is the root node of a parsed AsciiDoc document.
It provides an abstract syntax tree (AST) that represents the structure of the AsciiDoc document from which the Document object was parsed.

Although the constructor can be used to create an empty document object, more commonly, you'll load the document object from AsciiDoc source using the primary API methods on Asciidoctor. When using one of these APIs, you almost always want to set the safe mode to 'safe' (or 'unsafe') to enable all of Asciidoctor's features.

  var doc = Asciidoctor.load('= Hello, AsciiDoc!', { 'safe': 'safe' })
  // => Asciidoctor::Document { doctype: "article", doctitle: "Hello, AsciiDoc!", blocks: 0 }

Instances of this class can be used to extract information from the document or alter its structure. As such, the Document object is most often used in extensions and by integrations.

The most basic usage of the Document object is to retrieve the document's title.

 var source = '= Document Title'
 var doc = asciidoctor.load(source, { 'safe': 'safe' })
 console.log(doc.getTitle()) // 'Document Title'

You can also use the Document object to access document attributes defined in the header, such as the author and doctype.

Document

Extends AbstractBlock

Static Members
▸ getRefs()
▸ getImages()
▸ hasFootnotes()
▸ getFootnotes()
▸ getHeader()
▸ setAttribute(name, value)
▸ removeAttribute(name)
▸ convert(options)
▸ write(output, target)
▸ getAuthor()
▸ getSourceLines()
▸ hasExtensions()
▸ isBasebackend(base)
▸ getTitle()
▸ setTitle(title)
▸ getDocumentTitle(options)
▸ getCatalog()
▸ getRevisionDate()
▸ getRevisionNumber()
▸ getRevisionRemark()
▸ setHeaderAttribute(name, value, overwrite)
▸ getAuthors()
▸ hasRevisionInfo()
▸ deleteAttribute(name)
▸ isAttributeLocked(name)
▸ parse(data)
▸ getDocinfo(docinfoLocation, suffix)
▸ hasDocinfoProcessors(docinfoLocation)
▸ counterIncrement(counterName, block)
▸ counter(name, seed)
▸ getCompatMode()
▸ getSourcemap()
▸ getOutfilesuffix()
▸ getParentDocument()
▸ getConverter()
▸ getExtensions()
Document/Footnote
Static Members
▸ getIndex()
▸ getId()
▸ getText()
Document/ImageReference
Static Members
▸ getTarget()
▸ getImagesDirectory()
Document/Author
Static Members
▸ getName()
▸ getFirstName()
▸ getMiddleName()
▸ getLastName()
▸ getInitials()
▸ getEmail()
Document/RevisionInfo
Static Members
▸ getDate()
▸ getNumber()
▸ getRemark()
▸ isEmpty()
Document/Title
Static Members
Inline

Extends AbstractNode

Static Members
▸ create(parent, context, text, opts)
▸ convert()
▸ getText()
▸ getType()
▸ getTarget()
List
Static Members
▸ hasItems()
▸ getItems()
ListItem
Static Members
▸ getText()
▸ setText(text)
▸ hasText()
▸ getMarker()
▸ setMarker(marker)
▸ getList()
Reader
Static Members
▸ pushInclude(data, file, path, lineno, attributes)
▸ getCursor()
▸ getLines()
▸ getString()
▸ hasMoreLines()
▸ isEmpty()
▸ peekLine(direct)
▸ readLine()
▸ readLines()
▸ read()
Cursor
Static Members
▸ getFile()
▸ getDirectory()
▸ getPath()
▸ getLineNumber()
LoggerManager
LoggerSeverity
LoggerFormatter
MemoryLogger
Logger
NullLogger
Timings

This API is experimental and subject to change.

A pluggable adapter for integrating a syntax (aka code) highlighter into AsciiDoc processing.

There are two types of syntax highlighter adapters. The first performs syntax highlighting during the convert phase. This adapter type must define a "handlesHighlighting" method that returns true. The companion "highlight" method will then be called to handle the "specialcharacters" substitution for source blocks.

The second assumes syntax highlighting is performed on the client (e.g., when the HTML document is loaded). This adapter type must define a "hasDocinfo" method that returns true. The companion "docinfo" method will then be called to insert markup into the output document. The docinfo functionality is available to both adapter types.

Asciidoctor.js provides several a built-in adapter for highlight.js. Additional adapters can be registered using SyntaxHighlighter.register.

SyntaxHighlighter
Static Members
▸ register(names, functions)
▸ for(name)
SyntaxHighlighterBase
Static Members
▸ registerFor(names)

Extensions provide a way to participate in the parsing and converting phases of the AsciiDoc processor or extend the AsciiDoc syntax.

The various extensions participate in AsciiDoc processing as follows:

  1. After the source lines are normalized, {Extensions/Preprocessor}s modify or replace the source lines before parsing begins. {Extensions/IncludeProcessor}s are used to process include directives for targets which they claim to handle.
  2. The Parser parses the block-level content into an abstract syntax tree. Custom blocks and block macros are processed by associated {Extensions/BlockProcessor}s and {Extensions/BlockMacroProcessor}s, respectively.
  3. {Extensions/TreeProcessor}s are run on the abstract syntax tree.
  4. Conversion of the document begins, at which point inline markup is processed and converted. Custom inline macros are processed by associated {InlineMacroProcessor}s.
  5. {Extensions/Postprocessor}s modify or replace the converted document.
  6. The output is written to the output stream.

Extensions may be registered globally using the {Extensions.register} method or added to a custom {Registry} instance and passed as an option to a single Asciidoctor processor.

Extensions
Example
Opal.Asciidoctor.Extensions.register(function () {
  this.block(function () {
    var self = this;
    self.named('shout');
    self.onContext('paragraph');
    self.process(function (parent, reader) {
      var lines = reader.getLines().map(function (l) { return l.toUpperCase(); });
      return self.createBlock(parent, 'paragraph', lines);
    });
  });
});
Static Members
▸ create(name, block)
▸ register(name, block)
▸ getGroups()
▸ unregisterAll()
▸ unregister()
▸ createPostprocessor(name, functions)
▸ newPostprocessor(name, functions)
▸ createPreprocessor(name, functions)
▸ newPreprocessor(name, functions)
▸ createTreeProcessor(name, functions)
▸ newTreeProcessor(name, functions)
▸ createIncludeProcessor(name, functions)
▸ newIncludeProcessor(name, functions)
▸ createDocinfoProcessor(name, functions)
▸ newDocinfoProcessor(name, functions)
▸ createBlockProcessor(name, functions)
▸ newBlockProcessor(name, functions)
▸ createInlineMacroProcessor(name, functions)
▸ newInlineMacroProcessor(name, functions)
▸ createBlockMacroProcessor(name, functions)
▸ newBlockMacroProcessor(name, functions)
Extensions/Registry
Static Members
▸ prefer(name, processor)
▸ block(name, processor)
▸ inlineMacro(name, processor)
▸ includeProcessor(name, processor)
▸ blockMacro(name, processor)
▸ treeProcessor(name, processor)
▸ postprocessor(name, processor)
▸ preprocessor(name, processor)
▸ docinfoProcessor(name, processor)
▸ hasPreprocessors()
▸ hasTreeProcessors()
▸ hasIncludeProcessors()
▸ hasPostprocessors()
▸ hasDocinfoProcessors(location)
▸ hasBlocks()
▸ hasBlockMacros()
▸ hasInlineMacros()
▸ getPreprocessors()
▸ getTreeProcessors()
▸ getIncludeProcessors()
▸ getPostprocessors()
▸ getDocinfoProcessors(location)
▸ getBlocks()
▸ getBlockMacros()
▸ getInlineMacros()
▸ getInlineMacroFor(name)
▸ getBlockFor(name, context)
▸ getBlockMacroFor(name)
Extensions/Processor
Static Members
▸ prepend()
▸ process(block)
▸ named(name)
▸ createBlock(parent, context, source, attrs, opts)
▸ createList(parent, context, attrs)
▸ createListItem(parent, text)
▸ createImageBlock(parent, attrs, opts)
▸ createInline(parent, context, text, opts)
▸ parseContent(parent, content, attrs)
▸ positionalAttributes(value)
▸ resolvesAttributes(args)
Extensions/BlockProcessor
Static Members
▸ onContext(context)
▸ parseContentAs(value)
Extensions/BlockMacroProcessor
Static Members
▸ parseContentAs(value)
Extensions/InlineMacroProcessor
Static Members
▸ parseContentAs(value)
▸ matchFormat(value)
Extensions/IncludeProcessor
Static Members
▸ handles(block)
Extensions/TreeProcessor
Static Members
Extensions/Postprocessor
Static Members
Extensions/Preprocessor
Static Members
Extensions/DocinfoProcessor
Static Members
▸ atLocation(value)
Converter
Static Members
▸ convert(node, transform, opts)
Converter/Factory
Static Members
▸ create(backend, opts)
▸ create(backend, opts)
▸ register(converter, backends)
▸ getDefault(initialize)
Converter/Html5Converter