2018-01-21 21:44:25 -08:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const shared = require("./shared");
|
2018-01-21 21:44:25 -08:00
|
|
|
|
2018-04-27 22:05:34 -07:00
|
|
|
const inlineCodeSpansRe = /(?:^|[^\\])((`+)((?:.*?[^`])|)\2(?!`))/g;
|
2018-01-21 21:44:25 -08:00
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
"names": [ "MD038", "no-space-in-code" ],
|
|
|
|
|
"description": "Spaces inside code span elements",
|
|
|
|
|
"tags": [ "whitespace", "code" ],
|
|
|
|
|
"function": function MD038(params, onError) {
|
|
|
|
|
shared.forEachInlineChild(params, "code_inline",
|
|
|
|
|
function forToken(token) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const line = params.lines[token.lineNumber - 1];
|
|
|
|
|
let match = null;
|
2018-01-21 21:44:25 -08:00
|
|
|
while ((match = inlineCodeSpansRe.exec(line)) !== null) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const inlineCodeSpan = match[1];
|
|
|
|
|
const content = match[3];
|
|
|
|
|
const length = inlineCodeSpan.length;
|
|
|
|
|
const column = match.index + 1 + (match[0].length - length);
|
|
|
|
|
const range = [ column, length ];
|
2018-01-21 21:44:25 -08:00
|
|
|
if (/^\s([^`]|$)/.test(content)) {
|
|
|
|
|
shared.addErrorContext(onError, token.lineNumber,
|
|
|
|
|
inlineCodeSpan, true, false, range);
|
|
|
|
|
} else if (/[^`]\s$/.test(content)) {
|
|
|
|
|
shared.addErrorContext(onError, token.lineNumber,
|
|
|
|
|
inlineCodeSpan, false, true, range);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|