diff --git a/.gitignore b/.gitignore index 7fbbcd55d..8864f8826 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,6 @@ coverage demo/markdown-it.min.js -demo/markdownlint-browser.min.js -demo/micromark-browser.js -demo/micromark-html-browser.js -micromark/micromark.cjs -micromark/micromark.dev.cjs -micromark/micromark-browser.js -micromark/micromark-browser.dev.js -micromark/micromark-html-browser.js -micromark/micromark-html-browser.dev.js +demo/markdownlint-browser.min.cjs node_modules !test/node_modules npm-debug.log diff --git a/.npmignore b/.npmignore index 0b1a6d4f0..fbb17e0d8 100644 --- a/.npmignore +++ b/.npmignore @@ -5,13 +5,13 @@ .vscode coverage demo/* -!demo/markdownlint-browser.js +!demo/markdownlint-browser.cjs doc-build eslint.config.mjs example micromark npm-debug.log -schema/*.js +schema/*.mjs scripts test test-repos diff --git a/demo/default.js b/demo/default.cjs similarity index 100% rename from demo/default.js rename to demo/default.cjs diff --git a/demo/default.htm b/demo/default.htm index 32a8f2045..26739a109 100644 --- a/demo/default.htm +++ b/demo/default.htm @@ -36,7 +36,7 @@ - - + + diff --git a/demo/webpack.config.js b/demo/webpack.config.mjs similarity index 94% rename from demo/webpack.config.js rename to demo/webpack.config.mjs index 274b14037..7a52fec12 100644 --- a/demo/webpack.config.js +++ b/demo/webpack.config.mjs @@ -1,9 +1,7 @@ // @ts-check -"use strict"; - -const webpack = require("webpack"); -const TerserPlugin = require("terser-webpack-plugin"); +import webpack from "webpack"; +import TerserPlugin from "terser-webpack-plugin"; const nodeModulePrefixRe = /^node:/u; function config(options) { @@ -84,7 +82,7 @@ const entryLibrary = { // "entry": "../helpers/helpers.js", // "packageJson": require("../helpers/package.json") // }; -module.exports = [ +export default [ config({ ...entryLibrary, ...modeDevelopment, diff --git a/helpers/.npmignore b/helpers/.npmignore index daa602947..73c5a2779 100644 --- a/helpers/.npmignore +++ b/helpers/.npmignore @@ -1 +1 @@ -test.js +test.cjs diff --git a/helpers/helpers.js b/helpers/helpers.cjs similarity index 100% rename from helpers/helpers.js rename to helpers/helpers.cjs diff --git a/helpers/package.json b/helpers/package.json index 4790473f4..be5708fb8 100644 --- a/helpers/package.json +++ b/helpers/package.json @@ -2,9 +2,9 @@ "name": "markdownlint-rule-helpers", "version": "0.27.0", "description": "A collection of markdownlint helper functions for custom rules", - "main": "./helpers.js", + "main": "./helpers.cjs", "exports": { - ".": "./helpers.js", + ".": "./helpers.cjs", "./micromark": "./micromark-helpers.cjs" }, "author": "David Anson (https://dlaa.me/)", diff --git a/helpers/shared.js b/helpers/shared.cjs similarity index 100% rename from helpers/shared.js rename to helpers/shared.cjs diff --git a/lib/cache.js b/lib/cache.mjs similarity index 80% rename from lib/cache.js rename to lib/cache.mjs index 8d53f33f2..207efa441 100644 --- a/lib/cache.js +++ b/lib/cache.mjs @@ -1,9 +1,7 @@ // @ts-check -"use strict"; - -const helpers = require("../helpers"); -const { filterByTypes } = require("../helpers/micromark-helpers.cjs"); +import helpers from "../helpers/helpers.cjs"; +import { filterByTypes } from "../helpers/micromark-helpers.cjs"; /** @type {Map} */ const map = new Map(); @@ -15,7 +13,7 @@ let params = undefined; * @param {import("./markdownlint").RuleParams} [p] Rule parameters object. * @returns {void} */ -function initialize(p) { +export function initialize(p) { map.clear(); params = p; } @@ -43,7 +41,7 @@ function getCached(name, getValue) { * @param {boolean} [htmlFlow] Whether to include htmlFlow content. * @returns {import("./markdownlint").MicromarkToken[]} Filtered tokens. */ -function filterByTypesCached(types, htmlFlow) { +export function filterByTypesCached(types, htmlFlow) { return getCached( // eslint-disable-next-line prefer-rest-params JSON.stringify(arguments), @@ -56,15 +54,9 @@ function filterByTypesCached(types, htmlFlow) { * * @returns {Object} Reference link and image data object. */ -function getReferenceLinkImageData() { +export function getReferenceLinkImageData() { return getCached( getReferenceLinkImageData.name, () => helpers.getReferenceLinkImageData(params.parsers.micromark.tokens) ); } - -module.exports = { - initialize, - filterByTypesCached, - getReferenceLinkImageData -}; diff --git a/lib/constants.js b/lib/constants.mjs similarity index 60% rename from lib/constants.js rename to lib/constants.mjs index cdfbfae47..b83a7d9b5 100644 --- a/lib/constants.js +++ b/lib/constants.mjs @@ -1,9 +1,7 @@ // @ts-check -"use strict"; - -module.exports.deprecatedRuleNames = []; -module.exports.fixableRuleNames = [ +export const deprecatedRuleNames = []; +export const fixableRuleNames = [ "MD004", "MD005", "MD007", "MD009", "MD010", "MD011", "MD012", "MD014", "MD018", "MD019", "MD020", "MD021", "MD022", "MD023", "MD026", "MD027", "MD030", "MD031", @@ -11,5 +9,5 @@ module.exports.fixableRuleNames = [ "MD047", "MD049", "MD050", "MD051", "MD053", "MD054", "MD058" ]; -module.exports.homepage = "https://github.com/DavidAnson/markdownlint"; -module.exports.version = "0.36.1"; +export const homepage = "https://github.com/DavidAnson/markdownlint"; +export const version = "0.36.1"; diff --git a/lib/markdownlint.js b/lib/markdownlint.mjs similarity index 98% rename from lib/markdownlint.js rename to lib/markdownlint.mjs index 685f0911b..a020958db 100644 --- a/lib/markdownlint.js +++ b/lib/markdownlint.mjs @@ -1,19 +1,14 @@ // @ts-check -"use strict"; - -const path = require("node:path"); -const { promisify } = require("node:util"); -const micromark = require("../helpers/micromark-parse.cjs"); -const { version } = require("./constants"); -const rules = require("./rules"); -const helpers = require("../helpers"); -const cache = require("./cache"); - -// @ts-ignore -// eslint-disable-next-line camelcase, no-inline-comments, no-undef -const dynamicRequire = (typeof __non_webpack_require__ === "undefined") ? require : /* c8 ignore next */ __non_webpack_require__; -// Capture native require implementation for dynamic loading of modules +import { createRequire } from "node:module"; +const dynamicRequire = createRequire(import.meta.url); +import path from "node:path"; +import { promisify } from "node:util"; +import micromark from "../helpers/micromark-parse.cjs"; +import { version } from "./constants.mjs"; +import rules from "./rules.mjs"; +import helpers from "../helpers/helpers.cjs"; +import { initialize as cacheInitialize } from "./cache.mjs"; /** * Validate the list of rules for structure and reuse. @@ -533,7 +528,7 @@ function lintContent( "lines": Object.freeze(lines), "frontMatterLines": Object.freeze(frontMatterLines) }; - cache.initialize({ + cacheInitialize({ ...paramsBase, "parsers": parsersMicromark, "config": null @@ -751,7 +746,7 @@ function lintContent( } catch (error) { callbackError(error); } finally { - cache.initialize(); + cacheInitialize(); } } @@ -1342,7 +1337,7 @@ markdownlint.promises = { }; markdownlint.applyFix = applyFix; markdownlint.applyFixes = applyFixes; -module.exports = markdownlint; +export default markdownlint; // Type declarations diff --git a/lib/md001.js b/lib/md001.mjs similarity index 77% rename from lib/md001.js rename to lib/md001.mjs index 1befb179c..1a9bac40e 100644 --- a/lib/md001.js +++ b/lib/md001.mjs @@ -1,14 +1,12 @@ // @ts-check -"use strict"; - -const { addErrorDetailIf } = require("../helpers"); -const { getHeadingLevel } = require("../helpers/micromark-helpers.cjs"); -const { filterByTypesCached } = require("./cache"); +import { addErrorDetailIf } from "../helpers/helpers.cjs"; +import { getHeadingLevel } from "../helpers/micromark-helpers.cjs"; +import { filterByTypesCached } from "./cache.mjs"; // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ -module.exports = { +export default { "names": [ "MD001", "heading-increment" ], "description": "Heading levels should only increment by one level at a time", "tags": [ "headings" ], diff --git a/lib/md003.js b/lib/md003.mjs similarity index 86% rename from lib/md003.js rename to lib/md003.mjs index a4c21f6bb..51cee54e6 100644 --- a/lib/md003.js +++ b/lib/md003.mjs @@ -1,14 +1,12 @@ // @ts-check -"use strict"; - -const { addErrorDetailIf } = require("../helpers"); -const { getHeadingLevel, getHeadingStyle } = require("../helpers/micromark-helpers.cjs"); -const { filterByTypesCached } = require("./cache"); +import { addErrorDetailIf } from "../helpers/helpers.cjs"; +import { getHeadingLevel, getHeadingStyle } from "../helpers/micromark-helpers.cjs"; +import { filterByTypesCached } from "./cache.mjs"; // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ -module.exports = { +export default { "names": [ "MD003", "heading-style" ], "description": "Heading style", "tags": [ "headings" ], diff --git a/lib/md004.js b/lib/md004.mjs similarity index 90% rename from lib/md004.js rename to lib/md004.mjs index 79e06eb7d..ea31b2f74 100644 --- a/lib/md004.js +++ b/lib/md004.mjs @@ -1,10 +1,8 @@ // @ts-check -"use strict"; - -const { addErrorDetailIf } = require("../helpers"); -const { getDescendantsByType, getParentOfType } = require("../helpers/micromark-helpers.cjs"); -const { filterByTypesCached } = require("./cache"); +import { addErrorDetailIf } from "../helpers"; +import { getDescendantsByType, getParentOfType } from "../helpers/micromark-helpers.cjs"; +import { filterByTypesCached } from "./cache.mjs"; const markerToStyle = { "-": "dash", @@ -31,7 +29,7 @@ const validStyles = new Set([ // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ -module.exports = { +export default { "names": [ "MD004", "ul-style" ], "description": "Unordered list style", "tags": [ "bullet", "ul" ], diff --git a/lib/md005.js b/lib/md005.mjs similarity index 94% rename from lib/md005.js rename to lib/md005.mjs index e439ba3aa..5d8752eb3 100644 --- a/lib/md005.js +++ b/lib/md005.mjs @@ -1,13 +1,11 @@ // @ts-check -"use strict"; - -const { addError, addErrorDetailIf } = require("../helpers"); -const { filterByTypesCached } = require("./cache"); +import { addError, addErrorDetailIf } from "../helpers/helpers.cjs"; +import { filterByTypesCached } from "./cache.mjs"; // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule */ -module.exports = { +export default { "names": [ "MD005", "list-indent" ], "description": "Inconsistent indentation for list items at the same level", "tags": [ "bullet", "ul", "indentation" ], diff --git a/lib/md019-md021.js b/lib/md019-md021.mjs similarity index 91% rename from lib/md019-md021.js rename to lib/md019-md021.mjs index 4811936f4..dea991380 100644 --- a/lib/md019-md021.js +++ b/lib/md019-md021.mjs @@ -1,10 +1,8 @@ // @ts-check -"use strict"; - -const { addErrorContext } = require("../helpers/helpers"); -const { getHeadingStyle } = require("../helpers/micromark-helpers.cjs"); -const { filterByTypesCached } = require("./cache"); +import { addErrorContext } from "../helpers/helpers.cjs"; +import { getHeadingStyle } from "../helpers/micromark-helpers.cjs"; +import { filterByTypesCached } from "./cache.mjs"; /** * Validate heading sequence and whitespace length at start or end. @@ -49,7 +47,7 @@ function validateHeadingSpaces(onError, heading, delta) { // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule[] */ -module.exports = [ +export default [ { "names": [ "MD019", "no-multiple-space-atx" ], "description": "Multiple spaces after hash on atx style heading", diff --git a/lib/md049-md050.js b/lib/md049-md050.mjs similarity index 95% rename from lib/md049-md050.js rename to lib/md049-md050.mjs index a117b077c..96a2e4ef7 100644 --- a/lib/md049-md050.js +++ b/lib/md049-md050.mjs @@ -1,9 +1,7 @@ // @ts-check -"use strict"; - -const { addError } = require("../helpers"); -const { filterByPredicate, getDescendantsByType } = require("../helpers/micromark-helpers.cjs"); +import { addError } from "../helpers/helpers.cjs"; +import { filterByPredicate, getDescendantsByType } from "../helpers/micromark-helpers.cjs"; const intrawordRe = /^\w$/; @@ -80,7 +78,7 @@ const impl = // eslint-disable-next-line jsdoc/valid-types /** @type import("./markdownlint").Rule[] */ -module.exports = [ +export default [ { "names": [ "MD049", "emphasis-style" ], "description": "Emphasis style", diff --git a/lib/rules.js b/lib/rules.mjs similarity index 76% rename from lib/rules.js rename to lib/rules.mjs index cbdbd9fbb..7d03b3ea8 100644 --- a/lib/rules.js +++ b/lib/rules.mjs @@ -1,20 +1,20 @@ // @ts-check -"use strict"; +import { homepage, version } from "./constants.mjs"; -const { homepage, version } = require("./constants"); - -// @ts-ignore -const [ md019, md021 ] = require("./md019-md021"); -// @ts-ignore -const [ md049, md050 ] = require("./md049-md050"); +import md001 from "./md001.mjs"; +import md003 from "./md003.mjs"; +import md004 from "./md004.mjs"; +import md005 from "./md005.mjs"; +import md019md021 from "./md019-md021.mjs"; +import md049md050 from "./md049-md050.mjs"; const rules = [ - require("./md001"), + md001, // md002: Deprecated and removed - require("./md003"), - require("./md004"), - require("./md005"), + md003, + md004, + md005, // md006: Deprecated and removed require("./md007"), require("./md009"), @@ -24,9 +24,9 @@ const rules = [ require("./md013"), require("./md014"), require("./md018"), - md019, + md019md021[0], require("./md020"), - md021, + md019md021[1], require("./md022"), require("./md023"), require("./md024"), @@ -54,8 +54,8 @@ const rules = [ require("./md046"), require("./md047"), require("./md048"), - md049, - md050, + md049md050[0], + md049md050[1], require("./md051"), require("./md052"), require("./md053"), @@ -71,4 +71,4 @@ for (const rule of rules) { rule["information"] = new URL(`${homepage}/blob/v${version}/doc/${name}.md`); } -module.exports = rules; +export default rules; diff --git a/micromark/.npmignore b/micromark/.npmignore deleted file mode 100644 index 4947c297c..000000000 --- a/micromark/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -exports.mjs -exports-html.mjs -micromark.dev.cjs -micromark-browser.dev.js -micromark-html-browser.dev.js -webpack.config.js diff --git a/micromark/.npmrc b/micromark/.npmrc deleted file mode 100644 index 3757b3046..000000000 --- a/micromark/.npmrc +++ /dev/null @@ -1,2 +0,0 @@ -ignore-scripts=true -package-lock=false diff --git a/micromark/LICENSE b/micromark/LICENSE deleted file mode 100644 index 71ff07a3e..000000000 --- a/micromark/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) David Anson - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/micromark/README.md b/micromark/README.md deleted file mode 100644 index a9834c41c..000000000 --- a/micromark/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# markdownlint-micromark - -> A trivial package that re-exports some [`micromark`][micromark] functionality -> as a CommonJS module - -This package is unlikely to be of any use beyond a specific scenario used by -[`markdownlint`][markdownlint]. - -[markdownlint]: https://github.com/DavidAnson/markdownlint -[micromark]: https://github.com/micromark/micromark diff --git a/micromark/api-extractor.json b/micromark/api-extractor.json deleted file mode 100644 index 105981e25..000000000 --- a/micromark/api-extractor.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", - "projectFolder": ".", - "mainEntryPointFilePath": "/types.d.ts", - "bundledPackages": [ "*" ], - "newlineKind": "os", - "compiler": { - "overrideTsconfig": {} - }, - "apiReport": { - "enabled": false - }, - "docModel": { - "enabled": false - }, - "dtsRollup": { - "enabled": true, - "untrimmedFilePath": "/micromark.d.cts" - }, - "tsdocMetadata": { - "enabled": false - }, - "messages": { - "compilerMessageReporting": { - "default": { - "logLevel": "warning" - } - }, - "extractorMessageReporting": { - "default": { - "logLevel": "warning" - } - }, - "tsdocMessageReporting": { - "default": { - "logLevel": "warning" - } - } - } -} diff --git a/micromark/exports-html.mjs b/micromark/exports-html.mjs deleted file mode 100644 index 88d29bf7d..000000000 --- a/micromark/exports-html.mjs +++ /dev/null @@ -1,10 +0,0 @@ -// @ts-check - -/* eslint-disable n/no-missing-import */ - -export { compile } from "micromark"; -export { directiveHtml } from "micromark-extension-directive"; -export { gfmAutolinkLiteralHtml } from "micromark-extension-gfm-autolink-literal"; -export { gfmFootnoteHtml } from "micromark-extension-gfm-footnote"; -export { gfmTableHtml } from "micromark-extension-gfm-table"; -export { mathHtml } from "micromark-extension-math"; diff --git a/micromark/exports.mjs b/micromark/exports.mjs deleted file mode 100644 index fcf10df53..000000000 --- a/micromark/exports.mjs +++ /dev/null @@ -1,14 +0,0 @@ -// @ts-check - -/* eslint-disable n/no-missing-import */ - -export { directive } from "micromark-extension-directive"; -export { gfmAutolinkLiteral } from "micromark-extension-gfm-autolink-literal"; -export { gfmFootnote } from "micromark-extension-gfm-footnote"; -export { gfmTable } from "micromark-extension-gfm-table"; -export { math } from "micromark-extension-math"; -export { parse } from "micromark"; -export { postprocess } from "micromark"; -export { preprocess } from "micromark"; -// micromark-core-commonmark is not a dev/dependency because this instance must match what's used by micromark -export { labelEnd } from "micromark-core-commonmark"; diff --git a/micromark/micromark.d.cts b/micromark/micromark.d.cts deleted file mode 100644 index 276805703..000000000 --- a/micromark/micromark.d.cts +++ /dev/null @@ -1,1758 +0,0 @@ -/** - * Attempt deals with several values, and tries to parse according to those - * values. - * - * If a value resulted in `ok`, it worked, the tokens that were made are used, - * and `ok` is switched to. - * If the result is `nok`, the attempt failed, so we revert to the original - * state, and `nok` is used. - * - * @param construct - * Construct(s) to try. - * @param ok - * State to move to when successful. - * @param nok - * State to move to when unsuccessful. - * @returns - * Next state. - */ -declare type Attempt = ( -construct: Array | Construct | ConstructRecord, -ok: State, -nok?: State | undefined -) => State - -/** - * Directive attribute. - */ -declare interface Attributes { - /** - * Key to value. - */ - [key: string]: string -} - -/** - * Generate a back label dynamically. - * - * For the following markdown: - * - * ```markdown - * Alpha[^micromark], bravo[^micromark], and charlie[^remark]. - * - * [^remark]: things about remark - * [^micromark]: things about micromark - * ``` - * - * This function will be called with: - * - * * `0` and `0` for the backreference from `things about micromark` to - * `alpha`, as it is the first used definition, and the first call to it - * * `0` and `1` for the backreference from `things about micromark` to - * `bravo`, as it is the first used definition, and the second call to it - * * `1` and `0` for the backreference from `things about remark` to - * `charlie`, as it is the second used definition - * - * @param referenceIndex - * Index of the definition in the order that they are first referenced, - * 0-indexed. - * @param rereferenceIndex - * Index of calls to the same definition, 0-indexed. - * @returns - * Back label to use when linking back from definitions to their reference. - */ -declare type BackLabelTemplate = ( -referenceIndex: number, -rereferenceIndex: number -) => string - -/** - * A chunk is either a character code or a slice of a buffer in the form of a - * string. - * - * Chunks are used because strings are more efficient storage that character - * codes, but limited in what they can represent. - */ -declare type Chunk = Code | string - -declare type Chunk_2 = Chunk - -/** - * A character code. - * - * This is often the same as what `String#charCodeAt()` yields but micromark - * adds meaning to certain other values. - * - * `null` represents the end of the input stream (called eof). - * Negative integers are used instead of certain sequences of characters (such - * as line endings and tabs). - */ -declare type Code = number | null - -declare type Compile = Compile_2 - -/** - * @param {CompileOptions | null | undefined} [options] - * @returns {Compile} - */ -export declare function compile(options?: CompileOptions_2 | null | undefined): Compile - -/** - * Serialize micromark events as HTML. - */ -declare type Compile_2 = (events: Array) => string - -/** - * HTML compiler context. - */ -declare type CompileContext = { - /** - * Configuration passed by the user. - */ - options: CompileOptions - - /** - * Set data into the key-value store. - * - * @param key - * Key. - * @param value - * Value. - * @returns - * Nothing. - */ - setData: ( - key: Key, - value?: CompileData[Key] - ) => undefined - - /** - * Get data from the key-value store. - * - * @param key - * Key. - * @returns - * Value at `key` in compile data. - */ - getData: (key: Key) => CompileData[Key] - - /** - * Output an extra line ending if the previous value wasn’t EOF/EOL. - * - * @returns - * Nothing. - */ - lineEndingIfNeeded: () => undefined - - /** - * Make a value safe for injection in HTML (except w/ `ignoreEncode`). - * - * @param value - * Raw value. - * @returns - * Safe value. - */ - encode: (value: string) => string - - /** - * Capture some of the output data. - * - * @returns - * Nothing. - */ - buffer: () => undefined - - /** - * Stop capturing and access the output data. - * - * @returns - * Captured data. - */ - resume: () => string - - /** - * Output raw data. - * - * @param value - * Raw value. - * @returns - * Nothing. - */ - raw: (value: string) => undefined - - /** - * Output (parts of) HTML tags. - * - * @param value - * Raw value. - * @returns - * Nothing. - */ - tag: (value: string) => undefined - - /** - * Get the string value of a token. - * - * @param token - * Start/end in stream. - * @param expandTabs - * Whether to expand tabs. - * @returns - * Serialized chunks. - */ - sliceSerialize: TokenizeContext['sliceSerialize'] -} - -/** - * State tracked to compile events as HTML. - */ -export declare interface CompileData { - /** - * Whether the last emitted value was a tag. - */ - lastWasTag?: boolean | undefined - - /** - * Whether the first list item is expected, used by lists. - */ - expectFirstItem?: boolean | undefined - - /** - * Whether to slurp the next line ending (resets itself on the next line - * ending). - */ - slurpOneLineEnding?: boolean | undefined - - /** - * Whether to slurp all future line endings (has to be unset manually). - */ - slurpAllLineEndings?: boolean | undefined - - /** - * Whether we’re in fenced code, used by code (fenced). - */ - fencedCodeInside?: boolean | undefined - - /** - * Number of fences that were seen, used by code (fenced). - */ - fencesCount?: number | undefined - - /** - * Whether we’ve seen code data, used by code (fenced, indented). - */ - flowCodeSeenData?: boolean | undefined - - /** - * Ignore encoding unsafe characters, used for example for URLs which are - * first percent encoded, or by HTML when supporting it. - */ - ignoreEncode?: boolean | undefined - - /** - * Current heading rank, used by heading (atx, setext). - */ - headingRank?: number | undefined - - /** - * Whether we’re in code data, used by code (text). - */ - inCodeText?: boolean | undefined - - /** - * Current character reference kind. - */ - characterReferenceType?: string | undefined - - /** - * Stack of containers, whether they’re tight or not. - */ - tightStack: Array - - /** - * Collected definitions. - */ - definitions: Record -} - -/** - * Compile options. - */ -declare interface CompileOptions { - /** - * Whether to allow (dangerous) HTML (`boolean`, default: `false`). - * - * The default is `false`, which still parses the HTML according to - * `CommonMark` but shows the HTML as text instead of as elements. - * - * Pass `true` for trusted content to get actual HTML elements. - */ - allowDangerousHtml?: boolean | null | undefined - - /** - * Whether to allow dangerous protocols in links and images (`boolean`, - * default: `false`). - * - * The default is `false`, which drops URLs in links and images that use - * dangerous protocols. - * - * Pass `true` for trusted content to support all protocols. - * - * URLs that have no protocol (which means it’s relative to the current page, - * such as `./some/page.html`) and URLs that have a safe protocol (for - * images: `http`, `https`; for links: `http`, `https`, `irc`, `ircs`, - * `mailto`, `xmpp`), are safe. - * All other URLs are dangerous and dropped. - */ - allowDangerousProtocol?: boolean | null | undefined - - /** - * Default line ending to use when compiling to HTML, for line endings not in - * `value`. - * - * Generally, `micromark` copies line endings (`\r`, `\n`, `\r\n`) in the - * markdown document over to the compiled HTML. - * In some cases, such as `> a`, CommonMark requires that extra line endings - * are added: `
\n

a

\n
`. - * - * To create that line ending, the document is checked for the first line - * ending that is used. - * If there is no line ending, `defaultLineEnding` is used. - * If that isn’t configured, `\n` is used. - */ - defaultLineEnding?: LineEnding | null | undefined - - /** - * Array of HTML extensions (default: `[]`). - */ - htmlExtensions?: Array | null | undefined -} - -declare type CompileOptions_2 = CompileOptions - -/** - * An object describing how to parse a markdown construct. - */ -export declare type Construct = { - /** - * Set up a state machine to handle character codes streaming in. - */ - tokenize: Tokenizer - - /** - * Guard whether the previous character can come before the construct. - */ - previous?: Previous | undefined - - /** - * For containers, a continuation construct. - */ - continuation?: Construct | undefined - - /** - * For containers, a final hook. - */ - exit?: Exiter | undefined - - /** - * Name of the construct, used to toggle constructs off. - * - * Named constructs must not be `partial`. - */ - name?: string | undefined - - /** - * Whether this construct represents a partial construct. - * - * Partial constructs must not have a `name`. - */ - partial?: boolean | undefined - - /** - * Resolve the events parsed by `tokenize`. - * - * For example, if we’re currently parsing a link title and this construct - * parses character references, then `resolve` is called with the events - * ranging from the start to the end of a character reference each time one is - * found. - */ - resolve?: Resolver | undefined - - /** - * Resolve the events from the start of the content (which includes other - * constructs) to the last one parsed by `tokenize`. - * - * For example, if we’re currently parsing a link title and this construct - * parses character references, then `resolveTo` is called with the events - * ranging from the start of the link title to the end of a character - * reference each time one is found. - */ - resolveTo?: Resolver | undefined - - /** - * Resolve all events when the content is complete, from the start to the end. - * Only used if `tokenize` is successful once in the content. - * - * For example, if we’re currently parsing a link title and this construct - * parses character references, then `resolveAll` is called *if* at least one - * character reference is found, ranging from the start to the end of the link - * title to the end. - */ - resolveAll?: Resolver | undefined - - /** - * Concrete constructs cannot be interrupted by more containers. - * - * For example, when parsing the document (containers, such as block quotes - * and lists) and this construct is parsing fenced code: - * - * ````markdown - * > ```js - * > - list? - * ```` - * - * …then `- list?` cannot form if this fenced code construct is concrete. - * - * An example of a construct that is not concrete is a GFM table: - * - * ````markdown - * | a | - * | - | - * > | b | - * ```` - * - * …`b` is not part of the table. - */ - concrete?: boolean | undefined - - /** - * Whether the construct, when in a `ConstructRecord`, precedes over existing - * constructs for the same character code when merged. - * - * The default is that new constructs precede over existing ones. - */ - add?: 'after' | 'before' | undefined -} - -/** - * Several constructs, mapped from their initial codes. - */ -declare type ConstructRecord = Record< -string, -Array | Construct | undefined -> - -/** - * Deal with the character and move to the next. - * - * @param code - * Current code. - */ -declare type Consume = (code: Code) => undefined - -/** - * State shared between container calls. - */ -declare interface ContainerState { - /** - * Special field to close the current flow (or containers). - */ - _closeFlow?: boolean | undefined - - /** - * Used by block quotes. - */ - open?: boolean | undefined - - /** - * Current marker, used by lists. - */ - marker?: Code | undefined - - /** - * Current token type, used by lists. - */ - type?: TokenType | undefined - - /** - * Current size, used by lists. - */ - size?: number | undefined - - /** - * Whether there first line is blank, used by lists. - */ - initialBlankLine?: boolean | undefined - - /** - * Whether there are further blank lines, used by lists. - */ - furtherBlankLines?: boolean | undefined -} - -/** - * Enumeration of the content types. - * - * Technically `document` is also a content type, which includes containers - * (lists, block quotes) and flow. - * As `ContentType` is used on tokens to define the type of subcontent but - * `document` is the highest level of content, so it’s not listed here. - * - * Containers in markdown come from the margin and include more constructs - * on the lines that define them. - * Take for example a block quote with a paragraph inside it (such as - * `> asd`). - * - * `flow` represents the sections, such as headings, code, and content, which - * is also parsed per line - * An example is HTML, which has a certain starting condition (such as - * ` - * ``` - * - * The above example shows that elements are made available by browsers, by - * their ID, on the `window` object. - * This is a security risk because you might be expecting some other variable - * at that place. - * It can also break polyfills. - * Using a prefix solves these problems. - */ - clobberPrefix?: string | null | undefined - /** - * Textual label to use for the footnotes section (default: `'Footnotes'`). - * - * Change it when the markdown is not in English. - * - * This label is typically hidden visually (assuming a `sr-only` CSS class - * is defined that does that) and so affects screen readers only. - * If you do have such a class, but want to show this section to everyone, - * pass different attributes with the `labelAttributes` option. - */ - label?: string | null | undefined - /** - * Attributes to use on the footnote label (default: `'class="sr-only"'`). - * - * Change it to show the label and add other attributes. - * - * This label is typically hidden visually (assuming an `sr-only` CSS class - * is defined that does that) and so affects screen readers only. - * If you do have such a class, but want to show this section to everyone, - * pass an empty string. - * You can also add different attributes. - * - * > 👉 **Note**: `id="footnote-label"` is always added, because footnote - * > calls use it with `aria-describedby` to provide an accessible label. - */ - labelAttributes?: string | null | undefined - /** - * HTML tag name to use for the footnote label element (default: `'h2'`). - * - * Change it to match your document structure. - * - * This label is typically hidden visually (assuming a `sr-only` CSS class - * is defined that does that) and so affects screen readers only. - * If you do have such a class, but want to show this section to everyone, - * pass different attributes with the `labelAttributes` option. - */ - labelTagName?: string | null | undefined - /** - * Textual label to describe the backreference back to references (default: - * `defaultBackLabel`). - * - * The default value is: - * - * ```js - * function defaultBackLabel(referenceIndex, rereferenceIndex) { - * return ( - * 'Back to reference ' + - * (referenceIndex + 1) + - * (rereferenceIndex > 1 ? '-' + rereferenceIndex : '') - * ) - * } - * ``` - * - * Change it when the markdown is not in English. - * - * This label is used in the `aria-label` attribute on each backreference - * (the `↩` links). - * It affects users of assistive technology. - */ - backLabel?: BackLabelTemplate | string | null | undefined -} - -/** - * Configuration for HTML output. - * - * > 👉 **Note**: passed to `katex.renderToString`. - * > `displayMode` is overwritten by this plugin, to `false` for math in - * > text (inline), and `true` for math in flow (block). - */ -declare interface HtmlOptions_3 extends Object { - /** - * The field `displayMode` cannot be passed to `micromark-extension-math`. - * It is overwritten by it, - * to `false` for math in text (inline) and `true` for math in flow (block). - */ - displayMode?: never -} - -/** - * Type of line ending in markdown. - */ -declare type LineEnding = '\r' | '\n' | '\r\n' - -/** - * Create an extension for `micromark` to enable math syntax. - * - * @param {Options | null | undefined} [options={}] - * Configuration (default: `{}`). - * @returns {Extension} - * Extension for `micromark` that can be passed in `extensions`, to - * enable math syntax. - */ -export declare function math(options?: Options | null | undefined): Extension; - -/** - * Create an extension for `micromark` to support math when serializing to - * HTML. - * - * > 👉 **Note**: this uses KaTeX to render math. - * - * @param {Options | null | undefined} [options={}] - * Configuration (default: `{}`). - * @returns {HtmlExtension} - * Extension for `micromark` that can be passed in `htmlExtensions`, to - * support math when serializing to HTML. - */ -export declare function mathHtml(options?: HtmlOptions_3 | null | undefined): HtmlExtension; - -/** - * Configuration. - */ -declare interface Options { - /** - * Whether to support math (text) with a single dollar (default: `true`). - * - * Single dollars work in Pandoc and many other places, but often interfere - * with “normal” dollars in text. - * If you turn this off, you can use two or more dollars for text math. - */ - singleDollarTextMath?: boolean | null | undefined -} - -/** - * @param {ParseOptions | null | undefined} [options] - * @returns {ParseContext} - */ -export declare function parse(options?: ParseOptions_2 | null | undefined): ParseContext_2 - -/** - * A context object that helps w/ parsing markdown. - */ -declare interface ParseContext { - /** - * All constructs. - */ - constructs: FullNormalizedExtension - - /** - * Create a content tokenizer. - */ - content: Create - - /** - * Create a document tokenizer. - */ - document: Create - - /** - * Create a flow tokenizer. - */ - flow: Create - - /** - * Create a string tokenizer. - */ - string: Create - - /** - * Create a text tokenizer. - */ - text: Create - - /** - * List of defined identifiers. - */ - defined: Array - - /** - * Map of line numbers to whether they are lazy (as opposed to the line before - * them). - * Take for example: - * - * ```markdown - * > a - * b - * ``` - * - * L1 here is not lazy, L2 is. - */ - lazy: Record -} - -declare type ParseContext_2 = ParseContext - -/** - * Config defining how to parse. - */ -export declare interface ParseOptions { - /** - * Array of syntax extensions (default: `[]`). - */ - extensions?: Array | null | undefined -} - -declare type ParseOptions_2 = ParseOptions - -/** - * A location in the document (`line`/`column`/`offset`) and chunk (`_index`, - * `_bufferIndex`). - * - * `_bufferIndex` is `-1` when `_index` points to a code chunk and it’s a - * non-negative integer when pointing to a string chunk. - * - * The interface for the location in the document comes from unist `Point`: - * - */ -declare type Point = { - /** - * Position in a string chunk (or `-1` when pointing to a numeric chunk). - */ - _bufferIndex: number - - /** - * Position in a list of chunks. - */ - _index: number - - /** - * 1-indexed column number. - */ - column: number - - /** - * 1-indexed line number. - */ - line: number - - /** - * 0-indexed position in the document. - */ - offset: number -} - -/** - * @param {Array} events - * @returns {Array} - */ -export declare function postprocess( -events: Array -): Array - -/** - * @returns {Preprocessor} - */ -export declare function preprocess(): Preprocessor - -declare type Preprocessor = ( -value: Value, -encoding?: Encoding | null | undefined, -end?: boolean | null | undefined -) => Array - -/** - * Guard whether `code` can come before the construct. - * - * In certain cases a construct can hook into many potential start characters. - * Instead of setting up an attempt to parse that construct for most - * characters, this is a speedy way to reduce that. - * - * @param this - * Tokenize context. - * @param code - * Previous code. - * @returns - * Whether `code` is allowed before. - */ -declare type Previous = (this: TokenizeContext, code: Code) => boolean - -/** - * A resolver handles and cleans events coming from `tokenize`. - * - * @param events - * List of events. - * @param context - * Tokenize context. - * @returns - * The given, modified, events. - */ -declare type Resolver = ( -events: Array, -context: TokenizeContext -) => Array - -/** - * The main unit in the state machine: a function that gets a character code - * and has certain effects. - * - * A state function should return another function: the next - * state-as-a-function to go to. - * - * But there is one case where they return `undefined`: for the eof character - * code (at the end of a value). - * The reason being: well, there isn’t any state that makes sense, so - * `undefined` works well. - * Practically that has also helped: if for some reason it was a mistake, then - * an exception is throw because there is no next function, meaning it - * surfaces early. - * - * @param code - * Current code. - * @returns - * Next state. - */ -export declare type State = (code: Code) => State | undefined - -/** - * A token: a span of chunks. - * - * Tokens are what the core of micromark produces: the built in HTML compiler - * or other tools can turn them into different things. - * - * Tokens are essentially names attached to a slice of chunks, such as - * `lineEndingBlank` for certain line endings, or `codeFenced` for a whole - * fenced code. - * - * Sometimes, more info is attached to tokens, such as `_open` and `_close` - * by `attention` (strong, emphasis) to signal whether the sequence can open - * or close an attention run. - * - * Linked tokens are used because outer constructs are parsed first. - * Take for example: - * - * ```markdown - * > *a - * b*. - * ``` - * - * 1. The block quote marker and the space after it is parsed first - * 2. The rest of the line is a `chunkFlow` token - * 3. The two spaces on the second line are a `linePrefix` - * 4. The rest of the line is another `chunkFlow` token - * - * The two `chunkFlow` tokens are linked together. - * The chunks they span are then passed through the flow tokenizer. - */ -export declare interface Token { - /** - * Token type. - */ - type: TokenType - - /** - * Point where the token starts. - */ - start: Point - - /** - * Point where the token ends. - */ - end: Point - - /** - * The previous token in a list of linked tokens. - */ - previous?: Token | undefined - - /** - * The next token in a list of linked tokens. - */ - next?: Token | undefined - - /** - * Declares a token as having content of a certain type. - */ - contentType?: ContentType | undefined - - /** - * Connected tokenizer. - * - * Used when dealing with linked tokens. - * A child tokenizer is needed to tokenize them, which is stored on those - * tokens. - */ - _tokenizer?: TokenizeContext | undefined - - /** - * Field to help parse attention. - * - * Depending on the character before sequences (`**`), the sequence can open, - * close, both, or none. - */ - _open?: boolean | undefined - - /** - * Field to help parse attention. - * - * Depending on the character before sequences (`**`), the sequence can open, - * close, both, or none. - */ - _close?: boolean | undefined - - /** - * Field to help parse GFM task lists. - * - * This boolean is used internally to figure out if a token is in the first - * content of a list item construct. - */ - _isInFirstContentOfListItem?: boolean | undefined - - /** - * Field to help parse containers. - * - * This boolean is used internally to figure out if a token is a container - * token. - */ - _container?: boolean | undefined - - /** - * Field to help parse lists. - * - * This boolean is used internally to figure out if a list is loose or not. - */ - _loose?: boolean | undefined - - /** - * Field to help parse links. - * - * This boolean is used internally to figure out if a link opening - * can’t be used (because links in links are incorrect). - */ - _inactive?: boolean | undefined - - /** - * Field to help parse links. - * - * This boolean is used internally to figure out if a link opening is - * balanced: it’s not a link opening but has a balanced closing. - */ - _balanced?: boolean | undefined -} - -/** - * A context object that helps w/ tokenizing markdown constructs. - */ -declare interface TokenizeContext { - /** - * The previous code. - */ - previous: Code - - /** - * Current code. - */ - code: Code - - /** - * Whether we’re currently interrupting. - * - * Take for example: - * - * ```markdown - * a - * # b - * ``` - * - * At 2:1, we’re “interrupting”. - */ - interrupt?: boolean | undefined - - /** - * The current construct. - * - * Constructs that are not `partial` are set here. - */ - currentConstruct?: Construct | undefined - - /** - * share state set when parsing containers. - * - * Containers are parsed in separate phases: their first line (`tokenize`), - * continued lines (`continuation.tokenize`), and finally `exit`. - * This record can be used to store some information between these hooks. - */ - containerState?: ContainerState | undefined - - /** - * Current list of events. - */ - events: Array - - /** - * The relevant parsing context. - */ - parser: ParseContext - - /** - * Get the chunks that span a token (or location). - * - * @param token - * Start/end in stream. - * @returns - * List of chunks. - */ - sliceStream: (token: Pick) => Array - - /** - * Get the source text that spans a token (or location). - * - * @param token - * Start/end in stream. - * @param expandTabs - * Whether to expand tabs. - * @returns - * Serialized chunks. - */ - sliceSerialize: ( - token: Pick, - expandTabs?: boolean | undefined - ) => string - - /** - * Get the current place. - * - * @returns - * Current point. - */ - now: () => Point - - /** - * Define a skip - * - * As containers (block quotes, lists), “nibble” a prefix from the margins, - * where a line starts after that prefix is defined here. - * When the tokenizers moves after consuming a line ending corresponding to - * the line number in the given point, the tokenizer shifts past the prefix - * based on the column in the shifted point. - * - * @param point - * Skip. - * @returns - * Nothing. - */ - defineSkip: (point: Point) => undefined - - /** - * Write a slice of chunks. - * - * The eof code (`null`) can be used to signal the end of the stream. - * - * @param slice - * Chunks. - * @returns - * Events. - */ - write: (slice: Array) => Array - - /** - * Internal boolean shared with `micromark-extension-gfm-task-list-item` to - * signal whether the tokenizer is tokenizing the first content of a list item - * construct. - */ - _gfmTasklistFirstContentOfListItem?: boolean | undefined - - // To do: next major: remove `_gfmTableDynamicInterruptHack` (no longer - // needed in micromark-extension-gfm-table@1.0.6). - /** - * Internal boolean shared with `micromark-extension-gfm-table` whose body - * rows are not affected by normal interruption rules. - * “Normal” rules are, for example, that an empty list item can’t interrupt: - * - * ````markdown - * a - * * - * ```` - * - * The above is one paragraph. - * These rules don’t apply to table body rows: - * - * ````markdown - * | a | - * | - | - * * - * ```` - * - * The above list interrupts the table. - */ - _gfmTableDynamicInterruptHack?: boolean -} - -/** - * A tokenize function sets up a state machine to handle character codes streaming in. - * - * @param this - * Tokenize context. - * @param effects - * Effects. - * @param ok - * State to go to when successful. - * @param nok - * State to go to when unsuccessful. - * @returns - * First state. - */ -export declare type Tokenizer = ( -this: TokenizeContext, -effects: Effects, -ok: State, -nok: State -) => State - -/** - * Enum of allowed token types. - */ -export declare type TokenType = keyof TokenTypeMap - -/** - * Map of allowed token types. - */ -export declare interface TokenTypeMap { - // Note: these are compiled away. - attentionSequence: 'attentionSequence' // To do: remove. - space: 'space' // To do: remove. - - data: 'data' - whitespace: 'whitespace' - lineEnding: 'lineEnding' - lineEndingBlank: 'lineEndingBlank' - linePrefix: 'linePrefix' - lineSuffix: 'lineSuffix' - atxHeading: 'atxHeading' - atxHeadingSequence: 'atxHeadingSequence' - atxHeadingText: 'atxHeadingText' - autolink: 'autolink' - autolinkEmail: 'autolinkEmail' - autolinkMarker: 'autolinkMarker' - autolinkProtocol: 'autolinkProtocol' - characterEscape: 'characterEscape' - characterEscapeValue: 'characterEscapeValue' - characterReference: 'characterReference' - characterReferenceMarker: 'characterReferenceMarker' - characterReferenceMarkerNumeric: 'characterReferenceMarkerNumeric' - characterReferenceMarkerHexadecimal: 'characterReferenceMarkerHexadecimal' - characterReferenceValue: 'characterReferenceValue' - codeFenced: 'codeFenced' - codeFencedFence: 'codeFencedFence' - codeFencedFenceSequence: 'codeFencedFenceSequence' - codeFencedFenceInfo: 'codeFencedFenceInfo' - codeFencedFenceMeta: 'codeFencedFenceMeta' - codeFlowValue: 'codeFlowValue' - codeIndented: 'codeIndented' - codeText: 'codeText' - codeTextData: 'codeTextData' - codeTextPadding: 'codeTextPadding' - codeTextSequence: 'codeTextSequence' - content: 'content' - definition: 'definition' - definitionDestination: 'definitionDestination' - definitionDestinationLiteral: 'definitionDestinationLiteral' - definitionDestinationLiteralMarker: 'definitionDestinationLiteralMarker' - definitionDestinationRaw: 'definitionDestinationRaw' - definitionDestinationString: 'definitionDestinationString' - definitionLabel: 'definitionLabel' - definitionLabelMarker: 'definitionLabelMarker' - definitionLabelString: 'definitionLabelString' - definitionMarker: 'definitionMarker' - definitionTitle: 'definitionTitle' - definitionTitleMarker: 'definitionTitleMarker' - definitionTitleString: 'definitionTitleString' - emphasis: 'emphasis' - emphasisSequence: 'emphasisSequence' - emphasisText: 'emphasisText' - escapeMarker: 'escapeMarker' - hardBreakEscape: 'hardBreakEscape' - hardBreakTrailing: 'hardBreakTrailing' - htmlFlow: 'htmlFlow' - htmlFlowData: 'htmlFlowData' - htmlText: 'htmlText' - htmlTextData: 'htmlTextData' - image: 'image' - label: 'label' - labelText: 'labelText' - labelLink: 'labelLink' - labelImage: 'labelImage' - labelMarker: 'labelMarker' - labelImageMarker: 'labelImageMarker' - labelEnd: 'labelEnd' - link: 'link' - paragraph: 'paragraph' - reference: 'reference' - referenceMarker: 'referenceMarker' - referenceString: 'referenceString' - resource: 'resource' - resourceDestination: 'resourceDestination' - resourceDestinationLiteral: 'resourceDestinationLiteral' - resourceDestinationLiteralMarker: 'resourceDestinationLiteralMarker' - resourceDestinationRaw: 'resourceDestinationRaw' - resourceDestinationString: 'resourceDestinationString' - resourceMarker: 'resourceMarker' - resourceTitle: 'resourceTitle' - resourceTitleMarker: 'resourceTitleMarker' - resourceTitleString: 'resourceTitleString' - setextHeading: 'setextHeading' - setextHeadingText: 'setextHeadingText' - setextHeadingLine: 'setextHeadingLine' - setextHeadingLineSequence: 'setextHeadingLineSequence' - strong: 'strong' - strongSequence: 'strongSequence' - strongText: 'strongText' - thematicBreak: 'thematicBreak' - thematicBreakSequence: 'thematicBreakSequence' - blockQuote: 'blockQuote' - blockQuotePrefix: 'blockQuotePrefix' - blockQuoteMarker: 'blockQuoteMarker' - blockQuotePrefixWhitespace: 'blockQuotePrefixWhitespace' - listOrdered: 'listOrdered' - listUnordered: 'listUnordered' - listItemIndent: 'listItemIndent' - listItemMarker: 'listItemMarker' - listItemPrefix: 'listItemPrefix' - listItemPrefixWhitespace: 'listItemPrefixWhitespace' - listItemValue: 'listItemValue' - chunkDocument: 'chunkDocument' - chunkContent: 'chunkContent' - chunkFlow: 'chunkFlow' - chunkText: 'chunkText' - chunkString: 'chunkString' -} - -declare type Value = Value_2 - -/** - * Contents of the file. - * - * Can either be text, or a `Uint8Array` like structure. - */ -declare type Value_2 = Uint8Array | string - -export { } - -// Source: node_modules/micromark-extension-directive/index.d.ts - -export declare interface TokenTypeMap { - directiveContainer: 'directiveContainer' - directiveContainerAttributes: 'directiveContainerAttributes' - directiveContainerAttributesMarker: 'directiveContainerAttributesMarker' - directiveContainerAttribute: 'directiveContainerAttribute' - directiveContainerAttributeId: 'directiveContainerAttributeId' - directiveContainerAttributeIdValue: 'directiveContainerAttributeIdValue' - directiveContainerAttributeClass: 'directiveContainerAttributeClass' - directiveContainerAttributeClassValue: 'directiveContainerAttributeClassValue' - directiveContainerAttributeName: 'directiveContainerAttributeName' - directiveContainerAttributeInitializerMarker: 'directiveContainerAttributeInitializerMarker' - directiveContainerAttributeValueLiteral: 'directiveContainerAttributeValueLiteral' - directiveContainerAttributeValue: 'directiveContainerAttributeValue' - directiveContainerAttributeValueMarker: 'directiveContainerAttributeValueMarker' - directiveContainerAttributeValueData: 'directiveContainerAttributeValueData' - directiveContainerContent: 'directiveContainerContent' - directiveContainerFence: 'directiveContainerFence' - directiveContainerLabel: 'directiveContainerLabel' - directiveContainerLabelMarker: 'directiveContainerLabelMarker' - directiveContainerLabelString: 'directiveContainerLabelString' - directiveContainerName: 'directiveContainerName' - directiveContainerSequence: 'directiveContainerSequence' - - directiveLeaf: 'directiveLeaf' - directiveLeafAttributes: 'directiveLeafAttributes' - directiveLeafAttributesMarker: 'directiveLeafAttributesMarker' - directiveLeafAttribute: 'directiveLeafAttribute' - directiveLeafAttributeId: 'directiveLeafAttributeId' - directiveLeafAttributeIdValue: 'directiveLeafAttributeIdValue' - directiveLeafAttributeClass: 'directiveLeafAttributeClass' - directiveLeafAttributeClassValue: 'directiveLeafAttributeClassValue' - directiveLeafAttributeName: 'directiveLeafAttributeName' - directiveLeafAttributeInitializerMarker: 'directiveLeafAttributeInitializerMarker' - directiveLeafAttributeValueLiteral: 'directiveLeafAttributeValueLiteral' - directiveLeafAttributeValue: 'directiveLeafAttributeValue' - directiveLeafAttributeValueMarker: 'directiveLeafAttributeValueMarker' - directiveLeafAttributeValueData: 'directiveLeafAttributeValueData' - directiveLeafLabel: 'directiveLeafLabel' - directiveLeafLabelMarker: 'directiveLeafLabelMarker' - directiveLeafLabelString: 'directiveLeafLabelString' - directiveLeafName: 'directiveLeafName' - directiveLeafSequence: 'directiveLeafSequence' - - directiveText: 'directiveText' - directiveTextAttributes: 'directiveTextAttributes' - directiveTextAttributesMarker: 'directiveTextAttributesMarker' - directiveTextAttribute: 'directiveTextAttribute' - directiveTextAttributeId: 'directiveTextAttributeId' - directiveTextAttributeIdValue: 'directiveTextAttributeIdValue' - directiveTextAttributeClass: 'directiveTextAttributeClass' - directiveTextAttributeClassValue: 'directiveTextAttributeClassValue' - directiveTextAttributeName: 'directiveTextAttributeName' - directiveTextAttributeInitializerMarker: 'directiveTextAttributeInitializerMarker' - directiveTextAttributeValueLiteral: 'directiveTextAttributeValueLiteral' - directiveTextAttributeValue: 'directiveTextAttributeValue' - directiveTextAttributeValueMarker: 'directiveTextAttributeValueMarker' - directiveTextAttributeValueData: 'directiveTextAttributeValueData' - directiveTextLabel: 'directiveTextLabel' - directiveTextLabelMarker: 'directiveTextLabelMarker' - directiveTextLabelString: 'directiveTextLabelString' - directiveTextMarker: 'directiveTextMarker' - directiveTextName: 'directiveTextName' -} - -// Source: node_modules/micromark-extension-gfm-autolink-literal/index.d.ts - -export declare interface TokenTypeMap { - literalAutolink: 'literalAutolink' - literalAutolinkEmail: 'literalAutolinkEmail' - literalAutolinkHttp: 'literalAutolinkHttp' - literalAutolinkWww: 'literalAutolinkWww' -} - -// Source: node_modules/micromark-extension-gfm-footnote/index.d.ts - -export declare interface TokenTypeMap { - gfmFootnoteCall: 'gfmFootnoteCall' - gfmFootnoteCallLabelMarker: 'gfmFootnoteCallLabelMarker' - gfmFootnoteCallMarker: 'gfmFootnoteCallMarker' - gfmFootnoteCallString: 'gfmFootnoteCallString' - gfmFootnoteDefinition: 'gfmFootnoteDefinition' - gfmFootnoteDefinitionIndent: 'gfmFootnoteDefinitionIndent' - gfmFootnoteDefinitionLabel: 'gfmFootnoteDefinitionLabel' - gfmFootnoteDefinitionLabelMarker: 'gfmFootnoteDefinitionLabelMarker' - gfmFootnoteDefinitionLabelString: 'gfmFootnoteDefinitionLabelString' - gfmFootnoteDefinitionMarker: 'gfmFootnoteDefinitionMarker' - gfmFootnoteDefinitionWhitespace: 'gfmFootnoteDefinitionWhitespace' -} - -// Source: node_modules/micromark-extension-gfm-table/index.d.ts - -export declare interface TokenTypeMap { - table: 'table' - tableBody: 'tableBody' - tableCellDivider: 'tableCellDivider' - tableContent: 'tableContent' - tableData: 'tableData' - tableDelimiter: 'tableDelimiter' - tableDelimiterFiller: 'tableDelimiterFiller' - tableDelimiterMarker: 'tableDelimiterMarker' - tableDelimiterRow: 'tableDelimiterRow' - tableHead: 'tableHead' - tableHeader: 'tableHeader' - tableRow: 'tableRow' -} - -// Source: node_modules/micromark-extension-math/index.d.ts - -export declare interface TokenTypeMap { - mathFlow: 'mathFlow' - mathFlowFence: 'mathFlowFence' - mathFlowFenceMeta: 'mathFlowFenceMeta' - mathFlowFenceSequence: 'mathFlowFenceSequence' - mathFlowValue: 'mathFlowValue' - mathText: 'mathText' - mathTextData: 'mathTextData' - mathTextPadding: 'mathTextPadding' - mathTextSequence: 'mathTextSequence' -} - -// Source: Custom types generated by markdownlint in getEvents - -export declare interface TokenTypeMap { - undefinedReference: 'undefinedReference' - undefinedReferenceCollapsed: 'undefinedReferenceCollapsed' - undefinedReferenceFull: 'undefinedReferenceFull' - undefinedReferenceShortcut: 'undefinedReferenceShortcut' -} diff --git a/micromark/package.json b/micromark/package.json deleted file mode 100644 index 58c50af56..000000000 --- a/micromark/package.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "name": "markdownlint-micromark", - "version": "0.1.12", - "description": "A trivial package that re-exports some micromark functionality as a CommonJS module", - "type": "commonjs", - "exports": "./micromark.cjs", - "types": "./micromark.d.cts", - "author": "David Anson (https://dlaa.me/)", - "license": "MIT", - "homepage": "https://github.com/DavidAnson/markdownlint", - "repository": { - "type": "git", - "url": "git+https://github.com/DavidAnson/markdownlint.git" - }, - "bugs": "https://github.com/DavidAnson/markdownlint/issues", - "funding": "https://github.com/sponsors/DavidAnson", - "scripts": { - "build": "webpack --stats minimal", - "types": "api-extractor run --local" - }, - "engines": { - "node": ">=18" - }, - "files": [ - "LICENSE", - "micromark-browser.js", - "micromark-html-browser.js", - "micromark.cjs", - "micromark.d.cts", - "package.json", - "README.md" - ], - "devDependencies": { - "@microsoft/api-extractor": "7.47.12", - "micromark": "4.0.1", - "micromark-extension-directive": "3.0.2", - "micromark-extension-gfm-autolink-literal": "2.1.0", - "micromark-extension-gfm-footnote": "2.1.0", - "micromark-extension-gfm-table": "2.1.0", - "micromark-extension-math": "3.1.0", - "micromark-util-types": "2.0.1", - "terser-webpack-plugin": "5.3.10", - "webpack": "5.96.1", - "webpack-cli": "5.1.4" - } -} diff --git a/micromark/types.d.ts b/micromark/types.d.ts deleted file mode 100644 index e146e23e3..000000000 --- a/micromark/types.d.ts +++ /dev/null @@ -1,34 +0,0 @@ -// Manually update due to api-extractor limitations including: -// - https://github.com/microsoft/rushstack/issues/1709 -// - ERROR: Failed to fetch entity for import() type node: import('micromark-util-types').ParseContext -// - Unwillingness to treat "katex" as one of bundledPackages -// -// 1. npm install -// 2. Comment-out micromark-util-types/ParseContext in micromark/node_modules/micromark-extension-gfm-footnote/index.d.ts -// 3. npm run types -// 4. Remove "import type { KatexOptions } from 'katex';" in micromark/micromark.d.cts -// 5. Replace "KatexOptions" with "Object" in micromark/micromark.d.cts -// 6. Append "declare module 'micromark-util-types' { interface TokenTypeMap { ... } }" in micromark/micromark.d.cts from: -// - micromark/node_modules/micromark-extension-directive/index.d.ts -// - micromark/node_modules/micromark-extension-gfm-autolink-literal/index.d.ts -// - micromark/node_modules/micromark-extension-gfm-footnote/index.d.ts -// - micromark/node_modules/micromark-extension-gfm-table/index.d.ts -// - micromark/node_modules/micromark-extension-math/index.d.ts -// - export declare interface TokenTypeMap { -// undefinedReference: 'undefinedReference' -// undefinedReferenceCollapsed: 'undefinedReferenceCollapsed' -// undefinedReferenceFull: 'undefinedReferenceFull' -// undefinedReferenceShortcut: 'undefinedReferenceShortcut' -// } -// 7. Update version number in package.json and stage changes -// 8. Test: npm run build, npm pack, npm install ./micromark/markdownlint-micromark-0.1.11.tgz, npm run ci, verify types like gfmFootnote* in getReferenceLinkImageData(...) -// 9. Publish: git clean -dfx, npm install, npm run build, npm publish ., git push - -export type { directive, directiveHtml } from "micromark-extension-directive"; -export type { gfmAutolinkLiteral, gfmAutolinkLiteralHtml } from "micromark-extension-gfm-autolink-literal"; -export type { gfmFootnote, gfmFootnoteHtml } from "micromark-extension-gfm-footnote"; -export type { gfmTable, gfmTableHtml } from "micromark-extension-gfm-table"; -export type { math, mathHtml } from "micromark-extension-math"; -export type { compile, parse, postprocess, preprocess } from "micromark"; - -export type { CompileData, Construct, Event, ParseOptions, State, Token, TokenType, TokenTypeMap, Tokenizer } from "micromark-util-types"; diff --git a/micromark/webpack.config.js b/micromark/webpack.config.js deleted file mode 100644 index 3cc2c28bd..000000000 --- a/micromark/webpack.config.js +++ /dev/null @@ -1,127 +0,0 @@ -// @ts-check - -"use strict"; - -const webpack = require("webpack"); -const TerserPlugin = require("terser-webpack-plugin"); -const { name, version, homepage } = require("./package.json"); - -const htmlEntry = "./exports-html.mjs"; -const htmlName = "micromarkHtmlBrowser"; - -const base = { - "entry": "./exports.mjs", - "output": { - "path": __dirname - }, - "plugins": [ - new webpack.BannerPlugin({ - "banner": `${name} ${version} ${homepage}` - }) - ] -}; - -const commonjs = { - ...base, - "output": { - ...base.output, - "library": { - "type": "commonjs" - } - }, - "target": "node" -}; - -const web = { - ...base, - "output": { - ...base.output, - "library": { - "name": "micromarkBrowser", - "type": "var" - } - }, - "target": "web" -}; - -const production = { - "mode": "production", - "optimization": { - "minimizer": [ - new TerserPlugin({ - "extractComments": false, - "terserOptions": { - "compress": { - "passes": 2 - } - } - }) - ] - } -}; - -const development = { - "devtool": false, - "mode": "development" -}; - -module.exports = [ - { - ...commonjs, - ...production, - "output": { - ...commonjs.output, - "filename": "micromark.cjs" - } - }, - { - ...commonjs, - ...development, - "output": { - ...commonjs.output, - "filename": "micromark.dev.cjs" - } - }, - { - ...web, - ...production, - "output": { - ...web.output, - "filename": "micromark-browser.js" - } - }, - { - ...web, - ...development, - "output": { - ...web.output, - "filename": "micromark-browser.dev.js" - } - }, - { - ...web, - ...production, - "entry": htmlEntry, - "output": { - ...web.output, - "library": { - ...web.output.library, - "name": htmlName - }, - "filename": "micromark-html-browser.js" - } - }, - { - ...web, - ...development, - "entry": htmlEntry, - "output": { - ...web.output, - "library": { - ...web.output.library, - "name": htmlName - }, - "filename": "micromark-html-browser.dev.js" - } - } -]; diff --git a/package.json b/package.json index 243823c7c..fc191190a 100644 --- a/package.json +++ b/package.json @@ -2,10 +2,10 @@ "name": "markdownlint", "version": "0.36.1", "description": "A Node.js style checker and lint tool for Markdown/CommonMark files.", - "type": "commonjs", - "main": "./lib/markdownlint.js", + "type": "module", + "main": "./lib/markdownlint.mjs", "exports": { - ".": "./lib/markdownlint.js", + ".": "./lib/markdownlint.mjs", "./helpers": "./helpers/helpers.js", "./style/all": "./style/all.json", "./style/cirosantilli": "./style/cirosantilli.json", @@ -24,9 +24,9 @@ "funding": "https://github.com/sponsors/DavidAnson", "scripts": { "build-config": "npm run build-config-schema && npm run build-config-example", - "build-config-example": "node schema/build-config-example.js", - "build-config-schema": "node schema/build-config-schema.js", - "build-declaration": "tsc --allowJs --declaration --emitDeclarationOnly --module commonjs --outDir dts --resolveJsonModule --target es2015 lib/markdownlint.js && node scripts copy dts/lib/markdownlint.d.ts lib/markdownlint.d.ts && node scripts remove dts", + "build-config-example": "node schema/build-config-example.mjs", + "build-config-schema": "node schema/build-config-schema.mjs", + "build-declaration": "tsc --allowJs --declaration --emitDeclarationOnly --module commonjs --outDir dts --resolveJsonModule --target es2015 lib/markdownlint.mjs && node scripts copy dts/lib/markdownlint.d.ts lib/markdownlint.d.ts && node scripts remove dts", "build-demo": "node scripts copy node_modules/markdown-it/dist/markdown-it.min.js demo/markdown-it.min.js && node scripts copy node_modules/markdownlint-micromark/micromark-browser.js demo/micromark-browser.js && node scripts copy node_modules/markdownlint-micromark/micromark-html-browser.js demo/micromark-html-browser.js && cd demo && webpack --no-stats", "build-docs": "node doc-build/build-rules.mjs", "build-example": "npm install --no-save --ignore-scripts grunt grunt-cli gulp through2", @@ -50,15 +50,15 @@ "docker-npm-run-upgrade": "docker run --rm --tty --name npm-run-upgrade --volume $PWD:/home/workdir --workdir /home/workdir --user node node:latest npm run upgrade", "install-micromark": "cd micromark && npm install", "lint": "eslint --max-warnings 0", - "lint-test-repos": "ava --timeout=10m test/markdownlint-test-repos-*.js", + "lint-test-repos": "ava --timeout=10m test/markdownlint-test-repos-*.mjs", "serial-config-docs": "npm run build-config && npm run build-docs", "serial-declaration-demo": "npm run build-declaration && npm-run-all --continue-on-error --parallel build-demo test-declaration", - "test": "ava --timeout=30s test/markdownlint-test.js test/markdownlint-test-config.js test/markdownlint-test-custom-rules.js test/markdownlint-test-fixes.js test/markdownlint-test-helpers.js test/markdownlint-test-micromark.mjs test/markdownlint-test-result-object.js test/markdownlint-test-scenarios.js helpers/test.cjs", + "test": "ava --timeout=30s test/markdownlint-test.mjs test/markdownlint-test-config.mjs test/markdownlint-test-custom-rules.mjs test/markdownlint-test-fixes.mjs test/markdownlint-test-helpers.mjs test/markdownlint-test-micromark.mjs test/markdownlint-test-result-object.mjs test/markdownlint-test-scenarios.mjs helpers/test.cjs", "test-cover": "c8 --100 npm test", - "test-declaration": "cd example/typescript && tsc --module nodenext && tsc --module commonjs && node type-check.js", - "test-extra": "ava --timeout=10m test/markdownlint-test-extra-parse.js test/markdownlint-test-extra-type.js", - "update-snapshots": "ava --update-snapshots test/markdownlint-test-custom-rules.js test/markdownlint-test-micromark.mjs test/markdownlint-test-scenarios.js", - "update-snapshots-test-repos": "ava --timeout=10m --update-snapshots test/markdownlint-test-repos-*.js", + "test-declaration": "cd example/typescript && tsc --module nodenext && tsc --module commonjs && node type-check.mjs", + "test-extra": "ava --timeout=10m test/markdownlint-test-extra-parse.mjs test/markdownlint-test-extra-type.mjs", + "update-snapshots": "ava --update-snapshots test/markdownlint-test-custom-rules.mjs test/markdownlint-test-micromark.mjs test/markdownlint-test-scenarios.mjs", + "update-snapshots-test-repos": "ava --timeout=10m --update-snapshots test/markdownlint-test-repos-*.mjs", "upgrade": "npx --yes npm-check-updates --upgrade" }, "engines": { diff --git a/schema/build-config-example.js b/schema/build-config-example.mjs similarity index 93% rename from schema/build-config-example.js rename to schema/build-config-example.mjs index bc75f7e19..a72d517e5 100644 --- a/schema/build-config-example.js +++ b/schema/build-config-example.mjs @@ -1,10 +1,8 @@ // @ts-check -"use strict"; - -const fs = require("node:fs"); -const path = require("node:path"); -const yaml = require("js-yaml"); +import fs from "node:fs"; +import path from "node:path"; +import yaml from "js-yaml"; const configSchema = require("./markdownlint-config-schema.json"); const configExample = {}; diff --git a/schema/build-config-schema.js b/schema/build-config-schema.mjs similarity index 98% rename from schema/build-config-schema.js rename to schema/build-config-schema.mjs index b967ad1c0..9668a14b9 100644 --- a/schema/build-config-schema.js +++ b/schema/build-config-schema.mjs @@ -2,12 +2,12 @@ "use strict"; -const fs = require("node:fs"); -const path = require("node:path"); +import fs from "node:fs"; +import path from "node:path"; /** @type {import("../lib/markdownlint").Rule[]} */ -const rules = require("../lib/rules"); -const jsonSchemaToTypeScript = require("json-schema-to-typescript"); -const { version } = require("../lib/constants"); +import rules from "../lib/rules.mjs"; +import jsonSchemaToTypeScript from "json-schema-to-typescript"; +import { version } from "../lib/constants.mjs"; const schemaName = "markdownlint-config-schema.json"; const schemaUri = `https://raw.githubusercontent.com/DavidAnson/markdownlint/v${version}/schema/${schemaName}`; diff --git a/scripts/index.js b/scripts/index.js deleted file mode 100644 index 03ef88a07..000000000 --- a/scripts/index.js +++ /dev/null @@ -1,29 +0,0 @@ -// @ts-check - -"use strict"; - -const fs = require("node:fs").promises; - -const [ command, ...args ] = process.argv.slice(2); - -// eslint-disable-next-line unicorn/prefer-top-level-await -(async() => { - if (command === "copy") { - const [ src, dest ] = args; - await fs.copyFile(src, dest); - } else if (command === "delete") { - const { globby } = await import("globby"); - await Promise.all( - args.flatMap( - (glob) => globby(glob) - .then( - (files) => files.map((file) => fs.unlink(file)) - ) - ) - ); - } else if (command === "remove") { - await Promise.all(args.map((dir) => fs.rm(dir, { "recursive": true }))); - } else { - throw new Error(`Unsupported command: ${command}`); - } -})(); diff --git a/scripts/index.mjs b/scripts/index.mjs new file mode 100644 index 000000000..9e9ff6b4e --- /dev/null +++ b/scripts/index.mjs @@ -0,0 +1,24 @@ +// @ts-check + +import fs from "node:fs/promises"; +import { globby } from "globby"; + +const [ command, ...args ] = process.argv.slice(2); + +if (command === "copy") { + const [ src, dest ] = args; + await fs.copyFile(src, dest); +} else if (command === "delete") { + await Promise.all( + args.flatMap( + (glob) => globby(glob) + .then( + (files) => files.map((file) => fs.unlink(file)) + ) + ) + ); +} else if (command === "remove") { + await Promise.all(args.map((dir) => fs.rm(dir, { "recursive": true }))); +} else { + throw new Error(`Unsupported command: ${command}`); +}