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
|
|
|
|
|
|
|
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) {
|
2018-04-27 22:05:34 -07:00
|
|
|
let left = true;
|
|
|
|
let match = /\s(\*\*?|__?)\s.+\1/.exec(token.content);
|
2018-01-21 21:44:25 -08:00
|
|
|
if (!match) {
|
|
|
|
left = false;
|
|
|
|
match = /(\*\*?|__?).+\s\1\s/.exec(token.content);
|
|
|
|
}
|
|
|
|
if (match) {
|
2018-04-27 22:05:34 -07:00
|
|
|
const text = match[0].trim();
|
|
|
|
const line = params.lines[token.lineNumber - 1];
|
|
|
|
const column = line.indexOf(text) + 1;
|
|
|
|
const length = text.length;
|
2018-01-21 21:44:25 -08:00
|
|
|
shared.addErrorContext(onError, token.lineNumber,
|
|
|
|
text, left, !left, [ column, length ]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|