mdpack: Markdown Bundler

0.5.2 · maintenance · verified Tue Apr 21

mdpack is a markdown bundler that enables the composition of markdown and HTML files, treating them similarly to how JavaScript modules are imported. It processes custom `@@import` statements to combine content from various files and can output the bundled result in both markdown and HTML formats. The package, currently at version 0.5.2 (last published in August 2018), provides both a Command Line Interface (CLI) and a Node.js API for programmatic use. Key features include a plugin system, allowing extensions for tasks like HTML minification or adding banners and footers to the bundled output. While the project's README mentions alternatives like `docz` and labels its section on it as "Deprecated" (referring to `docz` or its own aspiration), `mdpack` differentiates itself through its specific custom import syntax and its dual output capabilities for markdown and HTML. Its release cadence is currently inactive, given the last publish date.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates programmatic use of `mdpack` with a full configuration, including output paths, custom CSS resources, HTML templates, and two plugins (HTML minifier and banner/footer). It also includes setup for dummy files to ensure the example is runnable.

const path = require('path');
const mdpack = require('mdpack');

const config = {
  entry: 'index.md',
  output: {
    path: path.resolve(__dirname, 'dist'),
    name: 'mybundle'
  },
  format: ['md', 'html'],
  resources: {
    markdownCss: 'https://unpkg.com/github-markdown-css@2.10.0/github-markdown.css',
    highlightCss: 'https://unpkg.com/highlight.js@9.12.0/styles/github-gist.css'
  },
  template: path.resolve(__dirname, 'mytemplate.html'),
  plugins: [
    new mdpack.plugins.mdpackPluginHtmlMinifier(),
    new mdpack.plugins.mdpackPluginBannerFooter({
      banner: '# My Custom Banner',
      footer: '<footer>Built with mdpack</footer>'
    })
  ],
  watch: false // Set to true for development
};

// Create dummy files for the example to run
require('fs').writeFileSync('index.md', '# Hello World\n\n@@import "./sub.md"');
require('fs').writeFileSync('sub.md', '## Sub-content here');
require('fs').writeFileSync('mytemplate.html', '<!DOCTYPE html><html><head><title>My Bundle</title></head><body><div class="markdown-body">{html}</div></body></html>');

mdpack(config).then(() => console.log('mdpack bundled successfully!')).catch(err => console.error('mdpack error:', err));

view raw JSON →