Skip to content

Loader

The main way to use this library is through the use of the Asciidoc Loader. The loader is a function that loads files from a folder using a path to a folder and the collection's name. This loader will always search for the file extensions .adoc or .asciidoc. It then uses both the folder path specified and the content collection name. To extract Asciidoc files and transform them into entries.

function asciidocLoader(contentFolderName:string):Loader

Usage

To use this package import it from the @forastro/asciidoc namespace. Then use it in the content.config.ts file.

import { z, defineCollection } from "astro:content"
import { asciidocLoader } from "@forastro/asciidoc"
export const collections = {
blog: defineCollection(
{
loader: asciidocLoader("src/content/")
schema: z.object({
doctitle: z.string(),
})
}
),
}

Features

Configuration

To configure the loader you must create an asciidoc.config.m{js,ts} file. This file expect's a default export of an object literal. The props are supposed to be attributes, macros, and blocks. The macros are either inline or block.

export default {
attributes: {
author: "Erika Moreau"
},
blocks: {
shout: {
context: "pass",
render:()=> "shout"
}
},
macros:{
inline: {
superLink: {
context: 'quote',
render:()=> "superLink"
}
},
block: {
tip: {
context: "pass",
render:(target)=> `TIP: ${target} `
}
}
}
}

The attributes prop is a set of global attributes that will be the default for all Asciidoc Documents. When you use these attributes by default the shiki highlighter will be activated.

namevalue
authorMust be FirstName LastName with capitals (e.g., John Smith)
emailAny valid email address (e.g., user@example.com)
backendAny string value for the backend processor
filetypetrue or false to enable/disable filetype processing
localdirAny string value representing a directory path
localdateValid date in YYYY-MM-DD format (e.g., 2024-01-10)
localdatetimeValid datetime in ISO format (e.g., 2024-01-10T15:30:00)
localtimeValid time in HH:MM:SS format (e.g., 15:30:00)
localyearInteger year value (e.g., 2024)
attributeMissingOne of: drop, drop-line, skip, warn
attributeUndefinedOne of: drop, drop-line
experimentaltrue or false to enable experimental features
leveloffsetNumber from 0 to 5 for section level offset
partnumstrue or false to enable part numbers
setanchorstrue or false to automatically generate anchors
sectidstrue or false to generate section IDs
sectlinkstrue or false to enable section links
sectnumstrue or false to enable section numbering
sectnumlevelsNumber from 0 to 5 for section numbering depth
tocOne of: true, auto, left, right, macro, preamble
toclevelsNumber from 1 to 5 for TOC depth
fragmenttrue or false to process as document fragment
sourceHighlighterEither "prism" or "shiki" for code highlighting
prismLanguagesArray of language names (e.g., javascript, typescript, markdown).
Default includes: markup, css, javascript, typescript, markdown, yaml, json, jsx, tsx, asciidoc, bash, php, git
shikiThemeConfiguration object with:
light: theme name for light mode
dark: theme name for dark mode
dim: optional theme name for dim mode
Default: github-light, github-dark, github-dark-dimmed

The block prop is a prop that takes in an object. The object's keys are the names of the block's.

The value's are an object that takes in these props.

  • The context: the type of block that will be created the values are:

    • listing
    • literal
    • pass
    • quote
    • sidebar
  • The render: A function that takes in a string and a set of attributes. The string is some preprocessed content. The attributes are the attributes from the attributes list.

The macro prop is a prop that take's either an inline or a block prop. Both props take in props where the keys are the names of either inline or block macros.

The values are an object that take in a context and a render.

  • For the inline macros the value for context can only be:
    • quoted
    • anchor
  • For block marcos the value for context can only be:
    • listing
    • literal
    • pass
    • quote
    • sidebar

Both block and inline marco's render function take in the target as the first parameter and a set of attributes as the second parameter.