mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Update MD049/emphasis-style and MD050/strong-style to not report intraword asterisks/underscores as violations because exchanging either alters meaning (fixes #789).
This commit is contained in:
parent
7005a8a438
commit
0006636f75
8 changed files with 77 additions and 22 deletions
|
|
@ -6050,9 +6050,12 @@ var _require = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js"),
|
||||||
var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
|
var _require2 = __webpack_require__(/*! ../helpers/micromark.cjs */ "../helpers/micromark.cjs"),
|
||||||
filterByTypes = _require2.filterByTypes,
|
filterByTypes = _require2.filterByTypes,
|
||||||
tokenIfType = _require2.tokenIfType;
|
tokenIfType = _require2.tokenIfType;
|
||||||
|
var intrawordRe = /\w/;
|
||||||
var impl = function impl(params, onError, type, asterisk, underline) {
|
var impl = function impl(params, onError, type, asterisk, underline) {
|
||||||
var style = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "consistent";
|
var style = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : "consistent";
|
||||||
var emphasisTokens = filterByTypes(params.parsers.micromark.tokens, [type]);
|
var lines = params.lines,
|
||||||
|
parsers = params.parsers;
|
||||||
|
var emphasisTokens = filterByTypes(parsers.micromark.tokens, [type]);
|
||||||
var _iterator = _createForOfIteratorHelper(emphasisTokens),
|
var _iterator = _createForOfIteratorHelper(emphasisTokens),
|
||||||
_step;
|
_step;
|
||||||
try {
|
try {
|
||||||
|
|
@ -6068,6 +6071,8 @@ var impl = function impl(params, onError, type, asterisk, underline) {
|
||||||
style = markupStyle;
|
style = markupStyle;
|
||||||
}
|
}
|
||||||
if (style !== markupStyle) {
|
if (style !== markupStyle) {
|
||||||
|
var underscoreIntraword = style === "underscore" && (intrawordRe.test(lines[startSequence.startLine - 1][startSequence.startColumn - 2]) || intrawordRe.test(lines[endSequence.endLine - 1][endSequence.endColumn - 1]));
|
||||||
|
if (!underscoreIntraword) {
|
||||||
for (var _i = 0, _arr = [startSequence, endSequence]; _i < _arr.length; _i++) {
|
for (var _i = 0, _arr = [startSequence, endSequence]; _i < _arr.length; _i++) {
|
||||||
var sequence = _arr[_i];
|
var sequence = _arr[_i];
|
||||||
addError(onError, sequence.startLine, "Expected: ".concat(style, "; Actual: ").concat(markupStyle), undefined, [sequence.startColumn, sequence.text.length], {
|
addError(onError, sequence.startLine, "Expected: ".concat(style, "; Actual: ").concat(markupStyle), undefined, [sequence.startColumn, sequence.text.length], {
|
||||||
|
|
@ -6079,6 +6084,7 @@ var impl = function impl(params, onError, type, asterisk, underline) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
_iterator.e(err);
|
_iterator.e(err);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,13 @@
|
||||||
const { addError, emphasisOrStrongStyleFor } = require("../helpers");
|
const { addError, emphasisOrStrongStyleFor } = require("../helpers");
|
||||||
const { filterByTypes, tokenIfType } = require("../helpers/micromark.cjs");
|
const { filterByTypes, tokenIfType } = require("../helpers/micromark.cjs");
|
||||||
|
|
||||||
|
const intrawordRe = /\w/;
|
||||||
|
|
||||||
const impl =
|
const impl =
|
||||||
(params, onError, type, asterisk, underline, style = "consistent") => {
|
(params, onError, type, asterisk, underline, style = "consistent") => {
|
||||||
|
const { lines, parsers } = params;
|
||||||
const emphasisTokens =
|
const emphasisTokens =
|
||||||
filterByTypes(params.parsers.micromark.tokens, [ type ]);
|
filterByTypes(parsers.micromark.tokens, [ type ]);
|
||||||
for (const token of emphasisTokens) {
|
for (const token of emphasisTokens) {
|
||||||
const { children } = token;
|
const { children } = token;
|
||||||
const childType = `${type}Sequence`;
|
const childType = `${type}Sequence`;
|
||||||
|
|
@ -20,6 +23,15 @@ const impl =
|
||||||
style = markupStyle;
|
style = markupStyle;
|
||||||
}
|
}
|
||||||
if (style !== markupStyle) {
|
if (style !== markupStyle) {
|
||||||
|
const underscoreIntraword = (style === "underscore") && (
|
||||||
|
intrawordRe.test(
|
||||||
|
lines[startSequence.startLine - 1][startSequence.startColumn - 2]
|
||||||
|
) ||
|
||||||
|
intrawordRe.test(
|
||||||
|
lines[endSequence.endLine - 1][endSequence.endColumn - 1]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (!underscoreIntraword) {
|
||||||
for (const sequence of [ startSequence, endSequence ]) {
|
for (const sequence of [ startSequence, endSequence ]) {
|
||||||
addError(
|
addError(
|
||||||
onError,
|
onError,
|
||||||
|
|
@ -37,6 +49,7 @@ const impl =
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,12 @@ This is *fine*
|
||||||
|
|
||||||
This is _not_ {MD049}
|
This is _not_ {MD049}
|
||||||
|
|
||||||
|
Internal emphasis is preserved:
|
||||||
|
apple*banana*cherry, apple*banana*, *banana*cherry
|
||||||
|
apple_banana_cherry, apple_banana_, _banana_cherry
|
||||||
|
|
||||||
<!-- markdownlint-configure-file {
|
<!-- markdownlint-configure-file {
|
||||||
|
"MD037": false,
|
||||||
"MD049": {
|
"MD049": {
|
||||||
"style": "asterisk"
|
"style": "asterisk"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,12 @@ This is _fine_
|
||||||
|
|
||||||
This is *not* {MD049}
|
This is *not* {MD049}
|
||||||
|
|
||||||
|
Internal emphasis is preserved:
|
||||||
|
apple*banana*cherry, apple*banana*, *banana*cherry
|
||||||
|
apple_banana_cherry, apple_banana_, _banana_cherry
|
||||||
|
|
||||||
<!-- markdownlint-configure-file {
|
<!-- markdownlint-configure-file {
|
||||||
|
"MD037": false,
|
||||||
"MD049": {
|
"MD049": {
|
||||||
"style": "underscore"
|
"style": "underscore"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10754,7 +10754,12 @@ Generated by [AVA](https://avajs.dev).
|
||||||
␊
|
␊
|
||||||
This is *not* {MD049}␊
|
This is *not* {MD049}␊
|
||||||
␊
|
␊
|
||||||
|
Internal emphasis is preserved:␊
|
||||||
|
apple*banana*cherry, apple*banana*, *banana*cherry␊
|
||||||
|
apple_banana_cherry, apple_banana_, _banana_cherry␊
|
||||||
|
␊
|
||||||
<!-- markdownlint-configure-file {␊
|
<!-- markdownlint-configure-file {␊
|
||||||
|
"MD037": false,␊
|
||||||
"MD049": {␊
|
"MD049": {␊
|
||||||
"style": "asterisk"␊
|
"style": "asterisk"␊
|
||||||
}␊
|
}␊
|
||||||
|
|
@ -10815,7 +10820,12 @@ Generated by [AVA](https://avajs.dev).
|
||||||
␊
|
␊
|
||||||
This is _not_ {MD049}␊
|
This is _not_ {MD049}␊
|
||||||
␊
|
␊
|
||||||
|
Internal emphasis is preserved:␊
|
||||||
|
apple*banana*cherry, apple*banana*, *banana*cherry␊
|
||||||
|
apple_banana_cherry, apple_banana_, _banana_cherry␊
|
||||||
|
␊
|
||||||
<!-- markdownlint-configure-file {␊
|
<!-- markdownlint-configure-file {␊
|
||||||
|
"MD037": false,␊
|
||||||
"MD049": {␊
|
"MD049": {␊
|
||||||
"style": "underscore"␊
|
"style": "underscore"␊
|
||||||
}␊
|
}␊
|
||||||
|
|
@ -44028,6 +44038,10 @@ Generated by [AVA](https://avajs.dev).
|
||||||
␊
|
␊
|
||||||
This is **not** {MD050}␊
|
This is **not** {MD050}␊
|
||||||
␊
|
␊
|
||||||
|
Internal emphasis is preserved:␊
|
||||||
|
apple**banana**cherry, apple**banana**, **banana**cherry␊
|
||||||
|
apple__banana__cherry, apple__banana__, __banana__cherry␊
|
||||||
|
␊
|
||||||
<!-- markdownlint-configure-file {␊
|
<!-- markdownlint-configure-file {␊
|
||||||
"MD050": {␊
|
"MD050": {␊
|
||||||
"style": "asterisk"␊
|
"style": "asterisk"␊
|
||||||
|
|
@ -44089,6 +44103,10 @@ Generated by [AVA](https://avajs.dev).
|
||||||
␊
|
␊
|
||||||
This is __not__ {MD050}␊
|
This is __not__ {MD050}␊
|
||||||
␊
|
␊
|
||||||
|
Internal emphasis is preserved:␊
|
||||||
|
apple**banana**cherry, apple**banana**, **banana**cherry␊
|
||||||
|
apple__banana__cherry, apple__banana__, __banana__cherry␊
|
||||||
|
␊
|
||||||
<!-- markdownlint-configure-file {␊
|
<!-- markdownlint-configure-file {␊
|
||||||
"MD050": {␊
|
"MD050": {␊
|
||||||
"style": "underscore"␊
|
"style": "underscore"␊
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -4,6 +4,10 @@ This is **fine**
|
||||||
|
|
||||||
This is __not__ {MD050}
|
This is __not__ {MD050}
|
||||||
|
|
||||||
|
Internal emphasis is preserved:
|
||||||
|
apple**banana**cherry, apple**banana**, **banana**cherry
|
||||||
|
apple__banana__cherry, apple__banana__, __banana__cherry
|
||||||
|
|
||||||
<!-- markdownlint-configure-file {
|
<!-- markdownlint-configure-file {
|
||||||
"MD050": {
|
"MD050": {
|
||||||
"style": "asterisk"
|
"style": "asterisk"
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,10 @@ This is __fine__
|
||||||
|
|
||||||
This is **not** {MD050}
|
This is **not** {MD050}
|
||||||
|
|
||||||
|
Internal emphasis is preserved:
|
||||||
|
apple**banana**cherry, apple**banana**, **banana**cherry
|
||||||
|
apple__banana__cherry, apple__banana__, __banana__cherry
|
||||||
|
|
||||||
<!-- markdownlint-configure-file {
|
<!-- markdownlint-configure-file {
|
||||||
"MD050": {
|
"MD050": {
|
||||||
"style": "underscore"
|
"style": "underscore"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue