transform-files

This module provides functions to transform document files (primarily DOCX) to HTML and Markdown using Pandoc, handling asset extraction and URL updates.

Description:
  • This module provides functions to transform document files (primarily DOCX) to HTML and Markdown using Pandoc, handling asset extraction and URL updates.

Source:

Members

(static, constant) defaults :TransformFilesOptions

Description:
  • Default configuration for the pandoc function.

Source:

Default configuration for the pandoc function.

Type:
  • TransformFilesOptions

Methods

(async, static) transformFiles(userOptions) → {Promise.<void>}

Description:
  • Transforms files from DOCX to HTML and Markdown using Pandoc.

Source:
Parameters:
Name Type Description
userOptions TransformFilesOptions

User-provided options to override the defaults.

Returns:

A Promise that resolves when the transformation is complete.

Type
Promise.<void>

(inner) handleError(title, filepath, error)

Description:
  • Handles errors during file processing.

Source:
Parameters:
Name Type Description
title string

The error title.

filepath string

The path to the file being processed.

error Error

The error object.

(async, inner) processFile(filepath, index, options) → {Promise.<void>}

Description:
  • Processes a single file, converting it to HTML and Markdown.

Source:
Parameters:
Name Type Description
filepath string

The path to the file to process.

index number

The index of the file in the list.

options Options

The processing options.

Returns:

A Promise that resolves when the file is processed.

Type
Promise.<void>

Type Definitions

TransformFilesOptions

Description:
  • Default options for the transformFiles function.

Source:
Properties:
Name Type Description
inputDir string

The directory containing the input files.

outputDir string

The directory where the output files will be written.

assetDir string

The directory where extracted media (images, etc.) will be written.

assetPublicPath string

The final asset path (images/etc paths are modified to point at this absolute path, like the base path in site it will be used in).

pattern string

The glob pattern used to select input files.

emptyOutputDir boolean

Empty (delete contents) of output directory before populating

emptyAssetDir boolean

Empty (delete contents) of asset directory before populating

updateAssetUrls boolean

Whether you want the asset paths (absolute based on assetDir) to be updated to assetPublicPath (relative as though in a website/etc)

adapterOptions.allowError boolean

Allow errors from pandoc.

adapterOptions.allowStdoutError boolean

Allow errors from pandoc stdout.

adapterOptions.execFile object

Options for the child_process.execFile.

Properties
Name Type Description
maxBuffer number

Maximum buffer size.

getFileOutputPath function

Function to determine the output file path.

getFileOutputDir function

Function to determine the output directory.

getFileAssetDir function

Function to determine the asset extraction directory.

getHtmlArgs function

Function to generate Pandoc arguments for HTML conversion.

getMarkdownArgs function

Function to generate Pandoc arguments for Markdown conversion.

beforeWrite function

Function to modify the output before writing to disk.

Default options for the transformFiles function.

Type:
  • object