mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
Desktop: Fixed error when exporting certain notes that contain plugin content
This commit is contained in:
parent
0839b0314e
commit
f85db1496e
@ -1022,6 +1022,9 @@ packages/lib/services/plugins/defaultPlugins/desktopDefaultPluginsInfo.js
|
||||
packages/lib/services/plugins/reducer.js
|
||||
packages/lib/services/plugins/utils/createViewHandle.js
|
||||
packages/lib/services/plugins/utils/executeSandboxCall.js
|
||||
packages/lib/services/plugins/utils/getPluginNamespacedSettingKey.js
|
||||
packages/lib/services/plugins/utils/getPluginSettingKeyPrefix.js
|
||||
packages/lib/services/plugins/utils/getPluginSettingValue.js
|
||||
packages/lib/services/plugins/utils/loadContentScripts.js
|
||||
packages/lib/services/plugins/utils/makeListener.js
|
||||
packages/lib/services/plugins/utils/manifestFromObject.js
|
||||
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -1002,6 +1002,9 @@ packages/lib/services/plugins/defaultPlugins/desktopDefaultPluginsInfo.js
|
||||
packages/lib/services/plugins/reducer.js
|
||||
packages/lib/services/plugins/utils/createViewHandle.js
|
||||
packages/lib/services/plugins/utils/executeSandboxCall.js
|
||||
packages/lib/services/plugins/utils/getPluginNamespacedSettingKey.js
|
||||
packages/lib/services/plugins/utils/getPluginSettingKeyPrefix.js
|
||||
packages/lib/services/plugins/utils/getPluginSettingValue.js
|
||||
packages/lib/services/plugins/utils/loadContentScripts.js
|
||||
packages/lib/services/plugins/utils/makeListener.js
|
||||
packages/lib/services/plugins/utils/manifestFromObject.js
|
||||
|
@ -49,7 +49,7 @@ import PlainEditor from './NoteBody/PlainEditor/PlainEditor';
|
||||
import CodeMirror6 from './NoteBody/CodeMirror/v6/CodeMirror';
|
||||
import CodeMirror5 from './NoteBody/CodeMirror/v5/CodeMirror';
|
||||
import { openItemById } from './utils/contextMenu';
|
||||
import { namespacedKey } from '@joplin/lib/services/plugins/api/JoplinSettings';
|
||||
import getPluginSettingValue from '@joplin/lib/services/plugins/utils/getPluginSettingValue';
|
||||
import { MarkupLanguage } from '@joplin/renderer';
|
||||
|
||||
const commands = [
|
||||
@ -162,10 +162,6 @@ function NoteEditor(props: NoteEditorProps) {
|
||||
return formNote.saveActionQueue.waitForAllDone();
|
||||
}
|
||||
|
||||
const settingValue = useCallback((pluginId: string, key: string) => {
|
||||
return Setting.value(namespacedKey(pluginId, key));
|
||||
}, []);
|
||||
|
||||
const whiteBackgroundNoteRendering = formNote.markup_language === MarkupLanguage.Html;
|
||||
|
||||
const markupToHtml = useMarkupToHtml({
|
||||
@ -173,7 +169,7 @@ function NoteEditor(props: NoteEditorProps) {
|
||||
whiteBackgroundNoteRendering,
|
||||
customCss: props.customCss,
|
||||
plugins: props.plugins,
|
||||
settingValue,
|
||||
settingValue: getPluginSettingValue,
|
||||
});
|
||||
|
||||
const allAssets = useCallback(async (markupLanguage: number, options: AllAssetsOptions = null): Promise<any[]> => {
|
||||
|
@ -6,7 +6,7 @@
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
TEMP_PATH=~/src/plugin-tests
|
||||
NEED_COMPILING=1
|
||||
PLUGIN_PATH=~/src/joplin/packages/app-cli/tests/support/plugins/note_list_renderer
|
||||
PLUGIN_PATH=~/src/plugin-abc
|
||||
|
||||
if [[ $NEED_COMPILING == 1 ]]; then
|
||||
mkdir -p "$TEMP_PATH"
|
||||
|
@ -13,6 +13,7 @@ import htmlpack from '@joplin/htmlpack';
|
||||
const { themeStyle } = require('../../theme');
|
||||
const { escapeHtml } = require('../../string-utils.js');
|
||||
import { assetsToHeaders } from '@joplin/renderer';
|
||||
import getPluginSettingValue from '../plugins/utils/getPluginSettingValue';
|
||||
|
||||
export default class InteropService_Exporter_Html extends InteropService_Exporter_Base {
|
||||
|
||||
@ -112,6 +113,7 @@ export default class InteropService_Exporter_Html extends InteropService_Exporte
|
||||
const result = await this.markupToHtml_.render(item.markup_language, bodyMd, this.style_, {
|
||||
resources: this.resources_,
|
||||
plainResourceRendering: true,
|
||||
settingValue: getPluginSettingValue,
|
||||
});
|
||||
const noteContent = [];
|
||||
if (item.title) noteContent.push(`<div class="exported-note-title">${escapeHtml(item.title)}</div>`);
|
||||
|
@ -3,6 +3,8 @@
|
||||
import eventManager, { EventName } from '../../../eventManager';
|
||||
import Setting, { SettingItem as InternalSettingItem, SettingSectionSource } from '../../../models/Setting';
|
||||
import Plugin from '../Plugin';
|
||||
import getPluginNamespacedSettingKey from '../utils/getPluginNamespacedSettingKey';
|
||||
import getPluginSettingKeyPrefix from '../utils/getPluginSettingKeyPrefix';
|
||||
import { SettingItem, SettingSection } from './types';
|
||||
|
||||
// That's all the plugin as of 27/08/21 - any new plugin after that will not be
|
||||
@ -70,17 +72,6 @@ export interface ChangeEvent {
|
||||
|
||||
export type ChangeHandler = (event: ChangeEvent)=> void;
|
||||
|
||||
const keyPrefix = (pluginId: string): string => {
|
||||
return `plugin-${pluginId}.`;
|
||||
};
|
||||
|
||||
// Ensures that the plugin settings and sections are within their own namespace,
|
||||
// to prevent them from overwriting other plugin settings or the default
|
||||
// settings.
|
||||
export const namespacedKey = (pluginId: string, key: string): string => {
|
||||
return `${keyPrefix(pluginId)}${key}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* This API allows registering new settings and setting sections, as well as getting and setting settings. Once a setting has been registered it will appear in the config screen and be editable by the user.
|
||||
*
|
||||
@ -117,7 +108,7 @@ export default class JoplinSettings {
|
||||
|
||||
if ('subType' in setting) internalSettingItem.subType = setting.subType;
|
||||
if ('isEnum' in setting) internalSettingItem.isEnum = setting.isEnum;
|
||||
if ('section' in setting) internalSettingItem.section = namespacedKey(this.plugin_.id, setting.section);
|
||||
if ('section' in setting) internalSettingItem.section = getPluginNamespacedSettingKey(this.plugin_.id, setting.section);
|
||||
if ('options' in setting) internalSettingItem.options = () => setting.options;
|
||||
if ('appTypes' in setting) internalSettingItem.appTypes = setting.appTypes;
|
||||
if ('secure' in setting) internalSettingItem.secure = setting.secure;
|
||||
@ -127,7 +118,7 @@ export default class JoplinSettings {
|
||||
if ('step' in setting) internalSettingItem.step = setting.step;
|
||||
if ('storage' in setting) internalSettingItem.storage = setting.storage;
|
||||
|
||||
await Setting.registerSetting(namespacedKey(this.plugin_.id, key), internalSettingItem);
|
||||
await Setting.registerSetting(getPluginNamespacedSettingKey(this.plugin_.id, key), internalSettingItem);
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,21 +142,21 @@ export default class JoplinSettings {
|
||||
* Registers a new setting section. Like for registerSetting, it is dynamic and needs to be done every time the plugin starts.
|
||||
*/
|
||||
public async registerSection(name: string, section: SettingSection) {
|
||||
return Setting.registerSection(namespacedKey(this.plugin_.id, name), SettingSectionSource.Plugin, section);
|
||||
return Setting.registerSection(getPluginNamespacedSettingKey(this.plugin_.id, name), SettingSectionSource.Plugin, section);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a setting value (only applies to setting you registered from your plugin)
|
||||
*/
|
||||
public async value(key: string): Promise<any> {
|
||||
return Setting.value(namespacedKey(this.plugin_.id, key));
|
||||
return Setting.value(getPluginNamespacedSettingKey(this.plugin_.id, key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a setting value (only applies to setting you registered from your plugin)
|
||||
*/
|
||||
public async setValue(key: string, value: any) {
|
||||
return Setting.setValue(namespacedKey(this.plugin_.id, key), value);
|
||||
return Setting.setValue(getPluginNamespacedSettingKey(this.plugin_.id, key), value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -188,8 +179,8 @@ export default class JoplinSettings {
|
||||
// Filter out keys that are not related to this plugin
|
||||
eventManager.on(EventName.SettingsChange, (event: ChangeEvent) => {
|
||||
const keys = event.keys
|
||||
.filter(k => k.indexOf(keyPrefix(this.plugin_.id)) === 0)
|
||||
.map(k => k.substr(keyPrefix(this.plugin_.id).length));
|
||||
.filter(k => k.indexOf(getPluginSettingKeyPrefix(this.plugin_.id)) === 0)
|
||||
.map(k => k.substr(getPluginSettingKeyPrefix(this.plugin_.id).length));
|
||||
if (!keys.length) return;
|
||||
handler({ keys });
|
||||
});
|
||||
|
@ -0,0 +1,9 @@
|
||||
import getPluginSettingKeyPrefix from './getPluginSettingKeyPrefix';
|
||||
|
||||
// Ensures that the plugin settings and sections are within their own namespace,
|
||||
// to prevent them from overwriting other plugin settings or the default
|
||||
// settings.
|
||||
|
||||
export default (pluginId: string, key: string): string => {
|
||||
return `${getPluginSettingKeyPrefix(pluginId)}${key}`;
|
||||
};
|
@ -0,0 +1,3 @@
|
||||
export default (pluginId: string): string => {
|
||||
return `plugin-${pluginId}.`;
|
||||
};
|
@ -0,0 +1,6 @@
|
||||
import Setting from '../../../models/Setting';
|
||||
import getPluginNamespacedSettingKey from './getPluginNamespacedSettingKey';
|
||||
|
||||
export default (pluginId: string, key: string) => {
|
||||
return Setting.value(getPluginNamespacedSettingKey(pluginId, key));
|
||||
};
|
Loading…
Reference in New Issue
Block a user