Fix helpers.referenceLinkRe to handle full and shortcut reference image links inside normal links (fixes #571).

This commit is contained in:
David Anson 2022-08-31 22:46:19 -07:00
parent 62060aaf21
commit 6974cd6012
5 changed files with 51 additions and 23 deletions

View file

@ -56,7 +56,7 @@ const emphasisMarkersRe = /[_*]/g;
const blockquotePrefixRe = /^[>\s]*/; const blockquotePrefixRe = /^[>\s]*/;
module.exports.blockquotePrefixRe = blockquotePrefixRe; module.exports.blockquotePrefixRe = blockquotePrefixRe;
// Regular expression for reference links (full, collapsed, and shortcut) // Regular expression for reference links (full, collapsed, and shortcut)
const referenceLinkRe = /!?\\?\[((?:\[[^\]\0]*]|[^\]\0])*)](?:(?:\[([^\]\0]*)\])|([^(])|$)/g; const referenceLinkRe = /!?\\?\[((?:\[[^\]\0]*]|[^[\]\0])*)](?:(?:\[([^\]\0]*)\])|([^(])|$)/g;
// Regular expression for link reference definitions // Regular expression for link reference definitions
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])]:/; const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])]:/;
module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe; module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe;

View file

@ -36,7 +36,7 @@ module.exports.blockquotePrefixRe = blockquotePrefixRe;
// Regular expression for reference links (full, collapsed, and shortcut) // Regular expression for reference links (full, collapsed, and shortcut)
const referenceLinkRe = const referenceLinkRe =
/!?\\?\[((?:\[[^\]\0]*]|[^\]\0])*)](?:(?:\[([^\]\0]*)\])|([^(])|$)/g; /!?\\?\[((?:\[[^\]\0]*]|[^[\]\0])*)](?:(?:\[([^\]\0]*)\])|([^(])|$)/g;
// Regular expression for link reference definitions // Regular expression for link reference definitions
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])]:/; const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])]:/;

View file

@ -102,17 +102,19 @@ Escaped right label: [text][wrong\]
## Valid Images ## Valid Images
Full style: ![text][image] Full style: ![text][image0]
Collapsed style: ![image][] Collapsed style: ![image1][]
Shortcut style: ![image] Shortcut style: ![image2]
Image in link: [![text][image]][label] [![image][]][label] [![image]][label] Image in link: [![text][image3]](link) [![image4][]](link) [![image5]](link)
Wrapped in brackets: [![text][unique6]] Image in shortcut link: [![text][image6]][unique6] [![image7][]][unique7] [![image8]][unique8]
Embedded [in ![text][unique7] brackets] Wrapped in brackets: [![text][unique9]]
Embedded [in ![text][unique10] brackets]
## Invalid Images ## Invalid Images
@ -143,6 +145,15 @@ Missing[^2]
[label]: https://example.com/label [label]: https://example.com/label
[ label with spaces ]: https://example.com/label-with-spaces [ label with spaces ]: https://example.com/label-with-spaces
[image]:https://example.com/image [image]:https://example.com/image
[image0]: https://example.com/image0
[image1]: https://example.com/image1
[image2]: https://example.com/image2
[image3]: https://example.com/image3
[image4]: https://example.com/image4
[image5]: https://example.com/image5
[image6]: https://example.com/image6
[image7]: https://example.com/image7
[image8]: https://example.com/image8
[`code`]: https://example.com/code [`code`]: https://example.com/code
[^1]: https://example.com/footnote [^1]: https://example.com/footnote
[multi line full text]: https://example.com/multi-line-full-text [multi line full text]: https://example.com/multi-line-full-text
@ -165,6 +176,9 @@ https://example.com/multi-line-label
[unique5]: https://example.com/unique5 [unique5]: https://example.com/unique5
[unique6]: https://example.com/unique6 [unique6]: https://example.com/unique6
[unique7]: https://example.com/unique7 [unique7]: https://example.com/unique7
[unique8]: https://example.com/unique8
[unique9]: https://example.com/unique9
[unique10]: https://example.com/unique10
## Ignored Labels ## Ignored Labels

View file

