@vectojs/markdown 0.18.2 → 0.19.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/dist/Markdown.d.ts +48 -3
- package/dist/blockAffordances.d.ts +60 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +562 -61
- package/dist/index.mjs +560 -61
- package/dist/markdown-code.d.ts +136 -5
- package/dist/theme.d.ts +21 -0
- package/package.json +2 -2
package/dist/Markdown.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { Entity, type DevtoolsDescriptor, IRenderer } from '@vectojs/core';
|
|
|
2
2
|
import { type Token } from 'marked';
|
|
3
3
|
import { type StreamController, type StreamControllerOptions } from './StreamController';
|
|
4
4
|
export { isMathJaxReady, MathBlock, preloadMathJax } from './markdown-math';
|
|
5
|
-
export { CodeBlock, codeAtlas, codeAtlasStats } from './markdown-code';
|
|
5
|
+
export { CodeBlock, codeAtlas, codeAtlasStats, highlightedLanguages } from './markdown-code';
|
|
6
|
+
export type { CodeBlockOptions } from './markdown-code';
|
|
6
7
|
import { type MarkdownThemePresetName } from './markdown-presets';
|
|
7
8
|
import { type MarkdownTheme } from './theme';
|
|
8
9
|
export type { MarkdownTheme } from './theme';
|
|
@@ -11,6 +12,7 @@ export { isPresetName, PRESET_THEMES, resolvePresetTheme } from './markdown-pres
|
|
|
11
12
|
export { registerFencedBlockRenderer, unregisterFencedBlockRenderer, hasFencedBlockRenderer, isFencedBlockRendererReady, ensureFencedBlockRenderer, renderFencedBlock, } from './markdown-fenced-registry';
|
|
12
13
|
export type { FencedBlockRenderer, FencedBlockRendererSpec, FencedBlockRenderOptions, } from './markdown-fenced-registry';
|
|
13
14
|
import { Stack, UIComponent } from '@vectojs/ui';
|
|
15
|
+
import { type BlockAffordanceConfig, type ResolvedBlockAffordanceConfig } from './blockAffordances';
|
|
14
16
|
export interface MarkdownOptions {
|
|
15
17
|
maxWidth?: number;
|
|
16
18
|
/**
|
|
@@ -37,6 +39,33 @@ export interface MarkdownOptions {
|
|
|
37
39
|
* offered one.
|
|
38
40
|
*/
|
|
39
41
|
blockAffordances?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Which affordance controls a block gets, and what they are called.
|
|
44
|
+
*
|
|
45
|
+
* Defaults to copy + download on both code blocks and tables, i.e. exactly what
|
|
46
|
+
* `blockAffordances: true` produced before this existed. Set it to narrow the
|
|
47
|
+
* set (`{ download: false }` for copy-only blocks) or to relabel a control for a
|
|
48
|
+
* non-English document — the labels are user-visible text and are also what a
|
|
49
|
+
* screen reader announces, so they cannot stay hardcoded English.
|
|
50
|
+
*
|
|
51
|
+
* Separate from {@link blockAffordances} rather than folded into it, because the
|
|
52
|
+
* two answer different questions: whether a reader is offered controls at all,
|
|
53
|
+
* and which ones. Keeping the boolean means the common case stays a boolean.
|
|
54
|
+
*/
|
|
55
|
+
affordances?: BlockAffordanceConfig;
|
|
56
|
+
/**
|
|
57
|
+
* Show the fence's language in a header band at the top-left of each code
|
|
58
|
+
* block. Default `false`.
|
|
59
|
+
*
|
|
60
|
+
* Worth turning on for a document that mixes languages, where the label tells a
|
|
61
|
+
* reader what they are looking at. A single-language page gets the same word
|
|
62
|
+
* repeated down its length, which is why it is opt-in.
|
|
63
|
+
*
|
|
64
|
+
* It also reserves vertical space at the top of the block, which is what stops
|
|
65
|
+
* {@link blockAffordances} controls from overlapping the first line of code —
|
|
66
|
+
* so a document using both wants this on.
|
|
67
|
+
*/
|
|
68
|
+
showCodeLanguage?: boolean;
|
|
40
69
|
/**
|
|
41
70
|
* Writes text to the clipboard for the copy controls.
|
|
42
71
|
*
|
|
@@ -88,6 +117,22 @@ export declare class Markdown extends UIComponent {
|
|
|
88
117
|
* affordance.
|
|
89
118
|
*/
|
|
90
119
|
blockAffordances: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Which controls a block carries and what they are called, with defaults
|
|
122
|
+
* applied.
|
|
123
|
+
*
|
|
124
|
+
* Resolved once in the constructor rather than per block: the defaults are
|
|
125
|
+
* fixed, and re-deriving them for every code fence in a long document would
|
|
126
|
+
* repeat the same six `??` fallbacks for no benefit.
|
|
127
|
+
*/
|
|
128
|
+
affordanceConfig: ResolvedBlockAffordanceConfig;
|
|
129
|
+
/**
|
|
130
|
+
* Whether code blocks show their language in a header band.
|
|
131
|
+
*
|
|
132
|
+
* Read when a block entity is built, exactly like {@link blockAffordances}, so
|
|
133
|
+
* it affects blocks rendered from here on rather than retroactively.
|
|
134
|
+
*/
|
|
135
|
+
showCodeLanguage: boolean;
|
|
91
136
|
/** Clipboard writer used by the copy controls. */
|
|
92
137
|
writeClipboard: (text: string) => void;
|
|
93
138
|
/** File saver used by the download controls. */
|
|
@@ -585,9 +630,9 @@ export declare class Markdown extends UIComponent {
|
|
|
585
630
|
* `BlockAffordanceButton` does in its constructor.
|
|
586
631
|
*/
|
|
587
632
|
private withBlockAffordances;
|
|
588
|
-
/** Copy and download controls for one fenced code block. */
|
|
633
|
+
/** Copy and download controls for one fenced code block, per {@link affordanceConfig}. */
|
|
589
634
|
private codeBlockAffordances;
|
|
590
|
-
/** Copy (as Markdown) and download (as CSV) controls for one table. */
|
|
635
|
+
/** Copy (as Markdown) and download (as CSV) controls for one table, per {@link affordanceConfig}. */
|
|
591
636
|
private tableAffordances;
|
|
592
637
|
/**
|
|
593
638
|
* Button styling for the affordances, derived from the document theme.
|
|
@@ -75,6 +75,66 @@ export declare function defaultWriteClipboard(text: string): void;
|
|
|
75
75
|
* {@link tableToCsv} instead — see there for why.
|
|
76
76
|
*/
|
|
77
77
|
export declare function defaultSaveFile(filename: string, content: string, mimeType: string): void;
|
|
78
|
+
/**
|
|
79
|
+
* Which take-away controls a block carries, and what they are called.
|
|
80
|
+
*
|
|
81
|
+
* Two separate axes, deliberately. WHICH controls appear is an interaction and
|
|
82
|
+
* accessibility decision — each one is a focus stop in every code block of the
|
|
83
|
+
* document, so a reader who only ever copies should be able to drop the download
|
|
84
|
+
* without also having to restate its label. WHAT they are called is a
|
|
85
|
+
* localization decision, and a consumer rendering a Chinese document needs the
|
|
86
|
+
* labels in Chinese regardless of which controls they kept.
|
|
87
|
+
*
|
|
88
|
+
* Every field is optional and every default matches the labels these controls
|
|
89
|
+
* shipped with, so an existing `blockAffordances: true` caller is unaffected.
|
|
90
|
+
*/
|
|
91
|
+
export interface BlockAffordanceConfig {
|
|
92
|
+
/**
|
|
93
|
+
* Show the copy-to-clipboard control. Default `true`.
|
|
94
|
+
*
|
|
95
|
+
* Copy rather than download is the one kept by default when a caller disables
|
|
96
|
+
* the other: it is the action a reader takes on a code snippet, and it needs no
|
|
97
|
+
* filesystem.
|
|
98
|
+
*/
|
|
99
|
+
copy?: boolean;
|
|
100
|
+
/** Show the download-as-file control. Default `true`. */
|
|
101
|
+
download?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Labels, for localization or for a house style that says "Copy" rather than
|
|
104
|
+
* "Copy code".
|
|
105
|
+
*
|
|
106
|
+
* The success labels are separate strings rather than derived, because no
|
|
107
|
+
* derivation survives translation: "Copied" is not a suffix or a tense rule
|
|
108
|
+
* that holds across languages.
|
|
109
|
+
*/
|
|
110
|
+
labels?: {
|
|
111
|
+
/** Resting label of the code-block copy control. Default `'Copy code'`. */
|
|
112
|
+
copyCode?: string;
|
|
113
|
+
/** Resting label of the code-block download control. Default `'Download code'`. */
|
|
114
|
+
downloadCode?: string;
|
|
115
|
+
/** Resting label of the table copy control. Default `'Copy table'`. */
|
|
116
|
+
copyTable?: string;
|
|
117
|
+
/** Resting label of the table download control. Default `'Download table'`. */
|
|
118
|
+
downloadTable?: string;
|
|
119
|
+
/** Confirmation shown after a successful copy. Default `'Copied'`. */
|
|
120
|
+
copied?: string;
|
|
121
|
+
/** Confirmation shown after a successful download. Default `'Saved'`. */
|
|
122
|
+
saved?: string;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** Resolved {@link BlockAffordanceConfig}, with every default applied. */
|
|
126
|
+
export interface ResolvedBlockAffordanceConfig {
|
|
127
|
+
copy: boolean;
|
|
128
|
+
download: boolean;
|
|
129
|
+
labels: Required<NonNullable<BlockAffordanceConfig['labels']>>;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Apply {@link BlockAffordanceConfig} defaults.
|
|
133
|
+
*
|
|
134
|
+
* Exported so a consumer building controls by hand resolves them the same way the
|
|
135
|
+
* document does, rather than re-deriving a second set of defaults that can drift.
|
|
136
|
+
*/
|
|
137
|
+
export declare function resolveBlockAffordanceConfig(config?: BlockAffordanceConfig): ResolvedBlockAffordanceConfig;
|
|
78
138
|
/**
|
|
79
139
|
* A copy or download control drawn in a block's top-right corner.
|
|
80
140
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './Markdown';
|
|
2
|
-
export { BlockAffordanceButton, BlockWithAffordances, escapeCsvField, escapeMarkdownTableCell, extensionForLanguage, mimeForLanguage, tableContentOf, tableToCsv, tableToMarkdown, } from './blockAffordances';
|
|
3
|
-
export type { TableAlign, TableContent } from './blockAffordances';
|
|
2
|
+
export { BlockAffordanceButton, BlockWithAffordances, escapeCsvField, escapeMarkdownTableCell, extensionForLanguage, mimeForLanguage, resolveBlockAffordanceConfig, tableContentOf, tableToCsv, tableToMarkdown, } from './blockAffordances';
|
|
3
|
+
export type { BlockAffordanceConfig, ResolvedBlockAffordanceConfig, TableAlign, TableContent, } from './blockAffordances';
|
|
4
4
|
export { footnoteMarker } from './markdown-footnote';
|
|
5
5
|
export type { FootnoteDefToken, FootnoteRefToken } from './markdown-footnote';
|
|
6
6
|
export { parseFrontMatterFields, scanFrontMatter } from './frontMatter';
|