@canofold/markdown 0.2.1 → 0.3.1
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/dist/{Markdown-DgolXL7g.js → Markdown-CPG2lcO7.js} +223 -212
- package/dist/base.css +1 -1
- package/dist/client/chunks/{client-kVNIqHQd.js → client-CTpZrdpv.js} +2 -2
- package/dist/client/chunks/{image-BuMCsr5L.js → image-BsfZtDsx.js} +1 -1
- package/dist/client/chunks/{serialized-T1PzI4rG.js → serialized-Ck9NBdg7.js} +129 -118
- package/dist/client/chunks/{table-JOSJsHgy.js → table-jaJMPch3.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/compiler/analyze.d.ts +11 -0
- package/dist/compiler/fenceMetadata.d.ts +7 -0
- package/dist/compiler/normalizeOptions.d.ts +2 -1
- package/dist/compiler/plugins/code.d.ts +1 -1
- package/dist/compiler/plugins.d.ts +2 -0
- package/dist/compiler/prepareMarkdown.d.ts +1 -1
- package/dist/compiler/types.d.ts +9 -0
- package/dist/components/blocks/MarkdownCodeBlock.d.ts +3 -1
- package/dist/{directiveValidation-CwXRsn5k.js → directiveValidation-BdVbgcY_.js} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/{plugins-CeQ-Bo89.js → plugins-StkCS2su.js} +18 -8
- package/dist/{prepareMarkdown-Bug1ncYk.js → prepareMarkdown-DPMq7203.js} +221 -203
- package/dist/server/analyze.d.ts +1 -1
- package/dist/server/analyze.js +104 -86
- package/dist/server.js +60 -55
- package/package.json +2 -2
|
@@ -10,6 +10,16 @@ export interface MarkdownCodeExample {
|
|
|
10
10
|
meta?: string;
|
|
11
11
|
code: string;
|
|
12
12
|
}
|
|
13
|
+
export interface MarkdownDirective {
|
|
14
|
+
name: string;
|
|
15
|
+
type: 'containerDirective' | 'leafDirective' | 'textDirective';
|
|
16
|
+
label: string;
|
|
17
|
+
attributes: Record<string, string>;
|
|
18
|
+
line?: number;
|
|
19
|
+
column?: number;
|
|
20
|
+
offset?: number;
|
|
21
|
+
endOffset?: number;
|
|
22
|
+
}
|
|
13
23
|
export interface MarkdownAnalysis {
|
|
14
24
|
text: string;
|
|
15
25
|
headings: MarkdownHeading[];
|
|
@@ -17,6 +27,7 @@ export interface MarkdownAnalysis {
|
|
|
17
27
|
links: string[];
|
|
18
28
|
images: string[];
|
|
19
29
|
missingCodeBlockLanguages: number;
|
|
30
|
+
directives: MarkdownDirective[];
|
|
20
31
|
directiveIssues: MarkdownDirectiveIssue[];
|
|
21
32
|
}
|
|
22
33
|
export interface AnalyzeMarkdownOptions {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MarkdownCodeOverflow } from './types';
|
|
2
|
+
export interface MarkdownFenceMetadata {
|
|
3
|
+
filename?: string;
|
|
4
|
+
overflow?: MarkdownCodeOverflow;
|
|
5
|
+
}
|
|
6
|
+
/** Parse the shared metadata understood by Markdown and MDX code fences. */
|
|
7
|
+
export declare function parseFenceMetadata(meta: string): MarkdownFenceMetadata;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LanguageInput, ThemeRegistration } from '@shikijs/types';
|
|
2
|
-
import type { MarkdownFeatureOptions, MarkdownHtmlPolicy, MarkdownLabels, MarkdownPlugin, MarkdownUnknownLanguagePolicy, RenderMarkdownOptions } from './types';
|
|
2
|
+
import type { MarkdownFeatureOptions, MarkdownHtmlPolicy, MarkdownLabels, MarkdownCodeOverflow, MarkdownPlugin, MarkdownUnknownLanguagePolicy, RenderMarkdownOptions } from './types';
|
|
3
3
|
export interface NormalizedMarkdownOptions {
|
|
4
4
|
htmlPolicy: MarkdownHtmlPolicy;
|
|
5
5
|
codeThemes: {
|
|
@@ -7,6 +7,7 @@ export interface NormalizedMarkdownOptions {
|
|
|
7
7
|
dark: string | ThemeRegistration;
|
|
8
8
|
};
|
|
9
9
|
fallbackLanguage: string;
|
|
10
|
+
codeOverflow: MarkdownCodeOverflow;
|
|
10
11
|
codeLanguages: Readonly<Record<string, LanguageInput>>;
|
|
11
12
|
unknownLanguage: MarkdownUnknownLanguagePolicy;
|
|
12
13
|
features: Required<MarkdownFeatureOptions>;
|
|
@@ -13,4 +13,4 @@ export declare const rehypeRichFences: (assets: MarkdownAssetCollector, options:
|
|
|
13
13
|
/** Convert rich fences into React components for the MDX recma pipeline. */
|
|
14
14
|
export declare const remarkMdxRichBlocks: (assets: MarkdownAssetCollector, options: NormalizedMarkdownOptions) => (tree: MdastRoot) => void;
|
|
15
15
|
/** Wrap each highlighted code block with a file/language label and copy action. */
|
|
16
|
-
export declare const rehypeCodeBlocks: (assets: MarkdownAssetCollector,
|
|
16
|
+
export declare const rehypeCodeBlocks: (assets: MarkdownAssetCollector, options: Pick<NormalizedMarkdownOptions, "labels" | "codeOverflow">, excludedLanguages?: ReadonlySet<string>) => (tree: HastRoot) => void;
|
|
@@ -20,5 +20,7 @@ export declare function defineMarkdownPlugin(plugin: MarkdownPlugin): MarkdownPl
|
|
|
20
20
|
export declare function activeMarkdownPlugins(plugins: readonly MarkdownPlugin[], context: MarkdownPluginContext): readonly MarkdownPlugin[];
|
|
21
21
|
/** Collect normalized fenced-code labels owned by the active plugins. */
|
|
22
22
|
export declare function markdownPluginFenceLanguages(plugins: readonly MarkdownPlugin[]): ReadonlySet<string>;
|
|
23
|
+
/** Collect code languages generated by active plugin transforms. */
|
|
24
|
+
export declare function markdownPluginHighlightLanguages(plugins: readonly MarkdownPlugin[]): readonly string[];
|
|
23
25
|
/** Collect normalized directive names owned by the active plugins. */
|
|
24
26
|
export declare function markdownPluginDirectiveNames(plugins: readonly MarkdownPlugin[]): ReadonlySet<string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { PreparedMarkdown, RenderMarkdownOptions } from './types';
|
|
2
2
|
export type { MarkdownAssets } from './assets';
|
|
3
|
-
export type { MarkdownCodeOptions, MarkdownFeatureOptions, MarkdownHtmlPolicy, MarkdownLabels, MarkdownPlugin, MarkdownPluginBrowserCompiler, MarkdownPluginCacheValue, MarkdownPluginClientAsset, MarkdownPluginClientResource, MarkdownPluginClientResourceDirectory, MarkdownPluginContext, MarkdownPluginStyleAsset, MarkdownUnknownLanguagePolicy, RenderMarkdownOptions } from './types';
|
|
3
|
+
export type { MarkdownCodeOverflow, MarkdownCodeOptions, MarkdownFeatureOptions, MarkdownHtmlPolicy, MarkdownLabels, MarkdownPlugin, MarkdownPluginBrowserCompiler, MarkdownPluginCacheValue, MarkdownPluginClientAsset, MarkdownPluginClientResource, MarkdownPluginClientResourceDirectory, MarkdownPluginContext, MarkdownPluginStyleAsset, MarkdownUnknownLanguagePolicy, RenderMarkdownOptions } from './types';
|
|
4
4
|
export interface MarkdownCompilerContext {
|
|
5
5
|
warnedLanguages: Set<string>;
|
|
6
6
|
}
|
package/dist/compiler/types.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type { LanguageInput } from '@shikijs/types';
|
|
|
4
4
|
import type { PluggableList } from 'unified';
|
|
5
5
|
export type MarkdownHtmlPolicy = 'trusted' | 'sanitize' | 'strip';
|
|
6
6
|
export type MarkdownUnknownLanguagePolicy = 'warn' | 'error' | 'plain-text';
|
|
7
|
+
export type MarkdownCodeOverflow = 'wrap' | 'scroll';
|
|
7
8
|
export type MarkdownPluginCacheValue = string | number | boolean | null | MarkdownPluginCacheValue[] | {
|
|
8
9
|
[key: string]: MarkdownPluginCacheValue;
|
|
9
10
|
};
|
|
@@ -21,6 +22,8 @@ export interface MarkdownCodeOptions {
|
|
|
21
22
|
dark?: string;
|
|
22
23
|
};
|
|
23
24
|
fallbackLanguage?: string;
|
|
25
|
+
/** Default long-line behavior. Individual fences may override it with `wrap` or `scroll` metadata. */
|
|
26
|
+
overflow?: MarkdownCodeOverflow;
|
|
24
27
|
/**
|
|
25
28
|
* Additional fence-language loaders keyed by the label authors use after
|
|
26
29
|
* the opening fence. Built-in technical-document languages remain enabled.
|
|
@@ -99,6 +102,12 @@ export interface MarkdownPlugin {
|
|
|
99
102
|
* fences as ordinary code or reporting them as unsupported languages.
|
|
100
103
|
*/
|
|
101
104
|
fenceLanguages?: readonly string[];
|
|
105
|
+
/**
|
|
106
|
+
* Code languages introduced by this plugin's transforms. The compiler loads
|
|
107
|
+
* these grammars before the plugin runs so generated code blocks use the
|
|
108
|
+
* same Shiki pipeline as authored Markdown fences.
|
|
109
|
+
*/
|
|
110
|
+
highlightLanguages?: readonly string[];
|
|
102
111
|
/**
|
|
103
112
|
* Directive names owned by this plugin. Undeclared directive names are
|
|
104
113
|
* rejected so author typos cannot silently degrade to generic HTML.
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
import type { MarkdownCodeOverflow } from '../../compiler/types';
|
|
2
3
|
export interface MarkdownCodeBlockProps extends Omit<HTMLAttributes<HTMLElement>, 'children'> {
|
|
3
4
|
children?: ReactNode;
|
|
4
5
|
language?: string;
|
|
5
6
|
filename?: string;
|
|
7
|
+
overflow?: MarkdownCodeOverflow;
|
|
6
8
|
source?: string;
|
|
7
9
|
copyLabel?: string;
|
|
8
10
|
copyFailureLabel?: string;
|
|
9
11
|
}
|
|
10
|
-
export declare function MarkdownCodeBlock({ children, source: directSource, language: directLanguage, filename: directFilename, copyLabel: directCopyLabel, copyFailureLabel: directCopyFailureLabel, ...inputProps }: MarkdownCodeBlockProps): import("react").JSX.Element;
|
|
12
|
+
export declare function MarkdownCodeBlock({ children, source: directSource, language: directLanguage, filename: directFilename, overflow: directOverflow, copyLabel: directCopyLabel, copyFailureLabel: directCopyFailureLabel, ...inputProps }: MarkdownCodeBlockProps): import("react").JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,4 @@ export type { MarkdownClassNames, MarkdownComponents, MarkdownIntrinsicComponent
|
|
|
4
4
|
export type { MarkdownCaptionSlotProps, MarkdownIconName, MarkdownIconSlotProps, MarkdownSlots } from './react/slots';
|
|
5
5
|
export type { MarkdownUrlProperty, MarkdownUrlTransform } from './react/urlTransform';
|
|
6
6
|
export { defineMarkdownPlugin } from './compiler/plugins';
|
|
7
|
-
export type { MarkdownCodeOptions, MarkdownFeatureOptions, MarkdownHtmlPolicy, MarkdownLabels, MarkdownPlugin, MarkdownPluginBrowserCompiler, MarkdownPluginCacheValue, MarkdownPluginClientAsset, MarkdownPluginClientResource, MarkdownPluginClientResourceDirectory, MarkdownPluginContext, MarkdownPluginStyleAsset, MarkdownUnknownLanguagePolicy, RenderMarkdownOptions } from './compiler/prepareMarkdown';
|
|
7
|
+
export type { MarkdownCodeOverflow, MarkdownCodeOptions, MarkdownFeatureOptions, MarkdownHtmlPolicy, MarkdownLabels, MarkdownPlugin, MarkdownPluginBrowserCompiler, MarkdownPluginCacheValue, MarkdownPluginClientAsset, MarkdownPluginClientResource, MarkdownPluginClientResourceDirectory, MarkdownPluginContext, MarkdownPluginStyleAsset, MarkdownUnknownLanguagePolicy, RenderMarkdownOptions } from './compiler/prepareMarkdown';
|
package/dist/index.js
CHANGED
|
@@ -93,7 +93,7 @@ const w = {
|
|
|
93
93
|
rust: "source",
|
|
94
94
|
rs: "source"
|
|
95
95
|
};
|
|
96
|
-
function
|
|
96
|
+
function h(e, t = "") {
|
|
97
97
|
const r = e.split(/[\\/]/).pop()?.toLowerCase() || "", n = w[r];
|
|
98
98
|
if (n) return n;
|
|
99
99
|
if (/^\.env(?:\..+)?$/.test(r)) return "environment";
|
|
@@ -155,7 +155,7 @@ function j(e, t = "") {
|
|
|
155
155
|
if (/^\.env(?:\.|$)/.test(n)) return "environment";
|
|
156
156
|
if (n === "tsconfig.json" || n === "jsconfig.json") return "typescript";
|
|
157
157
|
if (/\.(?:jsx|tsx)$/.test(n)) return "react";
|
|
158
|
-
const o =
|
|
158
|
+
const o = h(n, t);
|
|
159
159
|
if (o === "config") return "config";
|
|
160
160
|
if (o === "database") return "database";
|
|
161
161
|
if (o === "diff") return "diff";
|
|
@@ -193,7 +193,7 @@ function p(e) {
|
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
const m = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,
|
|
196
|
+
const m = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/, b = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
197
197
|
function d(e) {
|
|
198
198
|
if (typeof e != "string" || !m.test(e))
|
|
199
199
|
throw new Error(
|
|
@@ -209,7 +209,7 @@ function g(e) {
|
|
|
209
209
|
if (t) {
|
|
210
210
|
if (typeof t.module != "string" || t.module.trim() === "")
|
|
211
211
|
throw new Error(`Markdown plugin "${e.name}" browserCompiler.module must be a non-empty string`);
|
|
212
|
-
if (typeof t.exportName != "string" || !
|
|
212
|
+
if (typeof t.exportName != "string" || !b.test(t.exportName))
|
|
213
213
|
throw new Error(
|
|
214
214
|
`Markdown plugin "${e.name}" browserCompiler.exportName must be a named JavaScript export`
|
|
215
215
|
);
|
|
@@ -273,16 +273,26 @@ function z(e) {
|
|
|
273
273
|
return t;
|
|
274
274
|
}
|
|
275
275
|
function E(e) {
|
|
276
|
+
const t = /* @__PURE__ */ new Set();
|
|
277
|
+
for (const r of e)
|
|
278
|
+
for (const n of r.highlightLanguages ?? []) {
|
|
279
|
+
const o = n.trim().toLowerCase();
|
|
280
|
+
o && t.add(o);
|
|
281
|
+
}
|
|
282
|
+
return [...t];
|
|
283
|
+
}
|
|
284
|
+
function O(e) {
|
|
276
285
|
return new Set(e.flatMap((t) => f(t)));
|
|
277
286
|
}
|
|
278
287
|
export {
|
|
279
288
|
x as a,
|
|
280
289
|
z as b,
|
|
281
|
-
|
|
290
|
+
E as c,
|
|
282
291
|
N as d,
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
292
|
+
v as e,
|
|
293
|
+
h as f,
|
|
294
|
+
j as g,
|
|
295
|
+
O as m,
|
|
286
296
|
$ as n,
|
|
287
297
|
p as s
|
|
288
298
|
};
|