Convert markdownlint library to an ECMAScript module, replace markdownlint-micromark with micromark, stop publishing (large) markdownlint-browser.js, see https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c for guidance.

This commit is contained in:
David Anson 2024-11-28 20:36:44 -08:00
parent 191226f070
commit 1e71f6f44e
140 changed files with 1087 additions and 10428 deletions

9
demo/browser-exports.mjs Normal file
View file

@ -0,0 +1,9 @@
// @ts-check
export { default as markdownlint } from "../lib/markdownlint.mjs";
export { compile, parse, postprocess, preprocess } from "micromark";
export { directive, directiveHtml } from "micromark-extension-directive";
export { gfmAutolinkLiteral, gfmAutolinkLiteralHtml } from "micromark-extension-gfm-autolink-literal";
export { gfmFootnote, gfmFootnoteHtml } from "micromark-extension-gfm-footnote";
export { gfmTable, gfmTableHtml } from "micromark-extension-gfm-table";
export { math, mathHtml } from "micromark-extension-math";

View file

@ -34,8 +34,6 @@
</div>
</div>
<script src="markdown-it.min.js"></script>
<script src="micromark-browser.js"></script>
<script src="micromark-html-browser.js"></script>
<script src="markdownlint-browser.min.js"></script>
<script src="default.js"></script>
</body>

View file

@ -3,9 +3,8 @@
(function main() {
// Dependencies
var markdownit = globalThis.markdownit;
var markdownlint = globalThis.markdownlint.library;
var micromark = globalThis.micromarkBrowser;
var micromarkHtml = globalThis.micromarkHtmlBrowser;
var markdownlint = globalThis.markdownlint.markdownlint;
var micromark = globalThis.markdownlint;
// DOM elements
var markdown = document.getElementById("markdown");
@ -70,15 +69,15 @@
const compileOptions = {
"allowDangerousHtml": true,
"htmlExtensions": [
micromarkHtml.directiveHtml({ "*": handleDirective }),
micromarkHtml.gfmAutolinkLiteralHtml(),
micromarkHtml.gfmFootnoteHtml(),
micromarkHtml.gfmTableHtml(),
micromarkHtml.mathHtml()
micromark.directiveHtml({ "*": handleDirective }),
micromark.gfmAutolinkLiteralHtml(),
micromark.gfmFootnoteHtml(),
micromark.gfmTableHtml(),
micromark.mathHtml()
]
};
try {
return micromarkHtml.compile(compileOptions)(events);
return micromark.compile(compileOptions)(events);
} catch (error) {
return `[Exception: "${error}"]`;
}

File diff suppressed because it is too large Load diff

View file

@ -1,8 +0,0 @@
// @ts-check
"use strict";
module.exports = {
"library": require(".."),
"helpers": require("../helpers")
};

8
demo/module-stub.cjs Normal file
View file

@ -0,0 +1,8 @@
// @ts-check
"use strict";
module.exports = {
// @ts-ignore
"createRequire": () => require
};

View file

@ -1,11 +1,14 @@
// @ts-check
"use strict";
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
import webpack from "webpack";
import TerserPlugin from "terser-webpack-plugin";
import { __dirname, importWithTypeJson } from "../test/esm-helpers.mjs";
const libraryPackageJson = await importWithTypeJson(import.meta, "../package.json");
const nodeModulePrefixRe = /^node:/u;
// eslint-disable-next-line jsdoc/require-jsdoc
function config(options) {
const { entry, filename, mode, optimization, packageJson } = options;
const { name, version, homepage, license } = packageJson;
@ -13,8 +16,7 @@ function config(options) {
"devtool": false,
"entry": entry,
"externals": {
"markdown-it": "markdownit",
"markdownlint-micromark": "micromarkBrowser"
"markdown-it": "markdownit"
},
"mode": mode,
"module": {
@ -33,7 +35,7 @@ function config(options) {
"name": name.replace(/(-\w)/g, (m) => m.slice(1).toUpperCase()),
"type": "var"
},
"path": __dirname
"path": __dirname(import.meta)
},
"plugins": [
new webpack.NormalModuleReplacementPlugin(
@ -52,7 +54,8 @@ function config(options) {
"fs": false,
"os": false,
"path": false,
"util": false
"util": false,
"module": require.resolve("./module-stub.cjs")
}
}
};
@ -77,14 +80,10 @@ const modeProduction = {
}
};
const entryLibrary = {
"entry": "./markdownlint-exports.js",
"packageJson": require("../package.json")
"entry": "./browser-exports.mjs",
"packageJson": libraryPackageJson
};
// const entryHelpers = {
// "entry": "../helpers/helpers.js",
// "packageJson": require("../helpers/package.json")
// };
module.exports = [
export default [
config({
...entryLibrary,
...modeDevelopment,
@ -95,14 +94,4 @@ module.exports = [
...modeProduction,
"filename": "markdownlint-browser.min.js"
})
// config({
// ...entryHelpers,
// ...modeDevelopment,
// "filename": "markdownlint-rule-helpers-browser.js"
// }),
// config({
// ...entryHelpers,
// ...modeProduction,
// "filename": "markdownlint-rule-helpers-browser.min.js"
// })
];