mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 22:10:13 +01:00
Move single use, not explicitly tested helpers into the file that uses them.
This commit is contained in:
parent
df70ea5989
commit
c5d4a3297f
5 changed files with 72 additions and 84 deletions
|
|
@ -33,10 +33,6 @@ const inlineCommentStartRe =
|
||||||
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gi;
|
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gi;
|
||||||
module.exports.inlineCommentStartRe = inlineCommentStartRe;
|
module.exports.inlineCommentStartRe = inlineCommentStartRe;
|
||||||
|
|
||||||
// Regular expression for link reference definitions
|
|
||||||
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
|
|
||||||
module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe;
|
|
||||||
|
|
||||||
// Regular expression for identifying an HTML entity at the end of a line
|
// Regular expression for identifying an HTML entity at the end of a line
|
||||||
module.exports.endOfLineHtmlEntityRe =
|
module.exports.endOfLineHtmlEntityRe =
|
||||||
/&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/;
|
/&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/;
|
||||||
|
|
@ -234,38 +230,6 @@ module.exports.escapeForRegExp = function escapeForRegExp(str) {
|
||||||
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the string representation of a fence markup character.
|
|
||||||
*
|
|
||||||
* @param {string} markup Fence string.
|
|
||||||
* @returns {string} String representation.
|
|
||||||
*/
|
|
||||||
module.exports.fencedCodeBlockStyleFor =
|
|
||||||
function fencedCodeBlockStyleFor(markup) {
|
|
||||||
switch (markup[0]) {
|
|
||||||
case "~":
|
|
||||||
return "tilde";
|
|
||||||
default:
|
|
||||||
return "backtick";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the string representation of a emphasis or strong markup character.
|
|
||||||
*
|
|
||||||
* @param {string} markup Emphasis or strong string.
|
|
||||||
* @returns {"asterisk" | "underscore"} String representation.
|
|
||||||
*/
|
|
||||||
module.exports.emphasisOrStrongStyleFor =
|
|
||||||
function emphasisOrStrongStyleFor(markup) {
|
|
||||||
switch (markup[0]) {
|
|
||||||
case "*":
|
|
||||||
return "asterisk";
|
|
||||||
default:
|
|
||||||
return "underscore";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds ellipsis to the left/right/middle of the specified text.
|
* Adds ellipsis to the left/right/middle of the specified text.
|
||||||
*
|
*
|
||||||
|
|
@ -388,13 +352,12 @@ const positionLessThanOrEqual = (lineA, columnA, lineB, columnB) => (
|
||||||
* @param {FileRange|import("../lib/markdownlint.js").MicromarkToken} rangeB Range B.
|
* @param {FileRange|import("../lib/markdownlint.js").MicromarkToken} rangeB Range B.
|
||||||
* @returns {boolean} True iff the two ranges overlap.
|
* @returns {boolean} True iff the two ranges overlap.
|
||||||
*/
|
*/
|
||||||
const hasOverlap = (rangeA, rangeB) => {
|
module.exports.hasOverlap = function hasOverlap(rangeA, rangeB) {
|
||||||
const lte = positionLessThanOrEqual(rangeA.startLine, rangeA.startColumn, rangeB.startLine, rangeB.startColumn);
|
const lte = positionLessThanOrEqual(rangeA.startLine, rangeA.startColumn, rangeB.startLine, rangeB.startColumn);
|
||||||
const first = lte ? rangeA : rangeB;
|
const first = lte ? rangeA : rangeB;
|
||||||
const second = lte ? rangeB : rangeA;
|
const second = lte ? rangeB : rangeA;
|
||||||
return positionLessThanOrEqual(second.startLine, second.startColumn, first.endLine, first.endColumn);
|
return positionLessThanOrEqual(second.startLine, second.startColumn, first.endLine, first.endColumn);
|
||||||
};
|
};
|
||||||
module.exports.hasOverlap = hasOverlap;
|
|
||||||
|
|
||||||
// Determines if the front matter includes a title
|
// Determines if the front matter includes a title
|
||||||
module.exports.frontMatterHasTitle =
|
module.exports.frontMatterHasTitle =
|
||||||
|
|
@ -6092,10 +6055,25 @@ module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const { addErrorDetailIf, fencedCodeBlockStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
const { addErrorDetailIf } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||||
const { getDescendantsByType } = __webpack_require__(/*! ../helpers/micromark-helpers.cjs */ "../helpers/micromark-helpers.cjs");
|
const { getDescendantsByType } = __webpack_require__(/*! ../helpers/micromark-helpers.cjs */ "../helpers/micromark-helpers.cjs");
|
||||||
const { filterByTypesCached } = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
const { filterByTypesCached } = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the string representation of a fence markup character.
|
||||||
|
*
|
||||||
|
* @param {string} markup Fence string.
|
||||||
|
* @returns {"tilde" | "backtick"} String representation.
|
||||||
|
*/
|
||||||
|
function fencedCodeBlockStyleFor(markup) {
|
||||||
|
switch (markup[0]) {
|
||||||
|
case "~":
|
||||||
|
return "tilde";
|
||||||
|
default:
|
||||||
|
return "backtick";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line jsdoc/valid-types
|
// eslint-disable-next-line jsdoc/valid-types
|
||||||
/** @type import("./markdownlint").Rule */
|
/** @type import("./markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
@ -6138,11 +6116,26 @@ module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const { addError, emphasisOrStrongStyleFor } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
const { addError } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||||
const { filterByPredicate, getDescendantsByType } = __webpack_require__(/*! ../helpers/micromark-helpers.cjs */ "../helpers/micromark-helpers.cjs");
|
const { filterByPredicate, getDescendantsByType } = __webpack_require__(/*! ../helpers/micromark-helpers.cjs */ "../helpers/micromark-helpers.cjs");
|
||||||
|
|
||||||
const intrawordRe = /^\w$/;
|
const intrawordRe = /^\w$/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the string representation of a emphasis or strong markup character.
|
||||||
|
*
|
||||||
|
* @param {string} markup Emphasis or strong string.
|
||||||
|
* @returns {"asterisk" | "underscore"} String representation.
|
||||||
|
*/
|
||||||
|
function emphasisOrStrongStyleFor(markup) {
|
||||||
|
switch (markup[0]) {
|
||||||
|
case "*":
|
||||||
|
return "asterisk";
|
||||||
|
default:
|
||||||
|
return "underscore";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import("./markdownlint").RuleParams} params Rule parameters.
|
* @param {import("./markdownlint").RuleParams} params Rule parameters.
|
||||||
* @param {import("./markdownlint").RuleOnError} onError Error-reporting callback.
|
* @param {import("./markdownlint").RuleOnError} onError Error-reporting callback.
|
||||||
|
|
@ -6486,10 +6479,11 @@ module.exports = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const { addError, ellipsify, linkReferenceDefinitionRe } =
|
const { addError, ellipsify } = __webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
||||||
__webpack_require__(/*! ../helpers */ "../helpers/helpers.js");
|
|
||||||
const { getReferenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
const { getReferenceLinkImageData } = __webpack_require__(/*! ./cache */ "../lib/cache.js");
|
||||||
|
|
||||||
|
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
|
||||||
|
|
||||||
// eslint-disable-next-line jsdoc/valid-types
|
// eslint-disable-next-line jsdoc/valid-types
|
||||||
/** @type import("./markdownlint").Rule */
|
/** @type import("./markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,6 @@ const inlineCommentStartRe =
|
||||||
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gi;
|
/(<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gi;
|
||||||
module.exports.inlineCommentStartRe = inlineCommentStartRe;
|
module.exports.inlineCommentStartRe = inlineCommentStartRe;
|
||||||
|
|
||||||
// Regular expression for link reference definitions
|
|
||||||
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
|
|
||||||
module.exports.linkReferenceDefinitionRe = linkReferenceDefinitionRe;
|
|
||||||
|
|
||||||
// Regular expression for identifying an HTML entity at the end of a line
|
// Regular expression for identifying an HTML entity at the end of a line
|
||||||
module.exports.endOfLineHtmlEntityRe =
|
module.exports.endOfLineHtmlEntityRe =
|
||||||
/&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/;
|
/&(?:#\d+|#[xX][\da-fA-F]+|[a-zA-Z]{2,31}|blk\d{2}|emsp1[34]|frac\d{2}|sup\d|there4);$/;
|
||||||
|
|
@ -222,38 +218,6 @@ module.exports.escapeForRegExp = function escapeForRegExp(str) {
|
||||||
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&");
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the string representation of a fence markup character.
|
|
||||||
*
|
|
||||||
* @param {string} markup Fence string.
|
|
||||||
* @returns {string} String representation.
|
|
||||||
*/
|
|
||||||
module.exports.fencedCodeBlockStyleFor =
|
|
||||||
function fencedCodeBlockStyleFor(markup) {
|
|
||||||
switch (markup[0]) {
|
|
||||||
case "~":
|
|
||||||
return "tilde";
|
|
||||||
default:
|
|
||||||
return "backtick";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return the string representation of a emphasis or strong markup character.
|
|
||||||
*
|
|
||||||
* @param {string} markup Emphasis or strong string.
|
|
||||||
* @returns {"asterisk" | "underscore"} String representation.
|
|
||||||
*/
|
|
||||||
module.exports.emphasisOrStrongStyleFor =
|
|
||||||
function emphasisOrStrongStyleFor(markup) {
|
|
||||||
switch (markup[0]) {
|
|
||||||
case "*":
|
|
||||||
return "asterisk";
|
|
||||||
default:
|
|
||||||
return "underscore";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds ellipsis to the left/right/middle of the specified text.
|
* Adds ellipsis to the left/right/middle of the specified text.
|
||||||
*
|
*
|
||||||
|
|
@ -376,13 +340,12 @@ const positionLessThanOrEqual = (lineA, columnA, lineB, columnB) => (
|
||||||
* @param {FileRange|import("../lib/markdownlint.js").MicromarkToken} rangeB Range B.
|
* @param {FileRange|import("../lib/markdownlint.js").MicromarkToken} rangeB Range B.
|
||||||
* @returns {boolean} True iff the two ranges overlap.
|
* @returns {boolean} True iff the two ranges overlap.
|
||||||
*/
|
*/
|
||||||
const hasOverlap = (rangeA, rangeB) => {
|
module.exports.hasOverlap = function hasOverlap(rangeA, rangeB) {
|
||||||
const lte = positionLessThanOrEqual(rangeA.startLine, rangeA.startColumn, rangeB.startLine, rangeB.startColumn);
|
const lte = positionLessThanOrEqual(rangeA.startLine, rangeA.startColumn, rangeB.startLine, rangeB.startColumn);
|
||||||
const first = lte ? rangeA : rangeB;
|
const first = lte ? rangeA : rangeB;
|
||||||
const second = lte ? rangeB : rangeA;
|
const second = lte ? rangeB : rangeA;
|
||||||
return positionLessThanOrEqual(second.startLine, second.startColumn, first.endLine, first.endColumn);
|
return positionLessThanOrEqual(second.startLine, second.startColumn, first.endLine, first.endColumn);
|
||||||
};
|
};
|
||||||
module.exports.hasOverlap = hasOverlap;
|
|
||||||
|
|
||||||
// Determines if the front matter includes a title
|
// Determines if the front matter includes a title
|
||||||
module.exports.frontMatterHasTitle =
|
module.exports.frontMatterHasTitle =
|
||||||
|
|
|
||||||
17
lib/md048.js
17
lib/md048.js
|
|
@ -2,10 +2,25 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addErrorDetailIf, fencedCodeBlockStyleFor } = require("../helpers");
|
const { addErrorDetailIf } = require("../helpers");
|
||||||
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
const { getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
||||||
const { filterByTypesCached } = require("./cache");
|
const { filterByTypesCached } = require("./cache");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the string representation of a fence markup character.
|
||||||
|
*
|
||||||
|
* @param {string} markup Fence string.
|
||||||
|
* @returns {"tilde" | "backtick"} String representation.
|
||||||
|
*/
|
||||||
|
function fencedCodeBlockStyleFor(markup) {
|
||||||
|
switch (markup[0]) {
|
||||||
|
case "~":
|
||||||
|
return "tilde";
|
||||||
|
default:
|
||||||
|
return "backtick";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line jsdoc/valid-types
|
// eslint-disable-next-line jsdoc/valid-types
|
||||||
/** @type import("./markdownlint").Rule */
|
/** @type import("./markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,26 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addError, emphasisOrStrongStyleFor } = require("../helpers");
|
const { addError } = require("../helpers");
|
||||||
const { filterByPredicate, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
const { filterByPredicate, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
|
||||||
|
|
||||||
const intrawordRe = /^\w$/;
|
const intrawordRe = /^\w$/;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the string representation of a emphasis or strong markup character.
|
||||||
|
*
|
||||||
|
* @param {string} markup Emphasis or strong string.
|
||||||
|
* @returns {"asterisk" | "underscore"} String representation.
|
||||||
|
*/
|
||||||
|
function emphasisOrStrongStyleFor(markup) {
|
||||||
|
switch (markup[0]) {
|
||||||
|
case "*":
|
||||||
|
return "asterisk";
|
||||||
|
default:
|
||||||
|
return "underscore";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {import("./markdownlint").RuleParams} params Rule parameters.
|
* @param {import("./markdownlint").RuleParams} params Rule parameters.
|
||||||
* @param {import("./markdownlint").RuleOnError} onError Error-reporting callback.
|
* @param {import("./markdownlint").RuleOnError} onError Error-reporting callback.
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const { addError, ellipsify, linkReferenceDefinitionRe } =
|
const { addError, ellipsify } = require("../helpers");
|
||||||
require("../helpers");
|
|
||||||
const { getReferenceLinkImageData } = require("./cache");
|
const { getReferenceLinkImageData } = require("./cache");
|
||||||
|
|
||||||
|
const linkReferenceDefinitionRe = /^ {0,3}\[([^\]]*[^\\])\]:/;
|
||||||
|
|
||||||
// eslint-disable-next-line jsdoc/valid-types
|
// eslint-disable-next-line jsdoc/valid-types
|
||||||
/** @type import("./markdownlint").Rule */
|
/** @type import("./markdownlint").Rule */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue