UNPKG

8.41 kBTypeScriptView Raw
1import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
2import { Contents } from '@jupyterlab/services';
3import { ITranslator } from '@jupyterlab/translation';
4import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
5import { MimeModel } from './mimemodel';
6import { IRenderMimeRegistry } from './tokens';
7/**
8 * An object which manages mime renderer factories.
9 *
10 * This object is used to render mime models using registered mime
11 * renderers, selecting the preferred mime renderer to render the
12 * model into a widget.
13 *
14 * #### Notes
15 * This class is not intended to be subclassed.
16 */
17export declare class RenderMimeRegistry implements IRenderMimeRegistry {
18 /**
19 * Construct a new rendermime.
20 *
21 * @param options - The options for initializing the instance.
22 */
23 constructor(options?: RenderMimeRegistry.IOptions);
24 /**
25 * The sanitizer used by the rendermime instance.
26 */
27 readonly sanitizer: IRenderMime.ISanitizer;
28 /**
29 * The object used to resolve relative urls for the rendermime instance.
30 */
31 readonly resolver: IRenderMime.IResolver | null;
32 /**
33 * The object used to handle path opening links.
34 */
35 readonly linkHandler: IRenderMime.ILinkHandler | null;
36 /**
37 * The LaTeX typesetter for the rendermime.
38 */
39 readonly latexTypesetter: IRenderMime.ILatexTypesetter | null;
40 /**
41 * The Markdown parser for the rendermime.
42 */
43 readonly markdownParser: IRenderMime.IMarkdownParser | null;
44 /**
45 * The application language translator.
46 */
47 readonly translator: ITranslator;
48 /**
49 * The ordered list of mimeTypes.
50 */
51 get mimeTypes(): ReadonlyArray<string>;
52 /**
53 * Find the preferred mime type for a mime bundle.
54 *
55 * @param bundle - The bundle of mime data.
56 *
57 * @param safe - How to consider safe/unsafe factories. If 'ensure',
58 * it will only consider safe factories. If 'any', any factory will be
59 * considered. If 'prefer', unsafe factories will be considered, but
60 * only after the safe options have been exhausted.
61 *
62 * @returns The preferred mime type from the available factories,
63 * or `undefined` if the mime type cannot be rendered.
64 */
65 preferredMimeType(bundle: ReadonlyPartialJSONObject, safe?: 'ensure' | 'prefer' | 'any'): string | undefined;
66 /**
67 * Create a renderer for a mime type.
68 *
69 * @param mimeType - The mime type of interest.
70 *
71 * @returns A new renderer for the given mime type.
72 *
73 * @throws An error if no factory exists for the mime type.
74 */
75 createRenderer(mimeType: string): IRenderMime.IRenderer;
76 /**
77 * Create a new mime model. This is a convenience method.
78 *
79 * @options - The options used to create the model.
80 *
81 * @returns A new mime model.
82 */
83 createModel(options?: MimeModel.IOptions): MimeModel;
84 /**
85 * Create a clone of this rendermime instance.
86 *
87 * @param options - The options for configuring the clone.
88 *
89 * @returns A new independent clone of the rendermime.
90 */
91 clone(options?: IRenderMimeRegistry.ICloneOptions): RenderMimeRegistry;
92 /**
93 * Get the renderer factory registered for a mime type.
94 *
95 * @param mimeType - The mime type of interest.
96 *
97 * @returns The factory for the mime type, or `undefined`.
98 */
99 getFactory(mimeType: string): IRenderMime.IRendererFactory | undefined;
100 /**
101 * Add a renderer factory to the rendermime.
102 *
103 * @param factory - The renderer factory of interest.
104 *
105 * @param rank - The rank of the renderer. A lower rank indicates
106 * a higher priority for rendering. If not given, the rank will
107 * defer to the `defaultRank` of the factory. If no `defaultRank`
108 * is given, it will default to 100.
109 *
110 * #### Notes
111 * The renderer will replace an existing renderer for the given
112 * mimeType.
113 */
114 addFactory(factory: IRenderMime.IRendererFactory, rank?: number): void;
115 /**
116 * Remove a mime type.
117 *
118 * @param mimeType - The mime type of interest.
119 */
120 removeMimeType(mimeType: string): void;
121 /**
122 * Get the rank for a given mime type.
123 *
124 * @param mimeType - The mime type of interest.
125 *
126 * @returns The rank of the mime type or undefined.
127 */
128 getRank(mimeType: string): number | undefined;
129 /**
130 * Set the rank of a given mime type.
131 *
132 * @param mimeType - The mime type of interest.
133 *
134 * @param rank - The new rank to assign.
135 *
136 * #### Notes
137 * This is a no-op if the mime type is not registered.
138 */
139 setRank(mimeType: string, rank: number): void;
140 private _id;
141 private _ranks;
142 private _types;
143 private _factories;
144}
145/**
146 * The namespace for `RenderMimeRegistry` class statics.
147 */
148export declare namespace RenderMimeRegistry {
149 /**
150 * The options used to initialize a rendermime instance.
151 */
152 interface IOptions {
153 /**
154 * Initial factories to add to the rendermime instance.
155 */
156 initialFactories?: ReadonlyArray<IRenderMime.IRendererFactory>;
157 /**
158 * The sanitizer used to sanitize untrusted html inputs.
159 *
160 * If not given, a default sanitizer will be used.
161 */
162 sanitizer?: IRenderMime.ISanitizer;
163 /**
164 * The initial resolver object.
165 *
166 * The default is `null`.
167 */
168 resolver?: IRenderMime.IResolver;
169 /**
170 * An optional path handler.
171 */
172 linkHandler?: IRenderMime.ILinkHandler;
173 /**
174 * An optional LaTeX typesetter.
175 */
176 latexTypesetter?: IRenderMime.ILatexTypesetter;
177 /**
178 * An optional Markdown parser.
179 */
180 markdownParser?: IRenderMime.IMarkdownParser;
181 /**
182 * The application language translator.
183 */
184 translator?: ITranslator;
185 }
186 /**
187 * A default resolver that uses a given reference path and a contents manager.
188 */
189 class UrlResolver implements IRenderMime.IResolver {
190 /**
191 * Create a new url resolver.
192 */
193 constructor(options: IUrlResolverOptions);
194 /**
195 * The path of the object, from which local urls can be derived.
196 */
197 get path(): string;
198 set path(value: string);
199 /**
200 * Resolve a relative url to an absolute url path.
201 */
202 resolveUrl(url: string): Promise<string>;
203 /**
204 * Get the download url of a given absolute url path.
205 *
206 * #### Notes
207 * The returned URL may include a query parameter.
208 */
209 getDownloadUrl(urlPath: string): Promise<string>;
210 /**
211 * Whether the URL should be handled by the resolver
212 * or not.
213 *
214 * @param allowRoot - Whether the paths starting at Unix-style filesystem root (`/`) are permitted.
215 *
216 * #### Notes
217 * This is similar to the `isLocal` check in `URLExt`,
218 * but it also checks whether the path points to any
219 * of the `IDrive`s that may be registered with the contents
220 * manager.
221 */
222 isLocal(url: string, allowRoot?: boolean): boolean;
223 /**
224 * Resolve a path from Jupyter kernel to a path:
225 * - relative to `root_dir` (preferably) this is in jupyter-server scope,
226 * - path understood and known by kernel (if such a path exists).
227 * Returns `null` if there is no file matching provided path in neither
228 * kernel nor jupyter-server contents manager.
229 */
230 resolvePath(path: string): Promise<IRenderMime.IResolvedLocation | null>;
231 /**
232 * Whether the URL can be decoded using `decodeURI`.
233 */
234 isMalformed(url: string): boolean;
235 private _path;
236 private _contents;
237 }
238 /**
239 * The options used to create a UrlResolver.
240 */
241 interface IUrlResolverOptions {
242 /**
243 * The path providing context for local urls.
244 *
245 * #### Notes
246 * Either session or path must be given, and path takes precedence.
247 */
248 path: string;
249 /**
250 * The contents manager used by the resolver.
251 */
252 contents: Contents.IManager;
253 }
254}