Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Fetch the initial state of the settings.
settingRegistry
.load(plugin.id)
.then((settings: ISettingRegistry.ISettings) => {
settings.changed.connect(() => {
updateSettings(settings);
});
updateSettings(settings);
})
.catch((reason: Error) => {
console.error(reason.message);
});
// Register the MarkdownViewer factory.
const factory = new MarkdownViewerFactory({
rendermime,
name: FACTORY,
primaryFileType: docRegistry.getFileType('markdown'),
fileTypes: ['markdown'],
defaultRendered: ['markdown']
});
factory.widgetCreated.connect((sender, widget) => {
// Notify the instance tracker if restore data needs to update.
widget.context.pathChanged.connect(() => {
void tracker.save(widget);
});
// Handle the settings of new widgets.
updateWidget(widget.content);
void tracker.add(widget);
});
docRegistry.addWidgetFactory(factory);
restorer: ILayoutRestorer,
rendermime: IRenderMimeRegistry,
settingRegistry: ISettingRegistry
): IMarkdownViewerTracker {
const { commands, docRegistry } = app;
// Add the markdown renderer factory.
rendermime.addFactory(markdownRendererFactory);
const namespace = 'markdownviewer-widget';
const tracker = new InstanceTracker({
namespace
});
let config: Partial = {
...MarkdownViewer.defaultConfig
};
/**
* Update the settings of a widget.
*/
function updateWidget(widget: MarkdownViewer): void {
Object.keys(config).forEach((k: keyof MarkdownViewer.IConfig) => {
widget.setOption(k, config[k]);
});
}
/**
* Update the setting values.
*/
function updateSettings(settings: ISettingRegistry.ISettings) {
config = settings.composite as Partial;
it('should require a context parameter', () => {
let widget = new MarkdownViewer(context, RENDERMIME);
expect(widget).to.be.a(MarkdownViewer);
});
it('should be fulfilled when the widget is done rendering', () => {
let widget = new MarkdownViewer(context, RENDERMIME);
context.save();
return widget.ready.then(() => {
let layout = widget.layout as PanelLayout;
expect(layout.widgets.length).to.be(2);
});
});
it('should require a context parameter', () => {
let widgetFactory = new MarkdownViewerFactory({
name: 'markdown',
fileExtensions: ['.md'],
rendermime: RENDERMIME
});
expect(widgetFactory.createNew(context)).to.be.a(MarkdownViewer);
});