From 233e3857566d592940347e03a2ff0214343b6802 Mon Sep 17 00:00:00 2001 From: Joshua Estrin Skrzypek Date: Mon, 21 May 2018 17:21:43 +0300 Subject: [PATCH 1/3] Replace old cwd option with configPath for mjmlconfig support --- src/helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper.ts b/src/helper.ts index 302fdc1..2fe2053 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -48,7 +48,7 @@ export default class Helper { minify: minify, beautify: beautify, filePath: mjmlPath, - cwd: this.getCWD(mjmlPath) + configPath: this.getCWD(mjmlPath) }); if (html) { From c1e32b414a39aacbee9bd6c7e12e1fd1547337a4 Mon Sep 17 00:00:00 2001 From: Joshua Estrin Skrzypek Date: Mon, 21 May 2018 17:54:45 +0300 Subject: [PATCH 2/3] Refactor helper.mjml2html to return errors for linter --- src/helper.ts | 11 ++++------- src/linter.ts | 9 ++------- src/preview.ts | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/helper.ts b/src/helper.ts index 2fe2053..2ab457f 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -19,7 +19,7 @@ export default class Helper { vscode.window.activeTextEditor.document.getText(), minify != undefined ? minify : vscode.workspace.getConfiguration("mjml").minifyHtmlOutput, beautify != undefined ? beautify : vscode.workspace.getConfiguration("mjml").beautifyHtmlOutput, - ); + ).html; if (content) { if (fixLinks != undefined && fixLinks) { @@ -37,23 +37,20 @@ export default class Helper { return document.languageId === "mjml" && document.uri.scheme !== "mjml-preview"; } - static mjml2html(mjml: string, minify: boolean, beautify: boolean, mjmlPath?: string): string { + static mjml2html(mjml: string, minify: boolean, beautify: boolean, mjmlPath?: string, level: 'skip' | 'strict' | 'ignore' = 'skip' ): { html: string, errors: any[] } { try { if (!mjmlPath) { mjmlPath = this.getPath(); } - let { html, errors } = mjml2html(mjml, { - level: "skip", + return mjml2html(mjml, { + level: level, minify: minify, beautify: beautify, filePath: mjmlPath, configPath: this.getCWD(mjmlPath) }); - if (html) { - return html; - } } catch (err) { return; diff --git a/src/linter.ts b/src/linter.ts index cd000ef..649eb52 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -2,8 +2,6 @@ import * as vscode from "vscode"; -import mjml2html = require("mjml"); - import helper from "./helper"; export default class MJMLLintingProvider { @@ -53,11 +51,8 @@ export default class MJMLLintingProvider { let diagnostics: vscode.Diagnostic[] = []; try { - let { html, errors } = mjml2html(vscode.window.activeTextEditor.document.getText(), { - level: "strict", - filePath: vscode.window.activeTextEditor.document.uri.fsPath, - cwd: helper.getCWD() - }); + let filePath = helper.getPath(); + let { html, errors } = helper.mjml2html(vscode.window.activeTextEditor.document.getText(), false, false, filePath, "strict"); errors.forEach((err: any) => { let line: number = err.line - 1; diff --git a/src/preview.ts b/src/preview.ts index c5d2ae3..c74a8be 100644 --- a/src/preview.ts +++ b/src/preview.ts @@ -216,7 +216,7 @@ class PreviewContentProvider implements vscode.TextDocumentContentProvider { } private renderMJML(): string { - let html: string = helper.mjml2html(this.document.getText(), false, false, this.document.uri.fsPath); + let html: string = helper.mjml2html(this.document.getText(), false, false, this.document.uri.fsPath).html; if (html) { return helper.fixLinks(html, this.document.uri.fsPath); From 483ccf56669d6cc900e52c3140e770cbfe345f6e Mon Sep 17 00:00:00 2001 From: Joshua Estrin Skrzypek Date: Tue, 22 May 2018 12:58:09 +0300 Subject: [PATCH 3/3] Return empty html & errors when mjml2html throws --- src/helper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helper.ts b/src/helper.ts index 2ab457f..7b0135f 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -53,7 +53,7 @@ export default class Helper { } catch (err) { - return; + return { html: '', errors: [err] }; } }