mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Previously a title with brackets was escaped incorrectly. The brackets were replaced by underscores. The following title `title [square] (round)` looked like this: [title _square_ _round_](:/c54794f53e5e4b1aa558699e255d5f95) Now it looks like this: [title \[square\] (round)](:/c54794f53e5e4b1aa558699e255d5f95) fixes #2085
This commit is contained in:
parent
8cbb0d03e8
commit
3f23d8ed06
@ -49,4 +49,19 @@ describe('markdownUtils', function() {
|
||||
}
|
||||
}));
|
||||
|
||||
it('escape a markdown link (title)', asyncTest(async () => {
|
||||
|
||||
const testCases = [
|
||||
['Helmut K. C. Tessarek', 'Helmut K. C. Tessarek'],
|
||||
['Helmut (K. C.) Tessarek', 'Helmut (K. C.) Tessarek'],
|
||||
['Helmut [K. C.] Tessarek', 'Helmut \\[K. C.\\] Tessarek'],
|
||||
];
|
||||
|
||||
for (let i = 0; i < testCases.length; i++) {
|
||||
const md = testCases[i][0];
|
||||
const expected = testCases[i][1];
|
||||
expect(markdownUtils.escapeTitleText(md)).toBe(expected);
|
||||
}
|
||||
}));
|
||||
|
||||
});
|
||||
|
@ -9,6 +9,11 @@ const markdownUtils = {
|
||||
return text.replace(/(\[|\]|\(|\))/g, '_');
|
||||
},
|
||||
|
||||
// Titles for markdown links only need escaping for [ and ]
|
||||
escapeTitleText(text) {
|
||||
return text.replace(/(\[|\])/g, '\\$1');
|
||||
},
|
||||
|
||||
escapeLinkUrl(url) {
|
||||
url = url.replace(/\(/g, '%28');
|
||||
url = url.replace(/\)/g, '%29');
|
||||
|
@ -761,7 +761,7 @@ class BaseItem extends BaseModel {
|
||||
|
||||
const output = [];
|
||||
output.push('[');
|
||||
output.push(markdownUtils.escapeLinkText(item.title));
|
||||
output.push(markdownUtils.escapeTitleText(item.title));
|
||||
output.push(']');
|
||||
output.push(`(:/${item.id})`);
|
||||
return output.join('');
|
||||
|
Loading…
Reference in New Issue
Block a user