mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
Update MD037/no-space-in-emphasis to ignore embedded underscore emphasis markers (fixes #444, fixes #408, fixes #354, fixes #324).
This commit is contained in:
parent
3e8d3320f7
commit
7cf9c2d6be
3 changed files with 18 additions and 4 deletions
|
@ -3480,6 +3480,7 @@ module.exports = {
|
||||||
var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, emphasisMarkersInContent = _a.emphasisMarkersInContent, forEachLine = _a.forEachLine, isBlankLine = _a.isBlankLine;
|
var _a = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"), addErrorContext = _a.addErrorContext, emphasisMarkersInContent = _a.emphasisMarkersInContent, forEachLine = _a.forEachLine, isBlankLine = _a.isBlankLine;
|
||||||
var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata);
|
var lineMetadata = (__webpack_require__(/*! ./cache */ "../lib/cache.js").lineMetadata);
|
||||||
var emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g;
|
var emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g;
|
||||||
|
var embeddedUnderscoreRe = /([A-Za-z0-9])_([A-Za-z0-9])/g;
|
||||||
var asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
|
var asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
|
||||||
var leftSpaceRe = /^\s+/;
|
var leftSpaceRe = /^\s+/;
|
||||||
var rightSpaceRe = /\s+$/;
|
var rightSpaceRe = /\s+$/;
|
||||||
|
@ -3559,13 +3560,14 @@ module.exports = {
|
||||||
// Emphasis has no meaning here
|
// Emphasis has no meaning here
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2");
|
||||||
if (onItemStart) {
|
if (onItemStart) {
|
||||||
// Trim overlapping '*' list item marker
|
// Trim overlapping '*' list item marker
|
||||||
line = line.replace(asteriskListItemMarkerRe, "$1 $2");
|
patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");
|
||||||
}
|
}
|
||||||
var match = null;
|
var match = null;
|
||||||
// Match all emphasis-looking runs in the line...
|
// Match all emphasis-looking runs in the line...
|
||||||
while ((match = emphasisRe.exec(line))) {
|
while ((match = emphasisRe.exec(patchedLine))) {
|
||||||
var ignoreMarkersForLine = ignoreMarkersByLine[lineIndex];
|
var ignoreMarkersForLine = ignoreMarkersByLine[lineIndex];
|
||||||
var matchIndex = match.index + match[1].length;
|
var matchIndex = match.index + match[1].length;
|
||||||
if (ignoreMarkersForLine.includes(matchIndex)) {
|
if (ignoreMarkersForLine.includes(matchIndex)) {
|
||||||
|
|
|
@ -7,6 +7,7 @@ const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine } =
|
||||||
const { lineMetadata } = require("./cache");
|
const { lineMetadata } = require("./cache");
|
||||||
|
|
||||||
const emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g;
|
const emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g;
|
||||||
|
const embeddedUnderscoreRe = /([A-Za-z0-9])_([A-Za-z0-9])/g;
|
||||||
const asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
|
const asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
|
||||||
const leftSpaceRe = /^\s+/;
|
const leftSpaceRe = /^\s+/;
|
||||||
const rightSpaceRe = /\s+$/;
|
const rightSpaceRe = /\s+$/;
|
||||||
|
@ -98,13 +99,14 @@ module.exports = {
|
||||||
// Emphasis has no meaning here
|
// Emphasis has no meaning here
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let patchedLine = line.replace(embeddedUnderscoreRe, "$1 $2");
|
||||||
if (onItemStart) {
|
if (onItemStart) {
|
||||||
// Trim overlapping '*' list item marker
|
// Trim overlapping '*' list item marker
|
||||||
line = line.replace(asteriskListItemMarkerRe, "$1 $2");
|
patchedLine = patchedLine.replace(asteriskListItemMarkerRe, "$1 $2");
|
||||||
}
|
}
|
||||||
let match = null;
|
let match = null;
|
||||||
// Match all emphasis-looking runs in the line...
|
// Match all emphasis-looking runs in the line...
|
||||||
while ((match = emphasisRe.exec(line))) {
|
while ((match = emphasisRe.exec(patchedLine))) {
|
||||||
const ignoreMarkersForLine = ignoreMarkersByLine[lineIndex];
|
const ignoreMarkersForLine = ignoreMarkersByLine[lineIndex];
|
||||||
const matchIndex = match.index + match[1].length;
|
const matchIndex = match.index + match[1].length;
|
||||||
if (ignoreMarkersForLine.includes(matchIndex)) {
|
if (ignoreMarkersForLine.includes(matchIndex)) {
|
||||||
|
|
|
@ -347,3 +347,13 @@ text [reference*link] star * star text
|
||||||
```yaml /* autogenerated */
|
```yaml /* autogenerated */
|
||||||
# YAML...
|
# YAML...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
new_value from *old_value* and *older_value*.
|
||||||
|
|
||||||
|
:ballot_box_with_check: _Emoji syntax_
|
||||||
|
|
||||||
|
some_snake_case_function() is _called_
|
||||||
|
|
||||||
|
_~/.ssh/id_rsa_ and _emphasis_
|
||||||
|
|
||||||
|
Partial *em*phasis of a *wo*rd.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue