fix: prevent escaping of footnotes and references (#3646)

Prevent footnotes ([^1]:blah) and footnote references ([^1]) from being incorrectly escaped when switching between Markdown and Rich Text modes.

Co-authored-by: Pedr <pedr@sleepstation.org.uk>
This commit is contained in:
Pedr Browne 2020-04-22 17:41:06 +01:00 committed by GitHub
parent cf57284f40
commit 028ab535df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 8 deletions

View File

@ -73,7 +73,13 @@ describe('remarkEscapeMarkdownEntities', () => {
expect(process('a b <pre>*c*</pre> d e')).toEqual('a b <pre>*c*</pre> d e');
});
it('should not parse footnotes', () => {
expect(process('[^a]')).toEqual('\\[^a]');
it('should not escape footnote references', () => {
expect(process('[^a]')).toEqual('[^a]');
expect(process('[^1]')).toEqual('[^1]');
});
it('should not escape footnotes', () => {
expect(process('[^a]:')).toEqual('[^a]:');
expect(process('[^1]:')).toEqual('[^1]:');
});
});

View File

@ -124,14 +124,14 @@ const escapePatterns = [
/(`+)[^`]*(\1)/g,
/**
* Links, Images, References, and Footnotes
* Links and Images
*
* Match strings surrounded by brackets. This could be improved to
* specifically match only the exact syntax of each covered entity, but
* doing so through current approach would incur a considerable performance
* penalty.
* Match strings surrounded by square brackets, except when the opening
* bracket is followed by a caret. This could be improved to specifically
* match only the exact syntax of each covered entity, but doing so through
* current approach would incur a considerable performance penalty.
*/
/(\[)[^\]]*]/g,
/(\[(?!\^)+)[^\]]*]/g,
];
/**