1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

All: Fixes #968: Export resources specified with a title

This commit is contained in:
Laurent Cozic 2018-11-20 23:18:56 +00:00
parent 3240ff40bc
commit 922bbdd1b6
3 changed files with 38 additions and 6 deletions

View File

@ -5,6 +5,7 @@ const { asyncTest, fileContentEqual, setupDatabase, setupDatabaseAndSynchronizer
const Folder = require('lib/models/Folder.js');
const Note = require('lib/models/Note.js');
const BaseModel = require('lib/BaseModel.js');
const ArrayUtils = require('lib/ArrayUtils.js');
const { shim } = require('lib/shim');
process.on('unhandledRejection', (reason, p) => {
@ -35,13 +36,36 @@ describe('models_Note', function() {
expect(items[0].type_).toBe(BaseModel.TYPE_NOTE);
expect(items[1].type_).toBe(BaseModel.TYPE_RESOURCE);
const resource = items[1];
note2.body += '<img alt="bla" src=":/' + resource.id + '"/>';
note2.body += '<img src=\':/' + resource.id + '\' />';
const resource2 = await shim.createResourceFromPath(__dirname + '/../tests/support/photo.jpg');
const resource3 = await shim.createResourceFromPath(__dirname + '/../tests/support/photo.jpg');
note2.body += '<img alt="bla" src=":/' + resource2.id + '"/>';
note2.body += '<img src=\':/' + resource3.id + '\' />';
items = await Note.linkedItems(note2.body);
expect(items.length).toBe(4);
}));
it('should find linked items', asyncTest(async () => {
const testCases = [
['[](:/06894e83b8f84d3d8cbe0f1587f9e226)', ['06894e83b8f84d3d8cbe0f1587f9e226']],
['[](:/06894e83b8f84d3d8cbe0f1587f9e226) [](:/06894e83b8f84d3d8cbe0f1587f9e226)', ['06894e83b8f84d3d8cbe0f1587f9e226']],
['[](:/06894e83b8f84d3d8cbe0f1587f9e226) [](:/06894e83b8f84d3d8cbe0f1587f9e227)', ['06894e83b8f84d3d8cbe0f1587f9e226', '06894e83b8f84d3d8cbe0f1587f9e227']],
['[](:/06894e83b8f84d3d8cbe0f1587f9e226 "some title")', ['06894e83b8f84d3d8cbe0f1587f9e226']],
];
for (let i = 0; i < testCases.length; i++) {
const t = testCases[i];
const input = t[0];
const expected = t[1];
const actual = Note.linkedItemIds(input);
const contentEquals = ArrayUtils.contentEquals(actual, expected);
// console.info(contentEquals, input, expected, actual);
expect(contentEquals).toBe(true);
}
}));
it('should change the type of notes', asyncTest(async () => {
let folder1 = await Folder.save({ title: "folder1" });
let note1 = await Note.save({ title: 'ma note', parent_id: folder1.id });

View File

@ -6,6 +6,7 @@ const Setting = require('lib/models/Setting.js');
const { shim } = require('lib/shim.js');
const { time } = require('lib/time-utils.js');
const { _ } = require('lib/locale.js');
const ArrayUtils = require('lib/ArrayUtils.js');
const moment = require('moment');
const lodash = require('lodash');
@ -110,12 +111,19 @@ class Note extends BaseItem {
}
static linkedItemIds(body) {
// For example: ![](:/fcca2938a96a22570e8eae2565bc6b0b)
if (!body || body.length <= 32) return [];
// For example: ![](:/fcca2938a96a22570e8eae2565bc6b0b)
let matches = body.match(/\(:\/[a-zA-Z0-9]{32}\)/g);
if (!matches) matches = [];
matches = matches.map((m) => m.substr(3, 32));
// For example: ![](:/fcca2938a96a22570e8eae2565bc6b0b "Some title")
let matches2 = body.match(/\(:\/[a-zA-Z0-9]{32}\s(.*?)\)/g);
if (!matches2) matches2 = [];
matches2 = matches2.map((m) => m.substr(3, 32));
matches = matches.concat(matches2)
// For example: <img src=":/fcca2938a96a22570e8eae2565bc6b0b"/>
const imgRegex = /<img.*?src=["']:\/([a-zA-Z0-9]{32})["']/g
const imgMatches = [];
@ -125,7 +133,7 @@ class Note extends BaseItem {
imgMatches.push(m[1]);
}
return matches.concat(imgMatches);
return ArrayUtils.unique(matches.concat(imgMatches));
}
static async linkedItems(body) {

View File

@ -100,7 +100,7 @@ class Setting extends BaseModel {
'encryption.enabled': { value: false, type: Setting.TYPE_BOOL, public: false },
'encryption.activeMasterKeyId': { value: '', type: Setting.TYPE_STRING, public: false },
'encryption.passwordCache': { value: {}, type: Setting.TYPE_OBJECT, public: false, secure: true },
'style.zoom': {value: "100", type: Setting.TYPE_INT, public: true, appTypes: ['desktop'], label: () => _('Global zoom percentage'), minimum: "50", maximum: "500", step: "10"},
'style.zoom': {value: 100, type: Setting.TYPE_INT, public: true, appTypes: ['desktop'], label: () => _('Global zoom percentage'), minimum: 50, maximum: 500, step: 10},
'style.editor.fontFamily': {value: "", type: Setting.TYPE_STRING, public: true, appTypes: ['desktop'], label: () => _('Editor font family'), description: () => _('This must be *monospace* font or it will not work properly. If the font is incorrect or empty, it will default to a generic monospace font.')},
'autoUpdateEnabled': { value: true, type: Setting.TYPE_BOOL, public: true, appTypes: ['desktop'], label: () => _('Automatically update the application') },
'clipperServer.autoStart': { value: false, type: Setting.TYPE_BOOL, public: false },