1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-27 23:28:38 +02:00

Desktop: Resolves #4433: Import linked local files when importing Markdown files (#4966)

This commit is contained in:
JackGruber
2021-05-19 23:22:03 +02:00
committed by GitHub
parent 85211e8d5c
commit eceb14ff9e
7 changed files with 72 additions and 9 deletions

View File

@ -61,7 +61,7 @@ const markdownUtils = {
},
// Returns the **encoded** URLs, so to be useful they should be decoded again before use.
extractImageUrls(md: string) {
extractFileUrls(md: string, onlyImage: boolean = false): Array<string> {
const markdownIt = new MarkdownIt();
markdownIt.validateLink = validateLinks; // Necessary to support file:/// links
@ -72,11 +72,10 @@ const markdownUtils = {
const searchUrls = (tokens: any[]) => {
for (let i = 0; i < tokens.length; i++) {
const token = tokens[i];
if (token.type === 'image') {
if ((onlyImage === true && token.type === 'image') || (onlyImage === false && (token.type === 'image' || token.type === 'link_open'))) {
for (let j = 0; j < token.attrs.length; j++) {
const a = token.attrs[j];
if (a[0] === 'src' && a.length >= 2 && a[1]) {
if ((a[0] === 'src' || a[0] === 'href') && a.length >= 2 && a[1]) {
output.push(a[1]);
}
}
@ -93,6 +92,10 @@ const markdownUtils = {
return output;
},
extractImageUrls(md: string) {
return markdownUtils.extractFileUrls(md,true);
},
// The match results has 5 items
// Full match array is
// [Full match, whitespace, list token, ol line number, whitespace following token]