Update MD037/no-space-in-emphasis to ignore emphasis markers in link text (fixes #280).

This commit is contained in:
David Anson 2020-05-12 20:13:51 -07:00
parent f607a49a5b
commit ac5d52a3e3
3 changed files with 46 additions and 3 deletions

View file

@ -28,8 +28,8 @@ module.exports.orderedListItemMarkerRe = /^[\s>]*0*(\d+)[.)]/;
// Regular expression for all instances of emphasis markers
const emphasisMarkersRe = /[_*]/g;
// Regular expression for links
const linkRe = /\[(?:[^\]]|\[[^\]]*\])*\]\(\S*\)/g;
// Regular expression for inline links and shortcut reference links
const linkRe = /\[(?:[^[\]]|\[[^\]]*\])*\](?:\(\S*\))?/g;
// readFile options for reading with the UTF-8 encoding
module.exports.utf8Encoding = { "encoding": "utf8" };

View file

@ -129,7 +129,7 @@ module.exports = {
// Back up one character so RegExp has a chance to match the
// next marker (ex: "**star**_underscore_")
emphasisRe.lastIndex--;
} else {
} else if (emphasisRe.lastIndex > 1) {
// Back up one character so RegExp has a chance to match the
// mis-matched marker (ex: "*text_*")
emphasisRe.lastIndex--;

View file

@ -254,3 +254,46 @@ text _underscore_**star** text _underscore_**star** text
`****** text ******`
`******* text *******`
under_score
_underscore_
st*ar
*star*
under_score
*star*
st*ar
_underscore_
*star*
_underscore_
_underscore_
*star*
_underscore
_*star*
*star
*_underscore_
[reference_link]
_first_ and _second_
[reference_link]
*first* and *second*
[reference*link]
_first_ and _second_
[reference*link]
*first* and *second*
text [reference_link] under _ score text
text [reference*link] star * star text
[reference_link]: https://example.com
[reference*link]: https://example.com