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

Replace old cwd option with configPath for mjmlconfig support #29

Merged
merged 3 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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);
Expand Down