mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Resolves #3333: Improved escaping of Markdown titles in links
This commit is contained in:
parent
f36e0c2513
commit
40adbc5e9e
@ -9,11 +9,6 @@ const listRegex = /^(\s*)([*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]))(\s*)/;
|
||||
const emptyListRegex = /^(\s*)([*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/;
|
||||
|
||||
const markdownUtils = {
|
||||
// Not really escaping because that's not supported by marked.js
|
||||
escapeLinkText(text) {
|
||||
return text.replace(/(\[|\]|\(|\))/g, '_');
|
||||
},
|
||||
|
||||
// Titles for markdown links only need escaping for [ and ]
|
||||
escapeTitleText(text) {
|
||||
return text.replace(/(\[|\])/g, '\\$1');
|
||||
|
@ -207,11 +207,11 @@ class Resource extends BaseItem {
|
||||
const lines = [];
|
||||
if (Resource.isSupportedImageMimeType(resource.mime)) {
|
||||
lines.push('![');
|
||||
lines.push(markdownUtils.escapeLinkText(tagAlt));
|
||||
lines.push(markdownUtils.escapeTitleText(tagAlt));
|
||||
lines.push(`](:/${resource.id})`);
|
||||
} else {
|
||||
lines.push('[');
|
||||
lines.push(markdownUtils.escapeLinkText(tagAlt));
|
||||
lines.push(markdownUtils.escapeTitleText(tagAlt));
|
||||
lines.push(`](:/${resource.id})`);
|
||||
}
|
||||
return lines.join('');
|
||||
|
@ -211,7 +211,7 @@ function shimInit() {
|
||||
}, options);
|
||||
|
||||
const { basename } = require('path');
|
||||
const { escapeLinkText } = require('lib/markdownUtils');
|
||||
const { escapeTitleText } = require('lib/markdownUtils');
|
||||
const { toFileProtocolPath } = require('lib/path-utils');
|
||||
|
||||
let resource = null;
|
||||
@ -231,7 +231,7 @@ function shimInit() {
|
||||
if (!options.createFileURL) {
|
||||
newBody.push(Resource.markdownTag(resource));
|
||||
} else {
|
||||
const filename = escapeLinkText(basename(filePath)); // to get same filename as standard drag and drop
|
||||
const filename = escapeTitleText(basename(filePath)); // to get same filename as standard drag and drop
|
||||
const fileURL = `[${filename}](${toFileProtocolPath(filePath)})`;
|
||||
newBody.push(fileURL);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user