Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

Commit

Permalink
Merge pull request #29 from jskrzypek/mjmlconfig-support-v4
Browse files Browse the repository at this point in the history
Replace old cwd option with configPath for mjmlconfig support
  • Loading branch information
attilabuti authored Sep 27, 2018
2 parents 5e4335e + 483ccf5 commit 9085580
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
15 changes: 6 additions & 9 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -37,26 +37,23 @@ 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,
cwd: this.getCWD(mjmlPath)
configPath: this.getCWD(mjmlPath)
});

if (html) {
return html;
}
}
catch (err) {
return;
return { html: '', errors: [err] };
}
}

Expand Down
9 changes: 2 additions & 7 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import * as vscode from "vscode";

import mjml2html = require("mjml");

import helper from "./helper";

export default class MJMLLintingProvider {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,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);
Expand Down

0 comments on commit 9085580

Please sign in to comment.