leaner-doc-utils
v1.0.3
Published
Vite plugins for generating static HTML documentation
Downloads
7
Maintainers
Readme
leaner-doc-utils
A collection of Vite plugins for generating static HTML documentation from Markdown files.
Usage
To use leaner-doc-utils, you need:
- a
vite.config.jsfile which imports the plugins - an
index.htmltemplate file using Handlebars syntax - a subdirectory containing Markdown files
- CSS and (optionally) JavaScript files loaded by
index.htmland processed using Vite
buildDocs()
The buildDocs() Vite plugin runs after Vite has finished transforming the index.html file and generating the bundle. It reads the transformed index.html as a Handlebars template, converts the Markdown files into HTML using markdown-it and renders the final HTML files using the template.
When Vite is started in watch mode, the plugin automatically updates the HTML files when the source Markdown files are modified. It also starts a simple development server with hot-reloading. The plugin is not compatible with Vite's own development server.
The following options can be passed to the plugin:
buildDocs( {
title: 'My Site',
nav: [
{ text: 'Link', link: '/file.html' },
// ...
],
sidebar: {
'example': {
text: 'Example',
items: [
{ text: 'Link', link: '/file.html' },
// ...
],
},
// ...
},
dir: 'docs',
port: 3000,
tags: {
'$TAG$': 'replacement',
// ...
},
onStartup( server ) {
console.log( `Listening on ${server.baseUrl}` );
},
} );titleis appended to theH1heading to create the page titlenavcontains an array of links included in the page headersidebarcontains one or more menus that can be included in the sidebardiris the path of the directory containing.mdfiles, relative to the root path (default:'docs')portis used by the development server (default: 3000)tagsis an optional object containing tags which are replaced in the.mdfiles using simple search and replaceonStartupis an optional callback executed when the development server is started
inlineScript()
The inlineScript() Vite plugin makes it possible to inline JavaScript files into index.html using the following syntax:
<script src="./src/inline.js" type="inline"></script>The script is minified with esbuild and wrapped in IIFE:
<script>(()=>{...})();</script>Markdown Extensions
The following Markdown extensions are supported:
Front Matter
---
title: Custom Title
meta:
description: Description of the page
sidebar: example
---The front matter is a fenced block indicated by three dashes. It must contain a valid YAML document. The following front matter options are supported:
title- custom page title which overrides the default onemeta- dictionary used to generate<meta>tagssidebar- name of the menu inserted into the sidebar (if not given, no sidebar is included)
Hero Block
::: hero
<h2>Hero title</h2>
<p>Hero content.</p>
:::The hero is a fenced block indicated by three colons and the hero keyword. It should contain HTML inserted into the hero section of the template page.
Alert Block
::: warning
The content of the alert.
:::The alert is a fenced block indicated by three colons and one of the following keywords: info, tip, warning or danger, followed by an optional custom heading.
Code Highlighting
Shiki is used for code highlighting. Light and dark themes are supported.
Table of Contents
A TOC is automatically generated from H2 headings and inserted into the sidebar menu.
License
The leaner-doc-utils package is open-source software released under the MIT License. © 2025 Michał Męciński.
