mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-17 06:20:12 +01:00
Refactor helpers.emphasisMarkersInContent slightly to avoid duplicate/unnecessary work.
This commit is contained in:
parent
11806dc5cb
commit
a508824b0f
3 changed files with 34 additions and 34 deletions
|
|
@ -632,6 +632,18 @@ module.exports.frontMatterHasTitle =
|
|||
function emphasisMarkersInContent(params) {
|
||||
const { lines } = params;
|
||||
const byLine = new Array(lines.length);
|
||||
// Search links
|
||||
lines.forEach((tokenLine, tokenLineIndex) => {
|
||||
const inLine = [];
|
||||
let linkMatch = null;
|
||||
while ((linkMatch = linkRe.exec(tokenLine))) {
|
||||
let markerMatch = null;
|
||||
while ((markerMatch = emphasisMarkersRe.exec(linkMatch[0]))) {
|
||||
inLine.push(linkMatch.index + markerMatch.index);
|
||||
}
|
||||
}
|
||||
byLine[tokenLineIndex] = inLine;
|
||||
});
|
||||
// Search code spans
|
||||
filterTokens(params, "inline", (token) => {
|
||||
const { children, lineNumber, map } = token;
|
||||
|
|
@ -642,31 +654,19 @@ function emphasisMarkersInContent(params) {
|
|||
(code, lineIndex, column, tickCount) => {
|
||||
const codeLines = code.split(newLineRe);
|
||||
codeLines.forEach((codeLine, codeLineIndex) => {
|
||||
const byLineIndex = lineNumber - 1 + lineIndex + codeLineIndex;
|
||||
const inLine = byLine[byLineIndex];
|
||||
const codeLineOffset = codeLineIndex ? 0 : column - 1 + tickCount;
|
||||
let match = null;
|
||||
while ((match = emphasisMarkersRe.exec(codeLine))) {
|
||||
const byLineIndex = lineNumber - 1 + lineIndex + codeLineIndex;
|
||||
const inLine = byLine[byLineIndex] || [];
|
||||
const codeLineOffset = codeLineIndex ? 0 : column - 1 + tickCount;
|
||||
inLine.push(codeLineOffset + match.index);
|
||||
byLine[byLineIndex] = inLine;
|
||||
}
|
||||
byLine[byLineIndex] = inLine;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
// Search links
|
||||
lines.forEach((tokenLine, tokenLineIndex) => {
|
||||
let linkMatch = null;
|
||||
while ((linkMatch = linkRe.exec(tokenLine))) {
|
||||
let markerMatch = null;
|
||||
while ((markerMatch = emphasisMarkersRe.exec(linkMatch[0]))) {
|
||||
const inLine = byLine[tokenLineIndex] || [];
|
||||
inLine.push(linkMatch.index + markerMatch.index);
|
||||
byLine[tokenLineIndex] = inLine;
|
||||
}
|
||||
}
|
||||
});
|
||||
return byLine;
|
||||
}
|
||||
module.exports.emphasisMarkersInContent = emphasisMarkersInContent;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue