upkram 1.0.5 → 1.0.7

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/upkram-ni.mjs CHANGED
@@ -7,5 +7,6 @@ export const {
7
7
  renderMarkdown, renderMarkdownWithMeta, parseToAst, tokenizeInline,
8
8
  validate, validateSecurity, lintMarkdown, lintRules,
9
9
  countWords, markdownToPlainText, initScrollFade,
10
- usePlugin, listPlugins
10
+ usePlugin, listPlugins, pluginErrors, clearPluginErrors,
11
+ registerLintRule, unregisterLintRule, listLintRules, VERSION
11
12
  } = api;
package/upkram.d.ts CHANGED
@@ -86,6 +86,37 @@ export interface LintDiagnostic {
86
86
  export interface LintRuleMeta {
87
87
  severity: LintSeverity;
88
88
  message: string;
89
+ /** Human-readable explanation of when the rule fires and how to fix it. */
90
+ description?: string;
91
+ /** Whether the rule ships an auto-fix hint (currently informational only). */
92
+ fixable?: boolean;
93
+ /** True for rules added at runtime through `registerLintRule`. */
94
+ custom?: boolean;
95
+ /** Rule id, present on entries returned by `listLintRules()`. */
96
+ id?: string;
97
+ }
98
+
99
+ /** Signature of a custom lint rule body passed to `registerLintRule`. */
100
+ export type LintRuleCheck = (
101
+ ast: AstNode,
102
+ source: string,
103
+ report: (position: SourcePosition | null, data?: Record<string, unknown>, extra?: Record<string, unknown>) => void
104
+ ) => void;
105
+
106
+ /** A plugin hook or renderer threw; captured instead of breaking rendering. */
107
+ export interface PluginError {
108
+ plugin: string;
109
+ hook: string;
110
+ error: string;
111
+ }
112
+
113
+ /** Descriptor returned by `listPlugins(true)`. */
114
+ export interface PluginInfo {
115
+ name: string;
116
+ renderers: string[];
117
+ before: boolean;
118
+ after: boolean;
119
+ config: Config | null;
89
120
  }
90
121
 
91
122
  export interface LintOptions {
@@ -108,6 +139,9 @@ export interface MetaResult {
108
139
  meta: Record<string, unknown>;
109
140
  }
110
141
 
142
+ /** Engine version, e.g. `"1.0.7"`. Mirrors `package.json` `version`. */
143
+ export const VERSION: string;
144
+
111
145
  /** Render Markdown to HTML (SSR / no-interaction build). */
112
146
  export function renderMarkdown(markdown: string, options?: RenderOptions): string;
113
147
  /** Render Markdown and collect `:::meta` metadata. */
@@ -128,8 +162,28 @@ export function markdownToPlainText(markdown: string): string;
128
162
  export function lintMarkdown(markdown: string, options?: RenderOptions, lintOptions?: LintOptions): LintDiagnostic[];
129
163
  /** Register a plugin; returns a disposer that unregisters it. */
130
164
  export function usePlugin(plugin: Plugin): () => void;
131
- /** Names of currently registered plugins. */
165
+ /** Names of currently registered plugins (pass `true` for full descriptors). */
132
166
  export function listPlugins(): string[];
167
+ export function listPlugins(details: true): PluginInfo[];
168
+ export function listPlugins(details?: boolean): string[] | PluginInfo[];
169
+ /** Plugin hook/renderer errors captured during rendering (newest last). */
170
+ export function pluginErrors(): PluginError[];
171
+ /** Clear the captured plugin error list. */
172
+ export function clearPluginErrors(): void;
173
+ /**
174
+ * Register a custom lint rule. `check` receives the parsed AST, the normalised
175
+ * source and a `report(position, data, extra)` callback. Returns a disposer.
176
+ * @throws TypeError when `id` or `check` is invalid.
177
+ */
178
+ export function registerLintRule(
179
+ id: string,
180
+ meta: Omit<LintRuleMeta, 'custom' | 'id'>,
181
+ check: LintRuleCheck
182
+ ): () => void;
183
+ /** Remove a custom lint rule. Returns whether it existed. */
184
+ export function unregisterLintRule(id: string): boolean;
185
+ /** All registered rules (built-in + custom) with metadata. */
186
+ export function listLintRules(): Record<string, LintRuleMeta>;
133
187
  /** Scroll-fade initialiser (browser only; no-op in SSR). */
134
188
  export function initScrollFade(root?: Element | Document | null): void;
135
189
 
@@ -146,6 +200,7 @@ export function initMermaid(...args: unknown[]): unknown;
146
200
  export function simpleHtmlToMarkdown(html: string): string;
147
201
 
148
202
  declare const api: {
203
+ VERSION: typeof VERSION;
149
204
  renderMarkdown: typeof renderMarkdown;
150
205
  renderMarkdownWithMeta: typeof renderMarkdownWithMeta;
151
206
  parseToAst: typeof parseToAst;
@@ -156,8 +211,13 @@ declare const api: {
156
211
  markdownToPlainText: typeof markdownToPlainText;
157
212
  lintMarkdown: typeof lintMarkdown;
158
213
  lintRules: typeof lintRules;
214
+ registerLintRule: typeof registerLintRule;
215
+ unregisterLintRule: typeof unregisterLintRule;
216
+ listLintRules: typeof listLintRules;
159
217
  usePlugin: typeof usePlugin;
160
218
  listPlugins: typeof listPlugins;
219
+ pluginErrors: typeof pluginErrors;
220
+ clearPluginErrors: typeof clearPluginErrors;
161
221
  initScrollFade: typeof initScrollFade;
162
222
  mountMarkdown?: typeof mountMarkdown;
163
223
  openLightbox?: typeof openLightbox;
package/upkram.mjs CHANGED
@@ -7,5 +7,6 @@ export const {
7
7
  renderMarkdown, renderMarkdownWithMeta, parseToAst, tokenizeInline,
8
8
  validate, validateSecurity, lintMarkdown, lintRules,
9
9
  countWords, markdownToPlainText, initScrollFade,
10
- usePlugin, listPlugins
10
+ usePlugin, listPlugins, pluginErrors, clearPluginErrors,
11
+ registerLintRule, unregisterLintRule, listLintRules, VERSION
11
12
  } = api;