asciidoctor.js

1.5.9

Methods for parsing AsciiDoc input files and converting documents.

AsciiDoc documents comprise a header followed by zero or more sections. Sections are composed of blocks of content. For example:

  = Doc Title

  == Section 1

  This is a paragraph block in the first section.

  == Section 2

  This section has a paragraph block and an olist block.

  . Item 1
  . Item 2
Asciidoctor
Example
asciidoctor.convertFile('sample.adoc');
Static Members
getCoreVersion()
getRuntime()
convert(input, options)
convertFile(filename, options)
load(input, options)
loadFile(filename, options)
getVersion()
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
getNodeName()
getAttributes()
getAttribute(name, defaultValue, inherit)
hasAttribute(name)
isAttribute(name, expectedValue, inherit)
setAttribute(name, value, overwrite)
removeAttribute(name)
getDocument()
getParent()
isInline()
isRole(expected)
hasRole(name)
getRoles()
addRole(name)
removeRole(name)
isReftext()
getReftext()
getContext()
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
getIds()
getRefs()
getImages()
getIndexTerms()
hasFootnotes()
getFootnotes()
getHeader()
setAttribute(name, value)
removeAttribute(name)
convert(options)
write(output, target)
getAuthor()
getSource()
getSourceLines()
isNested()
isEmbedded()
hasExtensions()
getDoctype()
getBackend()
isBasebackend(base)
getTitle()
setTitle(title)
getDocumentTitle(options)
getDoctitle
getCatalog()
getReferences
getRevisionDate()
getRevdate()
getRevisionNumber()
getRevisionRemark()
setHeaderAttribute(name, value, overwrite)
getAuthors()
hasRevisionInfo()
getNotitle()
getNoheader()
getNofooter()
hasHeader()
deleteAttribute(name)
isAttributeLocked(name)
parse(data)
getDocinfo(docinfoLocation, suffix)
hasDocinfoProcessors(docinfoLocation)
counterIncrement(counterName, block)
counter(name, seed)
getCompatMode()
getSourcemap()
getCounters()
getCallouts()
getBaseDir()
getOptions()
getOutfilesuffix()
getParentDocument()
getReader()
getConverter()
getExtensions()
Document/Footnote
Static Members
getIndex()
getId()
getText()

Document/ImageReference

src/asciidoctor-core-api.js
Document/ImageReference
Static Members
getTarget()
getImagesDirectory()
Document/Author
Static Members
getName()
getFirstName()
getMiddleName()
getLastName()
getInitials()
getEmail()

Document/RevisionInfo

src/asciidoctor-core-api.js
Document/RevisionInfo
Static Members
getDate()
getNumber()
getRemark()
isEmpty()
Document/Title
Static Members
getCombined()
getSubtitle()
isSanitized()
hasSubtitle()
Inline

Extends AbstractNode

Static Members
create(parent, context, text, opts)
convert()
getText()
getType()
getTarget()
List
Static Members
getItems()
ListItem
Static Members
getText()
setText(text)
Reader
Static Members
pushInclude(data, file, path, lineno, attributes)
getCursor()
getLines()
getString()
Cursor
Static Members
getFile()
getDirectory()
getPath()
getLineNumber()
LoggerManager
LoggerSeverity
LoggerFormatter
MemoryLogger
Logger
NullLogger

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
unregisterAll()
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)
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

src/asciidoctor-extensions-api.js
Extensions/BlockProcessor
Static Members
onContext(context)
onContexts()

Extensions/BlockMacroProcessor

src/asciidoctor-extensions-api.js
Extensions/BlockMacroProcessor
Static Members

Extensions/InlineMacroProcessor

src/asciidoctor-extensions-api.js
Extensions/InlineMacroProcessor
Static Members

Extensions/IncludeProcessor

src/asciidoctor-extensions-api.js
Extensions/IncludeProcessor
Static Members
handles(block)

Extensions/TreeProcessor

src/asciidoctor-extensions-api.js
Extensions/TreeProcessor
Static Members

Extensions/Postprocessor

src/asciidoctor-extensions-api.js
Extensions/Postprocessor
Static Members

Extensions/Preprocessor

src/asciidoctor-extensions-api.js
Extensions/Preprocessor
Static Members

Extensions/DocinfoProcessor

src/asciidoctor-extensions-api.js
Extensions/DocinfoProcessor
Static Members
atLocation(value)
Converter
Static Members
convert(node, transform, opts)
Converter/Factory
Static Members
register(converter, backends)
getDefault(initialize)
create(backend, opts)

Converter/Html5Converter

src/asciidoctor-extensions-api.js
Converter/Html5Converter