mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Update MD037/no-space-in-emphasis to ignore the content of HTML attributes (fixes #540).
This commit is contained in:
parent
48f47b5214
commit
1154ab483b
5 changed files with 209 additions and 39 deletions
|
|
@ -3841,8 +3841,8 @@ module.exports = {
|
|||
"use strict";
|
||||
// @ts-check
|
||||
|
||||
const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||
const { lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
||||
const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine, withinAnyRange } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||
const { htmlElementRanges, lineMetadata } = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
||||
const emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g;
|
||||
const embeddedUnderscoreRe = /([A-Za-z0-9])_([A-Za-z0-9])/g;
|
||||
const asteriskListItemMarkerRe = /^([\s>]*)\*(\s+)/;
|
||||
|
|
@ -3854,6 +3854,7 @@ module.exports = {
|
|||
"description": "Spaces inside emphasis markers",
|
||||
"tags": ["whitespace", "emphasis"],
|
||||
"function": function MD037(params, onError) {
|
||||
const exclusions = htmlElementRanges();
|
||||
// eslint-disable-next-line init-declarations
|
||||
let effectiveEmphasisLength, emphasisIndex, emphasisKind, emphasisLength, pendingError = null;
|
||||
// eslint-disable-next-line jsdoc/require-jsdoc
|
||||
|
|
@ -3881,25 +3882,27 @@ module.exports = {
|
|||
// Report the violation
|
||||
const contextStart = emphasisIndex - emphasisLength;
|
||||
const contextEnd = matchIndex + contextLength;
|
||||
const context = line.substring(contextStart, contextEnd);
|
||||
const column = contextStart + 1;
|
||||
const length = contextEnd - contextStart;
|
||||
const leftMarker = line.substring(contextStart, emphasisIndex);
|
||||
const rightMarker = match ? (match[2] || match[3]) : "";
|
||||
const fixedText = `${leftMarker}${content.trim()}${rightMarker}`;
|
||||
return [
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
context,
|
||||
leftSpace,
|
||||
rightSpace,
|
||||
[column, length],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": fixedText
|
||||
}
|
||||
];
|
||||
if (!withinAnyRange(exclusions, lineIndex, column, length)) {
|
||||
const context = line.substring(contextStart, contextEnd);
|
||||
const leftMarker = line.substring(contextStart, emphasisIndex);
|
||||
const rightMarker = match ? (match[2] || match[3]) : "";
|
||||
const fixedText = `${leftMarker}${content.trim()}${rightMarker}`;
|
||||
return [
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
context,
|
||||
leftSpace,
|
||||
rightSpace,
|
||||
[column, length],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": fixedText
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
43
lib/md037.js
43
lib/md037.js
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine } =
|
||||
require("../helpers");
|
||||
const { lineMetadata } = require("./cache");
|
||||
const { addErrorContext, emphasisMarkersInContent, forEachLine, isBlankLine,
|
||||
withinAnyRange } = require("../helpers");
|
||||
const { htmlElementRanges, lineMetadata } = require("./cache");
|
||||
|
||||
const emphasisRe = /(^|[^\\]|\\\\)(?:(\*\*?\*?)|(__?_?))/g;
|
||||
const embeddedUnderscoreRe = /([A-Za-z0-9])_([A-Za-z0-9])/g;
|
||||
|
|
@ -18,6 +18,7 @@ module.exports = {
|
|||
"description": "Spaces inside emphasis markers",
|
||||
"tags": [ "whitespace", "emphasis" ],
|
||||
"function": function MD037(params, onError) {
|
||||
const exclusions = htmlElementRanges();
|
||||
// eslint-disable-next-line init-declarations
|
||||
let effectiveEmphasisLength, emphasisIndex, emphasisKind, emphasisLength,
|
||||
pendingError = null;
|
||||
|
|
@ -50,25 +51,27 @@ module.exports = {
|
|||
// Report the violation
|
||||
const contextStart = emphasisIndex - emphasisLength;
|
||||
const contextEnd = matchIndex + contextLength;
|
||||
const context = line.substring(contextStart, contextEnd);
|
||||
const column = contextStart + 1;
|
||||
const length = contextEnd - contextStart;
|
||||
const leftMarker = line.substring(contextStart, emphasisIndex);
|
||||
const rightMarker = match ? (match[2] || match[3]) : "";
|
||||
const fixedText = `${leftMarker}${content.trim()}${rightMarker}`;
|
||||
return [
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
context,
|
||||
leftSpace,
|
||||
rightSpace,
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": fixedText
|
||||
}
|
||||
];
|
||||
if (!withinAnyRange(exclusions, lineIndex, column, length)) {
|
||||
const context = line.substring(contextStart, contextEnd);
|
||||
const leftMarker = line.substring(contextStart, emphasisIndex);
|
||||
const rightMarker = match ? (match[2] || match[3]) : "";
|
||||
const fixedText = `${leftMarker}${content.trim()}${rightMarker}`;
|
||||
return [
|
||||
onError,
|
||||
lineIndex + 1,
|
||||
context,
|
||||
leftSpace,
|
||||
rightSpace,
|
||||
[ column, length ],
|
||||
{
|
||||
"editColumn": column,
|
||||
"deleteCount": length,
|
||||
"insertText": fixedText
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37062,6 +37062,86 @@ Generated by [AVA](https://avajs.dev).
|
|||
|
||||
{
|
||||
errors: [
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: 'Element: b',
|
||||
errorRange: [
|
||||
10,
|
||||
3,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 361,
|
||||
ruleDescription: 'Inline HTML',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033',
|
||||
ruleNames: [
|
||||
'MD033',
|
||||
'no-inline-html',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: 'Element: p',
|
||||
errorRange: [
|
||||
1,
|
||||
3,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 363,
|
||||
ruleDescription: 'Inline HTML',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033',
|
||||
ruleNames: [
|
||||
'MD033',
|
||||
'no-inline-html',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: 'Element: p',
|
||||
errorRange: [
|
||||
10,
|
||||
39,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 367,
|
||||
ruleDescription: 'Inline HTML',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033',
|
||||
ruleNames: [
|
||||
'MD033',
|
||||
'no-inline-html',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: 'Element: img',
|
||||
errorRange: [
|
||||
10,
|
||||
41,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 369,
|
||||
ruleDescription: 'Inline HTML',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033',
|
||||
ruleNames: [
|
||||
'MD033',
|
||||
'no-inline-html',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: null,
|
||||
errorDetail: 'Element: p',
|
||||
errorRange: [
|
||||
10,
|
||||
24,
|
||||
],
|
||||
fixInfo: null,
|
||||
lineNumber: 371,
|
||||
ruleDescription: 'Inline HTML',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md033',
|
||||
ruleNames: [
|
||||
'MD033',
|
||||
'no-inline-html',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '* emphasis *',
|
||||
errorDetail: null,
|
||||
|
|
@ -38582,6 +38662,66 @@ Generated by [AVA](https://avajs.dev).
|
|||
'no-space-in-emphasis',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '* HTML *',
|
||||
errorDetail: null,
|
||||
errorRange: [
|
||||
20,
|
||||
8,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 8,
|
||||
editColumn: 20,
|
||||
insertText: '*HTML*',
|
||||
},
|
||||
lineNumber: 361,
|
||||
ruleDescription: 'Spaces inside emphasis markers',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md037',
|
||||
ruleNames: [
|
||||
'MD037',
|
||||
'no-space-in-emphasis',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '* HTML *',
|
||||
errorDetail: null,
|
||||
errorRange: [
|
||||
17,
|
||||
8,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 8,
|
||||
editColumn: 17,
|
||||
insertText: '*HTML*',
|
||||
},
|
||||
lineNumber: 364,
|
||||
ruleDescription: 'Spaces inside emphasis markers',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md037',
|
||||
ruleNames: [
|
||||
'MD037',
|
||||
'no-space-in-emphasis',
|
||||
],
|
||||
},
|
||||
{
|
||||
errorContext: '* HTML *',
|
||||
errorDetail: null,
|
||||
errorRange: [
|
||||
34,
|
||||
8,
|
||||
],
|
||||
fixInfo: {
|
||||
deleteCount: 8,
|
||||
editColumn: 34,
|
||||
insertText: '*HTML*',
|
||||
},
|
||||
lineNumber: 371,
|
||||
ruleDescription: 'Spaces inside emphasis markers',
|
||||
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md037',
|
||||
ruleNames: [
|
||||
'MD037',
|
||||
'no-space-in-emphasis',
|
||||
],
|
||||
},
|
||||
],
|
||||
fixed: `# Heading␊
|
||||
␊
|
||||
|
|
@ -38942,6 +39082,18 @@ Generated by [AVA](https://avajs.dev).
|
|||
_~/.ssh/id_rsa_ and _emphasis_␊
|
||||
␊
|
||||
Partial *em*phasis of a *wo*rd.␊
|
||||
␊
|
||||
Emphasis <b>inside *HTML* content</b> {MD033} {MD037}␊
|
||||
␊
|
||||
<p> {MD033}␊
|
||||
Emphasis inside *HTML* content {MD037}␊
|
||||
</p>␊
|
||||
␊
|
||||
Emphasis <p data="inside * attribute * content"></p> {MD033}␊
|
||||
␊
|
||||
Emphasis <img alt="inside * attribute * content"/> {MD033}␊
|
||||
␊
|
||||
Emphasis <p data="* attribute *">*HTML*</p> {MD033} {MD037}␊
|
||||
`,
|
||||
}
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -357,3 +357,15 @@ some_snake_case_function() is _called_
|
|||
_~/.ssh/id_rsa_ and _emphasis_
|
||||
|
||||
Partial *em*phasis of a *wo*rd.
|
||||
|
||||
Emphasis <b>inside * HTML * content</b> {MD033} {MD037}
|
||||
|
||||
<p> {MD033}
|
||||
Emphasis inside * HTML * content {MD037}
|
||||
</p>
|
||||
|
||||
Emphasis <p data="inside * attribute * content"></p> {MD033}
|
||||
|
||||
Emphasis <img alt="inside * attribute * content"/> {MD033}
|
||||
|
||||
Emphasis <p data="* attribute *">* HTML *</p> {MD033} {MD037}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue