remark-mdat 0.7.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/license.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Eric Mika
3
+ Copyright (c) 2024 - 2025 Eric Mika
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,63 +1,67 @@
1
1
  {
2
2
  "name": "remark-mdat",
3
- "version": "0.7.4",
4
- "type": "module",
3
+ "version": "1.0.0",
5
4
  "description": "A remark plugin implementing the Markdown Autophagic Template (MDAT) system.",
6
- "repository": "github:kitschpatrol/remark-mdat",
5
+ "keywords": [
6
+ "mdat",
7
+ "markdown",
8
+ "template",
9
+ "comments",
10
+ "unist",
11
+ "mdast",
12
+ "mdast-util",
13
+ "syntax-tree",
14
+ "remark",
15
+ "remark-plugin"
16
+ ],
7
17
  "homepage": "https://github.com/kitschpatrol/remark-mdat",
8
18
  "bugs": "https://github.com/kitschpatrol/remark-mdat/issues",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/github:kitschpatrol/remark-mdat"
22
+ },
23
+ "license": "MIT",
9
24
  "author": {
10
25
  "name": "Eric Mika",
11
26
  "email": "eric@ericmika.com",
12
27
  "url": "https://ericmika.com"
13
28
  },
14
- "license": "MIT",
15
- "engines": {
16
- "node": "^18.19.0 || >=20.5.0",
17
- "pnpm": ">=9.0.0"
18
- },
29
+ "type": "module",
19
30
  "main": "./dist/index.js",
20
31
  "module": "./dist/index.js",
21
32
  "types": "./dist/index.d.ts",
22
33
  "files": [
23
34
  "dist/*"
24
35
  ],
25
- "keywords": [
26
- "mdat",
27
- "markdown",
28
- "template",
29
- "comments",
30
- "unist",
31
- "mdast",
32
- "mdast-util",
33
- "syntax-tree",
34
- "remark",
35
- "remark-plugin"
36
- ],
37
36
  "dependencies": {
38
37
  "@types/mdast": "^4.0.4",
39
38
  "@types/node": "18.19.0",
40
- "@types/unist": "^3.0.3"
39
+ "@types/unist": "^3.0.3",
40
+ "type-fest": "^4.36.0",
41
+ "unified": "^11.0.5",
42
+ "vfile": "^6.0.3",
43
+ "zod": "^3.24.2"
41
44
  },
42
45
  "devDependencies": {
43
- "@kitschpatrol/shared-config": "^4.7.11",
44
- "bumpp": "^9.8.1",
45
- "chalk": "^5.3.0",
46
+ "@kitschpatrol/shared-config": "^5.0.6",
47
+ "@microsoft/api-extractor": "^7.51.1",
48
+ "bumpp": "^10.0.3",
49
+ "chalk": "^5.4.1",
46
50
  "cli-table3": "^0.6.5",
47
- "deepmerge-ts": "^7.1.3",
51
+ "deepmerge-ts": "^7.1.5",
48
52
  "hast-util-from-html": "^2.0.3",
49
53
  "json5": "^2.2.3",
50
54
  "remark": "^15.0.1",
51
- "remark-gfm": "^4.0.0",
52
- "tsup": "^8.3.5",
53
- "type-fest": "^4.26.1",
54
- "typescript": "^5.6.3",
55
- "unified": "^11.0.5",
55
+ "remark-gfm": "^4.0.1",
56
+ "tsup": "^8.4.0",
57
+ "typescript": "~5.7.3",
56
58
  "unist-util-visit": "^5.0.0",
57
- "vfile": "^6.0.3",
58
59
  "vfile-message": "^4.0.2",
59
- "vitest": "^2.1.4",
60
- "zod": "^3.23.8"
60
+ "vitest": "^3.0.7"
61
+ },
62
+ "engines": {
63
+ "node": "^18.19.0 || >=20.5.0",
64
+ "pnpm": ">=10.0.0"
61
65
  },
62
66
  "publishConfig": {
63
67
  "access": "public"
@@ -66,8 +70,8 @@
66
70
  "build": "tsup && tsc -p tsconfig.build.json",
67
71
  "clean": "git rm -f pnpm-lock.yaml ; git clean -fdX",
68
72
  "dev": "pnpm run test",
69
- "fix": "shared-config --fix",
70
- "lint": "shared-config --lint",
73
+ "fix": "kpi fix",
74
+ "lint": "kpi lint",
71
75
  "release": "bumpp --commit 'Release: %s' && pnpm run build && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
72
76
  "test": "vitest"
73
77
  }
package/readme.md CHANGED
@@ -19,7 +19,8 @@
19
19
 
20
20
  <!-- /description -->
21
21
 
22
- > \[!NOTE]\
22
+ > [!NOTE]
23
+ >
23
24
  > **Please see The [`mdat` package](https://github.com/kitschpatrol/mdat) for a higher-level CLI tool and library with a collection of built-in expansion rules.**
24
25
 
25
26
  <!-- table-of-contents -->
@@ -100,11 +101,11 @@ The plugin accepts an optional options object which exposes some configuration o
100
101
 
101
102
  ```ts
102
103
  export type Options = {
103
- addMetaComment?: boolean // default: false
104
- closingPrefix?: string // default: '/',
105
- keywordPrefix?: string // default: '',
106
- metaCommentIdentifier?: string // default: '+',
107
- rules?: Rules // default: a single test rule for the 'mdat' keyword
104
+ addMetaComment?: boolean // Default: false
105
+ closingPrefix?: string // Default: '/',
106
+ keywordPrefix?: string // Default: '',
107
+ metaCommentIdentifier?: string // Default: '+',
108
+ rules?: Rules // Default: a single test rule for the 'mdat' keyword
108
109
  }
109
110
  ```
110
111
 
@@ -137,7 +138,7 @@ If you wanted to replace `<!-- time -->` comments in your Markdown file with the
137
138
 
138
139
  ```ts
139
140
  import { remark } from 'remark'
140
- import { type Rules, default as remarkMdat } from 'remark-mdat'
141
+ import remarkMdat, { type Rules } from 'remark-mdat'
141
142
 
142
143
  // Create the rule
143
144
  const rules: Rules = {
package/dist/index.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export { mdat, type Options as MdatOptions } from './lib/mdast-utils/mdast-util-mdat';
2
- export { mdatCheck, type Options as MdatCheckOptions, } from './lib/mdast-utils/mdast-util-mdat-check';
3
- export { mdatClean, type Options as MdatCleanOptions, } from './lib/mdast-utils/mdast-util-mdat-clean';
4
- export { mdatExpand, type Options as MdatExpandOptions, } from './lib/mdast-utils/mdast-util-mdat-expand';
5
- export { mdatSplit } from './lib/mdast-utils/mdast-util-mdat-split';
6
- export { deepMergeDefined } from './lib/mdat/deep-merge-defined';
7
- export { default as log } from './lib/mdat/log';
8
- export { getMdatReports, type MdatFileReport, type MdatMessage, reporterMdat, } from './lib/mdat/mdat-log';
9
- export { getSoleRule, getSoleRuleKey, type NormalizedRule, type NormalizedRules, type Rule, type Rules, rulesSchema, type SimplifyDeep, } from './lib/mdat/rules';
10
- export { default, type Options, optionsSchema } from './lib/remark-mdat';
@@ -1,16 +0,0 @@
1
- import type { Root } from 'mdast';
2
- import type { VFile } from 'vfile';
3
- import { type Rules } from '../mdat/rules';
4
- export type Options = {
5
- addMetaComment: boolean;
6
- closingPrefix: string;
7
- keywordPrefix: string;
8
- metaCommentIdentifier: string;
9
- /** Enable extra checks, too noisy for real life. */
10
- paranoid: boolean;
11
- rules: Rules;
12
- };
13
- /**
14
- * Mdast utility function to check mdat source document, and output.
15
- */
16
- export declare function mdatCheck(tree: Root, file: VFile, options: Options): Promise<void>;
@@ -1,13 +0,0 @@
1
- import type { Root } from 'mdast';
2
- import { type VFile } from 'vfile';
3
- export type Options = {
4
- closingPrefix: string;
5
- keywordPrefix: string;
6
- metaCommentIdentifier: string;
7
- };
8
- /**
9
- * Collapses any expanded mdat comments and removes meta comments,
10
- * effectively resetting the document to its pre-expansion state. No-op if no
11
- * mdat comments are found.
12
- */
13
- export declare function mdatClean(tree: Root, file: VFile, options: Options): void;
@@ -1,11 +0,0 @@
1
- import type { Root } from 'mdast';
2
- import { type VFile } from 'vfile';
3
- import { type Rules } from '../mdat/rules';
4
- export type Options = {
5
- addMetaComment: boolean;
6
- closingPrefix: string;
7
- keywordPrefix: string;
8
- metaCommentIdentifier: string;
9
- rules: Rules;
10
- };
11
- export declare function mdatExpand(tree: Root, file: VFile, options: Options): Promise<void>;
@@ -1,9 +0,0 @@
1
- import type { Root } from 'mdast';
2
- import { type Html, type Text } from 'mdast';
3
- import { type VFile } from 'vfile';
4
- /**
5
- * Mdast utility plugin to split any multi-comment nodes and their content into individual MDAST HTML
6
- * nodes. They're wrapped in a paragraph so as not to introduce new breaks.
7
- */
8
- export declare function mdatSplit(tree: Root, file: VFile): void;
9
- export declare function splitHtmlIntoMdastNodes(mdastNode: Html): Array<Html | Text>;
@@ -1,11 +0,0 @@
1
- import type { Root } from 'mdast';
2
- import { type VFile } from 'vfile';
3
- import { type Rules } from '../mdat/rules';
4
- export type Options = {
5
- addMetaComment: boolean;
6
- closingPrefix: string;
7
- keywordPrefix: string;
8
- metaCommentIdentifier: string;
9
- rules: Rules;
10
- };
11
- export declare function mdat(tree: Root, file: VFile, options: Options): Promise<void>;
@@ -1,2 +0,0 @@
1
- export declare function stripUndefinedDeep<T>(object: T | T[]): T | T[];
2
- export declare function deepMergeDefined<T extends Record<string, unknown>>(...objects: T[]): T;
@@ -1,12 +0,0 @@
1
- declare const log: {
2
- verbose: boolean;
3
- log(...data: unknown[]): void;
4
- logPrefixed(prefix: string, ...data: unknown[]): void;
5
- info(...data: unknown[]): void;
6
- infoPrefixed(prefix: string, ...data: unknown[]): void;
7
- warn(...data: unknown[]): void;
8
- warnPrefixed(prefix: string, ...data: unknown[]): void;
9
- error(...data: unknown[]): void;
10
- errorPrefixed(prefix: string, ...data: unknown[]): void;
11
- };
12
- export default log;
@@ -1,20 +0,0 @@
1
- import type { Node } from 'unist';
2
- import { type VFile } from 'vfile';
3
- export type MdatMessage = {
4
- column?: number;
5
- level: 'error' | 'info' | 'warn';
6
- line?: number;
7
- message: string;
8
- source?: string;
9
- };
10
- export type MdatFileReport = {
11
- destinationPath?: string;
12
- errors: MdatMessage[];
13
- infos: MdatMessage[];
14
- sourcePath: string;
15
- warnings: MdatMessage[];
16
- };
17
- export declare function saveLog(file: VFile, level: 'error' | 'info' | 'warn', source: string, message: string, line?: number, column?: number): void;
18
- export declare function saveLog(file: VFile, level: 'error' | 'info' | 'warn', source: string, message: string, node?: Node): void;
19
- export declare function getMdatReports(files: VFile[]): MdatFileReport[];
20
- export declare function reporterMdat(files: VFile[]): void;
@@ -1,62 +0,0 @@
1
- import type { JsonValue } from 'type-fest';
2
- import { type Html, type Parent } from 'mdast';
3
- import { type Simplify } from 'type-fest';
4
- /**
5
- * Structured data about a parsed comment.
6
- * Note that this is a discriminated union based on the `type` field.
7
- */
8
- export type CommentMarker = Simplify<{
9
- /** The complete original comment, e.g. `<!-- keyword -->` */
10
- html: string;
11
- } & ({
12
- /** Character used to delimit closing tags, e.g. the `/` in `<!-- /keyword -->` */
13
- closingPrefix: string;
14
- /** The first complete word in the comment */
15
- keyword: string;
16
- /** The unique keyword prefix */
17
- keywordPrefix: string;
18
- /** Parsed JSON object of argument string that followed the keyword, empty object if nothing passed */
19
- options: JsonValue;
20
- /**
21
- * `open`: A mdat-style opening comment tag, e.g. `<!-- keyword -->` \
22
- * `close`: A mdat-style closing comment tag, e.g. `<!-- /keyword -->`
23
- */
24
- type: 'close' | 'open';
25
- } | {
26
- /** The original text inside the comment, e.g. `<!-- content -->` */
27
- content: string;
28
- /**
29
- * `meta`: A mdat-style generated meta comment tag \
30
- * `native`: A normal comment that does not match the the `keywordPrefix` (if specified)
31
- */
32
- type: 'meta' | 'native';
33
- })>;
34
- /**
35
- * Parsed comment with additional information about the Mdast Node and its Parent.
36
- */
37
- export type CommentMarkerNode = Simplify<{
38
- /** Original Mdast HTML Node where the comment was found. */
39
- node: Html;
40
- /** Parent of original Mdast HTML Node where the comment was found. */
41
- parent: Parent;
42
- } & CommentMarker>;
43
- export type CommentMarkerParseOptions = {
44
- /** Character to identify closing tags, e.g. the `/` in `<!-- /keyword -->` */
45
- closingPrefix: string;
46
- /** Prefix to require on all mdat comments, e.g. `mm-` */
47
- keywordPrefix: string;
48
- /** Means of identifying mdat generated meta comments, e.g. `+` */
49
- metaCommentIdentifier: string;
50
- };
51
- /**
52
- * Parse an Mdast HTML comment node into structured data.
53
- * @returns A discriminated union of CommentMarkerNode based on comment type, or
54
- * undefined if the node is not a comment.
55
- */
56
- export declare function parseCommentNode(node: Html, parent: Parent, options: CommentMarkerParseOptions): CommentMarkerNode | undefined;
57
- /**
58
- * Parse any comment string into structured data.
59
- * @returns A discriminated union of CommentMarker based on comment type, or
60
- * undefined if the node is not a comment.
61
- */
62
- export declare function parseComment(text: string, options: CommentMarkerParseOptions): CommentMarker | undefined;
@@ -1,117 +0,0 @@
1
- import type { Merge, MergeDeep, SetOptional, Simplify } from 'type-fest';
2
- import { type Root } from 'mdast';
3
- import { type JsonValue } from 'type-fest';
4
- import { z } from 'zod';
5
- export type SimplifyDeep<T> = Simplify<MergeDeep<T, T>>;
6
- /**
7
- * Strict normalized rules used internally.
8
- * Rules normalized to a form with async content functions and other default metadata
9
- * Simplifies processing elsewhere, while retaining flexibility for rule authors
10
- */
11
- export type NormalizedRule = {
12
- /**
13
- * The order in which the rule should be applied during processing
14
- * Helpful if a rule depends on the presence of content generated by another rule
15
- * Defaults to 0.
16
- */
17
- applicationOrder: number;
18
- /**
19
- * The function that generates the expanded Markdown string.
20
- * For 'compound' rules, this can be an array of rules (without keywords).
21
- */
22
- content: ((options: JsonValue, tree: Root) => Promise<string>) | NormalizedRule[];
23
- /**
24
- * The expected order of the keyword in the document relative to other expander comments.
25
- * Used for validation purposes.
26
- * Leave undefined to order skip validation.
27
- * Defaults to undefined, which means order is not enforced.
28
- */
29
- order: number | undefined;
30
- /**
31
- * Whether the presence of the keyword comment in the document is required.
32
- * Used for validation purposes.
33
- * Defaults to false.
34
- */
35
- required: boolean;
36
- };
37
- export type Rule =
38
- /**
39
- * Function that returns the Markdown string to expand at the comment site.
40
- */
41
- ((options: JsonValue, tree: Root) => Promise<string> | string)
42
- /**
43
- * Compound rules may be defined an array of rules, without keywords.
44
- * Can be defined at the top level, if no validation metadata is required, or as the 'content' value
45
- * of a rule object with validation metadata.
46
- */
47
- | Rule[]
48
- /**
49
- * The Markdown string to expand at the comment site.
50
- */
51
- | SetOptional<Merge<NormalizedRule, {
52
- /**
53
- * Gets content to expand into the comment.
54
- * Can be a simple string for direct replacement, a function that returns a string, or an async function that returns a string.
55
- *
56
- * If a function is provided, it will be passed the following arguments:
57
- *
58
- * @param options
59
- * JSON value of options parsed immediately after the comment keyword in the comment, e.g.:
60
- * `<!-- keyword({something: true}) -->` or
61
- * `<!-- keyword {something: true}-->`
62
- * Sets options to {something: true}
63
- *
64
- * @param tree
65
- * Markdown (mdast) abstract syntax tree containing the entire parsed document. Useful for expanders that need the entire document context, such as when generating a table of contents. Do not mutate the AST, instead return a new string.
66
- *
67
- * @returns A string with the generated content. The string will be parsed as Markdown and inserted into the document at the comment's location.
68
- */
69
- content: ((options: JsonValue, tree: Root) => Promise<string> | string) | Rule[] | string;
70
- }>, 'applicationOrder' | 'order' | 'required'> | string;
71
- /**
72
- * Rules are record objects whose keys match strings inside a Markdown comment, and values explain what should be expanded at the comment site.
73
- *
74
- * The record value may be a string, or an object containing additional metadata, possibly with a function to invoke to generate content.
75
- *
76
- *
77
- *
78
- * @example
79
- * Most basic rule:
80
- * ```ts
81
- * { basic: 'content' }
82
- * ```
83
- *
84
- * Rule with dynamic content:
85
- * ```ts
86
- * { basic: () => `${new Date().toISOString()}` }
87
- * ```
88
- *
89
- * Rule with metadata:
90
- * ```ts
91
- * { basic-meta: { required: true, content: 'content'} }
92
- * ```
93
- *
94
- * Rule with dynamic content and metadata:
95
- * { basic-date: { required: true, content: () => `${new Date().toISOString()}` } }
96
- */
97
- export type Rules = SimplifyDeep<Record<string, Rule>>;
98
- export type NormalizedRules = SimplifyDeep<Record<string, NormalizedRule>>;
99
- export declare function normalizeRules(rules: Rules): NormalizedRules;
100
- export declare function validateRules(rules: Rules): void;
101
- export declare const rulesSchema: z.ZodRecord<z.ZodString, z.ZodType<any, z.ZodTypeDef, any>>;
102
- export declare const normalizedRulesSchema: z.ZodRecord<z.ZodString, z.ZodType<any, z.ZodTypeDef, any>>;
103
- export declare function getRuleContent(rule: NormalizedRule, options: JsonValue, tree: Root, check?: boolean): Promise<string>;
104
- /**
105
- * Returns the rule value from a single-rule record.
106
- * Useful when aliasing rules or invoking them programmatically.
107
- *
108
- * Throws if there are no entries or more than one entry.
109
- */
110
- export declare function getSoleRule<T extends NormalizedRules | Rules>(rules: T): T[keyof T];
111
- /**
112
- * Returns the rule key from a single-rule record.
113
- * Useful for comment placeholder validation.
114
- *
115
- * Throws if there are no entries or more than one entry.
116
- */
117
- export declare function getSoleRuleKey<T extends NormalizedRules | Rules>(rules: T): keyof T;
@@ -1,29 +0,0 @@
1
- import type { Root } from 'mdast';
2
- import type { Plugin } from 'unified';
3
- import { z } from 'zod';
4
- import { type Options as MdatOptions } from './mdast-utils/mdast-util-mdat';
5
- export type Options = Partial<MdatOptions>;
6
- export declare const optionsSchema: z.ZodObject<{
7
- addMetaComment: z.ZodOptional<z.ZodBoolean>;
8
- closingPrefix: z.ZodOptional<z.ZodString>;
9
- keywordPrefix: z.ZodOptional<z.ZodString>;
10
- metaCommentIdentifier: z.ZodOptional<z.ZodString>;
11
- rules: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<any, z.ZodTypeDef, any>>>;
12
- }, "strip", z.ZodTypeAny, {
13
- closingPrefix?: string | undefined;
14
- keywordPrefix?: string | undefined;
15
- metaCommentIdentifier?: string | undefined;
16
- rules?: Record<string, any> | undefined;
17
- addMetaComment?: boolean | undefined;
18
- }, {
19
- closingPrefix?: string | undefined;
20
- keywordPrefix?: string | undefined;
21
- metaCommentIdentifier?: string | undefined;
22
- rules?: Record<string, any> | undefined;
23
- addMetaComment?: boolean | undefined;
24
- }>;
25
- /**
26
- * A remark plugin that expands HTML comments in Markdown files.
27
- */
28
- declare const remarkMdat: Plugin<[Options], Root>;
29
- export default remarkMdat;