An extendable Markdown parser.
Note
This is mostly meant as a hobby project. It is meant to be useful for me. Use it at your own risk.
parse(text: string, config: ParseConfiguration = defaultParseConfiguration): Document
Parses source code into a Sharkdown document.
text: string- The source code to parse.config: ParseConfiguration- Parse configuration.
const config: ParseConfiguration = {
blocks: {
// Parsers for custom blocks.
parsers: [],
},
elements: {
// Allowed custom elements.
allowed: ["div", "aside", "section", "article", "header", "footer", "nav", "main", "figure", "figcaption"],
},
attributes: {
// Allowed attributes on custom elements.
allowed: ["style", /^data-.+/, /^aria-.+/],
},
}#!/usr/bin/env node
import { readFile, writeFile } from "fs/promises";
import { parse, toHTML } from "@hansjovis/sharkdown";
async function generate() {
const [ inFile, outFile ] = process.argv.slice(2);
if (!inFile) {
console.error("[ERROR] no source file defined");
return;
}
const sourceCode = await readFile(inFile, "utf-8");
const document = parse(sourceCode);
const html = toHTML(document);
await writeFile(outFile || "out.html", html);
}
generate();- Clone this repository using Git.
git clone ... - Install dependencies using NPM.
npm install - Compile the source code.
npm run compile - Run tests.
npm test - Run parser on sample document.
echo '# Hello world!' > test.md ./bin/parse-sharkdown.js test.md