1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-12 22:57:38 +02:00

Desktop, CLI: Fixed import of notes that contain links with hashes

This commit is contained in:
Laurent Cozic
2019-09-12 22:48:10 +01:00
parent 0379523eaf
commit 88561a6c3c
3 changed files with 68 additions and 33 deletions

View File

@ -10,6 +10,7 @@ const { time } = require('lib/time-utils.js');
const { _ } = require('lib/locale.js');
const ArrayUtils = require('lib/ArrayUtils.js');
const lodash = require('lodash');
const urlUtils = require('lib/urlUtils.js');
class Note extends BaseItem {
static tableName() {
@ -114,27 +115,9 @@ class Note extends BaseItem {
static linkedItemIds(body) {
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[\s\S]*?src=["']:\/([a-zA-Z0-9]{32})["'][\s\S]*?>/gi;
const imgMatches = [];
while (true) {
const m = imgRegex.exec(body);
if (!m) break;
imgMatches.push(m[1]);
}
return ArrayUtils.unique(matches.concat(imgMatches));
const links = urlUtils.extractResourceUrls(body);
const itemIds = links.map(l => l.itemId);
return ArrayUtils.unique(itemIds);
}
static async linkedItems(body) {