How to use markdownlint-rule-helpers - 5 common examples

To help you get started, we’ve selected a few markdownlint-rule-helpers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DavidAnson / markdownlint / test / rules / any-blockquote.js View on Github external
"function": (params, onError) => {
    filterTokens(params, "blockquote_open", (blockquote) => {
      const lines = blockquote.map[1] - blockquote.map[0];
      onError({
        "lineNumber": blockquote.lineNumber,
        "detail": "Blockquote spans " + lines + " line(s).",
        "context": blockquote.line.substr(0, 7)
      });
    });
  }
};
github DavidAnson / markdownlint / test / rules / every-n-lines.js View on Github external
"function": (params, onError) => {
    const n = params.config.n || 2;
    forEachLine(getLineMetadata(params), (line, lineIndex) => {
      const lineNumber = lineIndex + 1;
      if ((lineNumber % n) === 0) {
        onError({
          "lineNumber": lineNumber,
          "detail": "Line number " + lineNumber
        });
      }
    });
  }
};
github DavidAnson / vscode-markdownlint / extension.js View on Github external
return new Promise((resolve, reject) => {
		const editor = vscode.window.activeTextEditor;
		if (editor) {
			const document = editor.document;
			if (isMarkdownDocument(document)) {
				const name = document.uri.toString();
				const text = document.getText();
				const {config} = getConfig(document);
				const errors = markdownlintWrapper(name, text, config);
				const fixedText = markdownlintRuleHelpers.applyFixes(text, errors);
				if (text !== fixedText) {
					return editor.edit((editBuilder) => {
						const start = document.lineAt(0).range.start;
						const end = document.lineAt(document.lineCount - 1).range.end;
						editBuilder.replace(new vscode.Range(start, end), fixedText);
					}).then(resolve, reject);
				}
			}
		}
		return resolve();
	});
}
github DavidAnson / vscode-markdownlint / extension.js View on Github external
return new Promise((resolve, reject) => {
		const editor = vscode.window.activeTextEditor;
		if (editor && fixInfo) {
			const document = editor.document;
			const lineNumber = fixInfo.lineNumber || (lineIndex + 1);
			const {text, range} = document.lineAt(lineNumber - 1);
			const fixedText = markdownlintRuleHelpers.applyFix(text, fixInfo, "\n");
			return editor.edit((editBuilder) => {
				if (typeof fixedText === "string") {
					editBuilder.replace(range, fixedText);
				} else {
					let deleteRange = range;
					if (lineNumber === 1) {
						if (document.lineCount > 1) {
							const nextLine = document.lineAt(range.end.line + 1);
							deleteRange = range.with({"end": nextLine.range.start});
						}
					} else {
						const previousLine = document.lineAt(range.start.line - 1);
						deleteRange = range.with({"start": previousLine.range.end});
					}
					editBuilder.delete(deleteRange);
				}
github igorshubovych / markdownlint-cli / markdownlint.js View on Github external
files.forEach(file => {
      fixOptions.files = [file];
      const fixResult = markdownlint.sync(fixOptions);
      const fixes = fixResult[file].filter(error => error.fixInfo);
      if (fixes.length > 0) {
        const originalText = fs.readFileSync(file, fsOptions);
        const fixedText = markdownlintRuleHelpers.applyFixes(originalText, fixes);
        if (originalText !== fixedText) {
          fs.writeFileSync(file, fixedText, fsOptions);
        }
      }
    });
  }

markdownlint-rule-helpers

A collection of markdownlint helper functions for custom rules

MIT
Latest version published 14 days ago

Package Health Score

88 / 100
Full package analysis