mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +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 emptyListRegex = /^(\s*)([*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/;
|
||||||
|
|
||||||
const markdownUtils = {
|
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 ]
|
// Titles for markdown links only need escaping for [ and ]
|
||||||
escapeTitleText(text) {
|
escapeTitleText(text) {
|
||||||
return text.replace(/(\[|\])/g, '\\$1');
|
return text.replace(/(\[|\])/g, '\\$1');
|
||||||
|
@ -207,11 +207,11 @@ class Resource extends BaseItem {
|
|||||||
const lines = [];
|
const lines = [];
|
||||||
if (Resource.isSupportedImageMimeType(resource.mime)) {
|
if (Resource.isSupportedImageMimeType(resource.mime)) {
|
||||||
lines.push('![');
|
lines.push('![');
|
||||||
lines.push(markdownUtils.escapeLinkText(tagAlt));
|
lines.push(markdownUtils.escapeTitleText(tagAlt));
|
||||||
lines.push(`](:/${resource.id})`);
|
lines.push(`](:/${resource.id})`);
|
||||||
} else {
|
} else {
|
||||||
lines.push('[');
|
lines.push('[');
|
||||||
lines.push(markdownUtils.escapeLinkText(tagAlt));
|
lines.push(markdownUtils.escapeTitleText(tagAlt));
|
||||||
lines.push(`](:/${resource.id})`);
|
lines.push(`](:/${resource.id})`);
|
||||||
}
|
}
|
||||||
return lines.join('');
|
return lines.join('');
|
||||||
|
@ -211,7 +211,7 @@ function shimInit() {
|
|||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
const { basename } = require('path');
|
const { basename } = require('path');
|
||||||
const { escapeLinkText } = require('lib/markdownUtils');
|
const { escapeTitleText } = require('lib/markdownUtils');
|
||||||
const { toFileProtocolPath } = require('lib/path-utils');
|
const { toFileProtocolPath } = require('lib/path-utils');
|
||||||
|
|
||||||
let resource = null;
|
let resource = null;
|
||||||
@ -231,7 +231,7 @@ function shimInit() {
|
|||||||
if (!options.createFileURL) {
|
if (!options.createFileURL) {
|
||||||
newBody.push(Resource.markdownTag(resource));
|
newBody.push(Resource.markdownTag(resource));
|
||||||
} else {
|
} 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)})`;
|
const fileURL = `[${filename}](${toFileProtocolPath(filePath)})`;
|
||||||
newBody.push(fileURL);
|
newBody.push(fileURL);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user