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

Clipper: Fixes #1622: Import named anchors from clipped pages

This commit is contained in:
Laurent Cozic
2019-06-13 00:26:09 +01:00
parent ad211b4b4e
commit 86136e0c6c
14 changed files with 156 additions and 93 deletions

View File

@@ -7,6 +7,7 @@ class HtmlToMd {
const turndownPluginGfm = require('joplin-turndown-plugin-gfm').gfm
const turndown = new TurndownService({
headingStyle: 'atx',
anchorNames: options.anchorNames ? options.anchorNames.map(n => n.trim().toLowerCase()) : [],
})
turndown.use(turndownPluginGfm)
turndown.remove('script');

View File

@@ -366,7 +366,7 @@ class Api {
const imageSizes = requestNote.image_sizes ? requestNote.image_sizes : {};
let note = await this.requestNoteToNote(requestNote);
let note = await this.requestNoteToNote_(requestNote);
const imageUrls = markdownUtils.extractImageUrls(note.body);
@@ -416,7 +416,7 @@ class Api {
return this.htmlToMdParser_;
}
async requestNoteToNote(requestNote) {
async requestNoteToNote_(requestNote) {
const output = {
title: requestNote.title ? requestNote.title : '',
body: requestNote.body ? requestNote.body : '',
@@ -430,6 +430,7 @@ class Api {
// rendering but it makes sure everything will be parsed.
output.body = await this.htmlToMdParser().parse('<div>' + requestNote.body_html + '</div>', {
baseUrl: requestNote.base_url ? requestNote.base_url : '',
anchorNames: requestNote.anchor_names ? requestNote.anchor_names : [],
});
}

View File

@@ -25,6 +25,7 @@ urlUtils.prependBaseUrl = function(url, baseUrl) {
if (!url) url = '';
if (!baseUrl) return url;
if (url.indexOf('#') === 0) return url; // Don't prepend if it's a local anchor
if (urlUtils.urlProtocol(url)) return url; // Don't prepend the base URL if the URL already has a scheme
if (url.length >= 2 && url.indexOf('//') === 0) { // If it starts with // it's a protcol-relative URL