A small stack of Markdown tools (built on markdown-it) configured using the Architect team's preferred conventions for creating documentation and articles rendered and served from a cloud function.
Arcdown is an opinionated toolchain to create technical content from Markdown source files as quickly as possible to enable on-the-fly rendering in a Lambda (or any server) runtime.
Features
Document table of contents creator
Code syntax highlighter
Automatic frontmatter parsing
Generated HTML optimizations
Helpful return values
All built-ins are configurable and extensible.
Usage
Installation
npm install arcdown
ESM only, requires Node.js v14+
Example
The simplest usage is to just pass Arcdown.render a string of Markdown:
import { readFileSync } from'node:fs'import { Arcdown } from'arcdown'const mdString = `
---
title: Hello World
category: Examples
---
## Foo Bar
lorem ipsum _dolor_ sit **amet**
[Architect](https://arc.codes/)
`.trim()
const arcdown = newArcdown()
const {
frontmatter, // attributes from frontmatter
html, // the good stuff: HTML!
slug, // a URL-friendly slug
title, // document title from the frontmatter
tocHtml, // an HTML table of contents
} = await arcdown.render(mdString)
const fromFile = await arcdown.render(readFileSync('../docs/some-markdown.md', 'utf-8'))
Arcdown is set up to be used without any configuration. Out-of-the-box it uses defaults and conventions preferred by the Architect team (Architect project not required).
However, the renderer is customizable and extensible with a RendererOptions object.
🪧 See ./example/ for a kitchen sink demo.
markdown-it Config: markdownIt
markdownIt
Configure the core markdown-it renderer.
This config is passed directly to new MarkdownIt()
By default, html, linkify, and typographer are enabled.
Plugin Overrides: pluginOverrides
Three plugins are provided out-of-the-box and applied in a specific order.
Set configuration for each plugin by passing a keyed RendererOptions.pluginOverrides object.
⛔️ Disable a plugin by setting its key in pluginOverrides to false.
markdownItClass
Apply class names to each generated element based on its tag name. Provide a map of element names to an array of classes to be applied.
Perfect for utility class libraries.
This plugin is disabled unless configuration is provided.
markdown-it-toc-done-right enables users to include a copy of the table of contents in their markdown:
My Table of Contents:
${toc}
# The rest of## My document
User-Provided Plugins: plugins
It is possible to pass additional markdown-it plugins to Arcdown's renderer by populating RendererOptions.plugins.
Plugins can be provided in two ways and will be applied after the default plugins bundled with Arcdown.
plugins
The simplest method for extending markdown-it is to import a plugin function and provide it directly.
A custom highlight() method backed by Highlight.js is provided to the internal markdown-it renderer. Arcdown will detect languages used in fenced code blocks in the provided Markdown string and attempt to register just those languages in hljs.
⚠️ Currently, shorthand aliases for languages are not supported.
Full language names should be used with Markdown code fences. Instead of js, use javascript
Set Highlight.js configuration by passing a keyed RendererOptions.hljs object.
classString: string
A string that will be added to each <pre class=""> wrapper tag for highlighted code blocks.
ignoreIllegals: true is the default, but can be set by the user.
languages: object
Additional language syntaxes can be added from third party libraries.
If needed, Highlight.js built-in languages can be disabled by setting their key to false.
A couple plugins have been forked and/or vendored locally to this package. This has been done to increase performance and render speed.
Arcdown is not attached to any single package, plugin, or even to the core rendering engine, so long as the resulting features are maintained.
Suggestions and PRs welcome 🙏
FAQs & Decisions
Why markdown-it?
A great balance of speed, stability, adoption, and extensibility.
Why Highlight.js?
Most syntax highlighters are not fast enough for server-side rendering. hljs was tuned to work on slow client machines and performs well on a server.
That said, starry-night is really interesting.
Why plugin ___?
Because we used it a lot building docs sites and technical blogs.
Credits
In no particular order
markdown-it and their community for a solid .md ecosystem
highlight.js for a battle-tested highlighter
Architect and Begin for helping test/break things
@galvez for the rad readme.md formatting conventions
A small stack of Markdown tools configured using the Architect's team preferred conventions.
The npm package arcdown receives a total of 142 weekly downloads. As such, arcdown popularity was classified as not popular.
We found that arcdown demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.It has 1 open source maintainer collaborating on the project.
Package last updated on 22 Feb 2024
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
The Socket Threat Research Team uncovered a coordinated campaign that floods the Chrome Web Store with 131 rebranded clones of a WhatsApp Web automation extension to spam Brazilian users.