@ -33736,7 +33736,7 @@ Generated by [AVA](https://avajs.dev).
16, 16,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 119, lineNumber: 121,
ruleDescription: 'Reference links and images should use a label that is defined', ruleDescription: 'Reference links and images should use a label that is defined',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md052', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md052',
ruleNames: [ ruleNames: [
@ -33752,7 +33752,7 @@ Generated by [AVA](https://avajs.dev).
16, 16,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 121, lineNumber: 123,
ruleDescription: 'Reference links and images should use a label that is defined', ruleDescription: 'Reference links and images should use a label that is defined',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md052', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md052',
ruleNames: [ ruleNames: [
@ -33768,7 +33768,7 @@ Generated by [AVA](https://avajs.dev).
25, 25,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 202, lineNumber: 216,
ruleDescription: 'Reference links and images should use a label that is defined', ruleDescription: 'Reference links and images should use a label that is defined',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md052', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md052',
ruleNames: [ ruleNames: [
@ -33784,7 +33784,7 @@ Generated by [AVA](https://avajs.dev).
10, 10,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 216, lineNumber: 230,
ruleDescription: 'Reference links and images should use a label that is defined', ruleDescription: 'Reference links and images should use a label that is defined',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md052', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md052',
ruleNames: [ ruleNames: [
@ -33802,7 +33802,7 @@ Generated by [AVA](https://avajs.dev).
fixInfo: { fixInfo: {
deleteCount: -1, deleteCount: -1,
}, },
lineNumber: 178, lineNumber: 192,
ruleDescription: 'Link and image reference definitions should be needed', ruleDescription: 'Link and image reference definitions should be needed',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053',
ruleNames: [ ruleNames: [
@ -33820,7 +33820,7 @@ Generated by [AVA](https://avajs.dev).
fixInfo: { fixInfo: {
deleteCount: -1, deleteCount: -1,
}, },
lineNumber: 181, lineNumber: 195,
ruleDescription: 'Link and image reference definitions should be needed', ruleDescription: 'Link and image reference definitions should be needed',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053',
ruleNames: [ ruleNames: [
@ -33838,7 +33838,7 @@ Generated by [AVA](https://avajs.dev).
fixInfo: { fixInfo: {
deleteCount: -1, deleteCount: -1,
}, },
lineNumber: 184, lineNumber: 198,
ruleDescription: 'Link and image reference definitions should be needed', ruleDescription: 'Link and image reference definitions should be needed',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053',
ruleNames: [ ruleNames: [
@ -33854,7 +33854,7 @@ Generated by [AVA](https://avajs.dev).
44, 44,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 186, lineNumber: 200,
ruleDescription: 'Link and image reference definitions should be needed', ruleDescription: 'Link and image reference definitions should be needed',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053',
ruleNames: [ ruleNames: [
@ -33870,7 +33870,7 @@ Generated by [AVA](https://avajs.dev).
44, 44,
], ],
fixInfo: null, fixInfo: null,
lineNumber: 189, lineNumber: 203,
ruleDescription: 'Link and image reference definitions should be needed', ruleDescription: 'Link and image reference definitions should be needed',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053', ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md053',
ruleNames: [ ruleNames: [
@ -33983,17 +33983,19 @@ Generated by [AVA](https://avajs.dev).
## Valid Images␊ ## Valid Images␊
Full style: ![text][image]␊ Full style: ![text][image0]␊
Collapsed style: ![image][]␊ Collapsed style: ![image1][]␊
Shortcut style: ![image]␊ Shortcut style: ![image2]␊
Image in link: [![text][image]][label] [![image][]][label] [![image]][label] Image in link: [![text][image3]](link) [![image4][]](link) [![image5]](link)
Wrapped in brackets: [![text][unique6]]␊ Image in shortcut link: [![text][image6]][unique6] [![image7][]][unique7] [![image8]][unique8]␊
Embedded [in ![text][unique7] brackets]␊ Wrapped in brackets: [![text][unique9]]␊
Embedded [in ![text][unique10] brackets]␊
## Invalid Images␊ ## Invalid Images␊
@ -34024,6 +34026,15 @@ Generated by [AVA](https://avajs.dev).
[label]: https://example.com/label␊ [label]: https://example.com/label␊
[ label with spaces ]: https://example.com/label-with-spaces␊ [ label with spaces ]: https://example.com/label-with-spaces␊
[image]:https://example.com/image␊ [image]:https://example.com/image␊
[image0]: https://example.com/image0␊
[image1]: https://example.com/image1␊
[image2]: https://example.com/image2␊
[image3]: https://example.com/image3␊
[image4]: https://example.com/image4␊
[image5]: https://example.com/image5␊
[image6]: https://example.com/image6␊
[image7]: https://example.com/image7␊
[image8]: https://example.com/image8␊
[\`code\`]: https://example.com/code␊ [\`code\`]: https://example.com/code␊
[^1]: https://example.com/footnote␊ [^1]: https://example.com/footnote␊
[multi line full text]: https://example.com/multi-line-full-text␊ [multi line full text]: https://example.com/multi-line-full-text␊
@ -34046,6 +34057,9 @@ Generated by [AVA](https://avajs.dev).
[unique5]: https://example.com/unique5␊ [unique5]: https://example.com/unique5␊
[unique6]: https://example.com/unique6␊ [unique6]: https://example.com/unique6␊
[unique7]: https://example.com/unique7␊ [unique7]: https://example.com/unique7␊
[unique8]: https://example.com/unique8␊
[unique9]: https://example.com/unique9␊
[unique10]: https://example.com/unique10␊
## Ignored Labels␊ ## Ignored Labels␊