You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Clipper: Fixed importing certain images with sources that contain brackets
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
const urlUtils = require('lib/urlUtils');
|
||||
const MarkdownIt = require('markdown-it');
|
||||
|
||||
const markdownUtils = {
|
||||
|
||||
@ -20,15 +21,32 @@ const markdownUtils = {
|
||||
},
|
||||
|
||||
extractImageUrls(md) {
|
||||
// 
|
||||
const regex = new RegExp(/!\[.*?\]\(([^\s\)]+).*?\)/, 'g')
|
||||
let match = regex.exec(md);
|
||||
const markdownIt = new MarkdownIt();
|
||||
const env = {};
|
||||
const tokens = markdownIt.parse(md, env);
|
||||
const output = [];
|
||||
while (match) {
|
||||
const url = match[1];
|
||||
if (output.indexOf(url) < 0) output.push(url);
|
||||
match = regex.exec(md);
|
||||
|
||||
const searchUrls = (tokens) => {
|
||||
for (let i = 0; i < tokens.length; i++) {
|
||||
const token = tokens[i];
|
||||
|
||||
if (token.type === 'image') {
|
||||
for (let j = 0; j < token.attrs.length; j++) {
|
||||
const a = token.attrs[j];
|
||||
if (a[0] === 'src' && a.length >= 2 && a[1]) {
|
||||
output.push(a[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (token.children && token.children.length) {
|
||||
searchUrls(token.children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
searchUrls(tokens);
|
||||
|
||||
return output;
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user