mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-28 11:38:48 +01:00
Add includesSorted function, use for faster searches of sorted arrays.
This commit is contained in:
parent
d7c0d195d7
commit
9b9532e163
8 changed files with 86 additions and 50 deletions
|
|
@ -3,13 +3,14 @@
|
|||
"use strict";
|
||||
|
||||
const shared = require("./shared");
|
||||
const { addErrorContext, forEachInlineChild } = shared;
|
||||
|
||||
module.exports = {
|
||||
"names": [ "MD037", "no-space-in-emphasis" ],
|
||||
"description": "Spaces inside emphasis markers",
|
||||
"tags": [ "whitespace", "emphasis" ],
|
||||
"function": function MD037(params, onError) {
|
||||
shared.forEachInlineChild(params, "text", function forToken(token) {
|
||||
forEachInlineChild(params, "text", (token) => {
|
||||
let left = true;
|
||||
let match = /(?:^|\s)(\*\*?|__?)\s.*[^\\]\1/.exec(token.content);
|
||||
if (!match) {
|
||||
|
|
@ -19,11 +20,11 @@ module.exports = {
|
|||
if (match) {
|
||||
const fullText = match[0];
|
||||
const line = params.lines[token.lineNumber - 1];
|
||||
if (line.indexOf(fullText) !== -1) {
|
||||
if (line.includes(fullText)) {
|
||||
const text = fullText.trim();
|
||||
const column = line.indexOf(text) + 1;
|
||||
const length = text.length;
|
||||
shared.addErrorContext(onError, token.lineNumber,
|
||||
addErrorContext(onError, token.lineNumber,
|
||||
text, left, !left, [ column, length ]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue