void/extensions/markdown-language-features/preview-src/settings.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2024-09-11 02:37:36 +00:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export interface PreviewSettings {
readonly source: string;
readonly line?: number;
readonly fragment?: string;
readonly selectedLine?: number;
readonly scrollPreviewWithEditor?: boolean;
readonly scrollEditorWithPreview: boolean;
readonly disableSecurityWarnings: boolean;
readonly doubleClickToSwitchToEditor: boolean;
readonly webviewResourceRoot: string;
}
2025-03-01 02:01:53 +00:00
export function getRawData(key: string): string {
2024-09-11 02:37:36 +00:00
const element = document.getElementById('vscode-markdown-preview-data');
if (element) {
const data = element.getAttribute(key);
if (data) {
2025-03-01 02:01:53 +00:00
return data;
2024-09-11 02:37:36 +00:00
}
}
throw new Error(`Could not load data for ${key}`);
}
2025-03-01 02:01:53 +00:00
export function getData<T = {}>(key: string): T {
return JSON.parse(getRawData(key));
}
2024-09-11 02:37:36 +00:00
export class SettingsManager {
private _settings: PreviewSettings = getData('data-settings');
public get settings(): PreviewSettings {
return this._settings;
}
public updateSettings(newSettings: PreviewSettings) {
this._settings = newSettings;
}
}