1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Clipper: Set source URL and fixed issues with tables and urls

This commit is contained in:
Laurent Cozic 2018-05-24 12:44:13 +01:00
parent a8da469523
commit f79d7b9626
8 changed files with 33 additions and 9 deletions

View File

@ -36,7 +36,7 @@ describe('HtmlToMd', function() {
const htmlPath = basePath + '/' + htmlFilename;
const mdPath = basePath + '/' + filename(htmlFilename) + '.md';
// if (htmlFilename !== 'anchor_with_newlines.html') continue;
// if (htmlFilename !== 'table_with_colspan.html') continue;
const html = await shim.fsDriver().readFile(htmlPath);
const expectedMd = await shim.fsDriver().readFile(mdPath);

View File

@ -0,0 +1,15 @@
<table>
<tr>
<td colspan="2">
Something that was originally spanning two columns
</td>
</tr>
<tr>
<td>
One
</td>
<td>
Two
</td>
</tr>
</table>

View File

@ -0,0 +1,4 @@
| | |
| --- | --- |
| Something that was originally spanning two columns | |
| One | Two |

View File

@ -26,6 +26,11 @@ describe('urlUtils', function() {
expect(urlUtils.prependBaseUrl('', 'http://example.com/something')).toBe('http://example.com/something');
expect(urlUtils.prependBaseUrl('testing.html', '')).toBe('testing.html');
// It shouldn't prepend anyting for these:
expect(urlUtils.prependBaseUrl('mailto:emailme@example.com', 'http://example.com')).toBe('mailto:emailme@example.com');
expect(urlUtils.prependBaseUrl('javascript:var%20testing=true', 'http://example.com')).toBe('javascript:var%20testing=true');
expect(urlUtils.prependBaseUrl('http://alreadyabsolute.com', 'http://example.com')).toBe('http://alreadyabsolute.com');
done();
});

View File

@ -4035,9 +4035,9 @@
}
},
"joplin-turndown-plugin-gfm": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/joplin-turndown-plugin-gfm/-/joplin-turndown-plugin-gfm-1.0.5.tgz",
"integrity": "sha512-B0gLGle6NJUlu3redq4wv99sYiAAiJmio0WPCXnD1O9uAkq6YAbOkVG6CW+JPJSKOizSTZidrVYdeDAl+mQ8dg=="
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/joplin-turndown-plugin-gfm/-/joplin-turndown-plugin-gfm-1.0.6.tgz",
"integrity": "sha512-FLGejYMWvYNQbuAYuDAVQdcVB6X3zwmSEKSneAuXg2/3KAhdRFq6lqBf54hxan+iD3RISK8LhkmPFBLEGwVNtQ=="
},
"js-tokens": {
"version": "3.0.2",

View File

@ -90,7 +90,7 @@
"html-entities": "^1.2.1",
"image-type": "^3.0.0",
"joplin-turndown": "^4.0.4",
"joplin-turndown-plugin-gfm": "^1.0.5",
"joplin-turndown-plugin-gfm": "^1.0.6",
"jssha": "^2.3.1",
"katex": "^0.9.0-beta1",
"levenshtein": "^1.0.5",

View File

@ -37,7 +37,7 @@ class ClipperServer {
body: requestNote.body ? requestNote.body : '',
};
if (requestNote.bodyHtml) {
if (requestNote.bodyHtml) {
// Parsing will not work if the HTML is not wrapped in a top level tag, which is not guaranteed
// when getting the content from elsewhere. So here wrap it - it won't change anything to the final
// rendering but it makes sure everything will be parsed.
@ -54,6 +54,8 @@ class ClipperServer {
output.parent_id = folder.id;
}
if (requestNote.url) output.source_url = requestNote.url;
return output;
}

View File

@ -18,15 +18,13 @@ urlUtils.urlProtocol = function(url) {
return parsed.protocol;
}
const schemeRegex = /^[a-zA-Z0-9\+\-\.]+:\/\//
urlUtils.prependBaseUrl = function(url, baseUrl) {
baseUrl = rtrimSlashes(baseUrl).trim(); // All the code below assumes that the baseUrl does not end up with a slash
url = url.trim();
if (!url) url = '';
if (!baseUrl) return url;
const matches = schemeRegex.exec(url);
if (matches) return url; // Don't prepend the base URL if the URL already has a scheme
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
return urlUtils.urlProtocol(baseUrl) + url;