You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
Desktop: Various improvements to Markdown import and export (#5290)
In preparation for #5224
This commit is contained in:
@@ -45,18 +45,39 @@ class HtmlUtils {
|
||||
}
|
||||
|
||||
// Returns the **encoded** URLs, so to be useful they should be decoded again before use.
|
||||
public extractImageUrls(html: string) {
|
||||
private extractUrls(regex: RegExp, html: string) {
|
||||
if (!html) return [];
|
||||
|
||||
const output = [];
|
||||
let matches;
|
||||
while ((matches = imageRegex.exec(html))) {
|
||||
while ((matches = regex.exec(html))) {
|
||||
output.push(matches[2]);
|
||||
}
|
||||
|
||||
return output.filter(url => !!url);
|
||||
}
|
||||
|
||||
// Returns the **encoded** URLs, so to be useful they should be decoded again before use.
|
||||
public extractImageUrls(html: string) {
|
||||
return this.extractUrls(imageRegex, html);
|
||||
}
|
||||
|
||||
// Returns the **encoded** URLs, so to be useful they should be decoded again before use.
|
||||
public extractAnchorUrls(html: string) {
|
||||
return this.extractUrls(anchorRegex, html);
|
||||
}
|
||||
|
||||
// Returns the **encoded** URLs, so to be useful they should be decoded again before use.
|
||||
public extractFileUrls(html: string) {
|
||||
return this.extractImageUrls(html).concat(this.extractAnchorUrls(html));
|
||||
}
|
||||
|
||||
public replaceResourceUrl(html: string, urlToReplace: string, id: string) {
|
||||
const htmlLinkRegex = `(?<=(?:src|href)=["'])${urlToReplace}(?=["'])`;
|
||||
const htmlReg = new RegExp(htmlLinkRegex, 'g');
|
||||
return html.replace(htmlReg, `:/${id}`);
|
||||
}
|
||||
|
||||
public replaceImageUrls(html: string, callback: Function) {
|
||||
return this.processImageTags(html, (data: any) => {
|
||||
const newSrc = callback(data.src);
|
||||
|
||||
Reference in New Issue
Block a user