var vscode = require("vscode");
var markdownlint = require("markdownlint");
var opn = require("opn");
var packageJson = require("./package.json");
var defaultConfig = require("./default-config.json");

var extensionName = packageJson.name;
var openLinkCommandName = extensionName + ".openLink";
var markdownLanguageId = "markdown";
var markdownlintRulesMd = "https://github.com/DavidAnson/markdownlint/blob/master/doc/Rules.md";
var codeActionPrefix = "Click for more information about ";
var newLineRe = /\r\n|\r|\n/;
var resultLineRe = /^document: (\d+): (MD\d\d\d) (.*)$/;
var diagnosticCollection = null;

function lint(document) {
	if (document.languageId !== markdownLanguageId) {
		return;
	}

	var options = {
		"strings": {
			"document": document.getText()
		},
		"config": defaultConfig
	};
	var diagnostics = [];

	markdownlint
		.sync(options)
		.toString()
		.split(newLineRe)
		.forEach(function forLine(line) {
			var match = line.match(resultLineRe);
			if (match) {
				var lineNumber = parseInt(match[1], 10) - 1;
				var rule = match[2];
				var description = match[3];
				var message = rule + ": " + description;
				var diagnostic = new vscode.Diagnostic(document.lineAt(lineNumber).range, message, 1 /* Warning */);
				diagnostic.code = markdownlintRulesMd + "#" + rule.toLowerCase() + "---" + description.toLowerCase().replace(/ /g, "-");
				diagnostics.push(diagnostic);
			}
		});

	diagnosticCollection.set(document.uri, diagnostics);
}

function provideCodeActions(document, range, codeActionContext) {
	var diagnostics = codeActionContext.diagnostics || [];
	return diagnostics.map(function forDiagnostic(diagnostic) {
		return {
			title: codeActionPrefix + diagnostic.message.substr(0, 5),
			command: openLinkCommandName,
			arguments: [ diagnostic.code ]
		}
	});
}

function didOpenTextDocument(document) {
	lint(document);
}

function didChangeTextDocument(change) {
	lint(change.document);
}

function openLink(link) {
	opn(link);
}

function activate(context) {
	context.subscriptions.push(vscode.workspace.onDidOpenTextDocument(didOpenTextDocument));
	context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(didChangeTextDocument));
	context.subscriptions.push(vscode.commands.registerCommand(openLinkCommandName, openLink));
	context.subscriptions.push(vscode.languages.registerCodeActionsProvider(markdownLanguageId, {
		provideCodeActions: provideCodeActions
	}));
	diagnosticCollection = vscode.languages.createDiagnosticCollection(extensionName);
	context.subscriptions.push(diagnosticCollection);
}

exports.activate = activate;

@@ -91,24 +91,76 @@
 ire(%22opn%22);%0A
+var fs = require(%22fs%22);%0Avar path = require(%22path%22);%0A
 var packageJ
@@ -188,24 +188,24 @@
 age.json%22);%0A
-
 var defaultC
@@ -340,16 +340,59 @@
 nLink%22;%0A
+var configFileName = %22.markdownlint.json%22;%0A
 var mark
@@ -577,16 +577,70 @@
 bout %22;%0A
+var badConfig = %22Unable to read configuration file %22;%0A
 var newL
@@ -750,16 +750,41 @@
  = null;
+%0Avar customConfig = null;
 %0A%0Afuncti
@@ -950,16 +950,32 @@
 config%22:
+ customConfig %7C%7C
  default
@@ -1982,24 +1982,441 @@
 %09%09%7D%0A%09%7D);%0A%7D%0A%0A
+function loadCustomConfig() %7B%0A%09var rootPath = vscode.workspace.rootPath;%0A%09if (rootPath) %7B%0A%09%09var configFilePath = path.join(rootPath, configFileName);%0A%09%09if (fs.existsSync(configFilePath)) %7B%0A%09%09%09try %7B%0A%09%09%09%09customConfig = JSON.parse(fs.readFileSync(configFilePath, %22utf8%22));%0A%09%09%09%7D catch(e) %7B%0A%09%09%09%09vscode.window.showWarningMessage(badConfig + %22'%22 + configFilePath + %22' (%22 + (e.message %7C%7C e.toString()) + %22)%22);%0A%09%09%09%7D%0A%09%09%7D%0A%09%7D%0A%7D%0A%0A
 function did
@@ -3105,16 +3105,16 @@
 nName);%0A
-
 %09context
@@ -3156,16 +3156,37 @@
 ction);%0A
+%09loadCustomConfig();%0A
 %7D%0A%0Aexpor

Add static support for custom config file.