From ecac8ecd8c32b4f227b97b95b125b9c4948f14c1 Mon Sep 17 00:00:00 2001 From: Attila Buti Date: Wed, 3 Oct 2018 12:46:00 +0200 Subject: [PATCH] Releasing 1.5.1 --- CHANGELOG.md | 4 ++ README.md | 4 ++ documentation/build.ts | 2 +- language-configuration.json | 41 +++++++++--------- package-lock.json | 51 ++++++++++------------ package.json | 84 +++++++++++++++++++++---------------- src/helper.ts | 21 +++++++++- 7 files changed, 120 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c83dbc2..f0cefaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to the "mjml" extension will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +### [1.5.1] (2018-10-03) +* [#41](https://github.com/attilabuti/vscode-mjml/issues/41): fixed preview issue. +* [#40](https://github.com/attilabuti/vscode-mjml/issues/40): fixed comment issue. + ### [1.5.0] (2018-09-28) * [new] Configuration property `mjml.previewBackgroundColor`: preview background color ([#39](https://github.com/attilabuti/vscode-mjml/issues/39)). * [new] Configuration property `mjml.showSaveDialog`: show the save as dialog instead of input box. diff --git a/README.md b/README.md index dda77df..0aec34c 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,10 @@ Please see the [Nodemailer](https://nodemailer.com) documentation for more infor ## Change Log +### [1.5.1] (2018-10-03) +* [#41](https://github.com/attilabuti/vscode-mjml/issues/41): fixed preview issue. +* [#40](https://github.com/attilabuti/vscode-mjml/issues/40): fixed comment issue. + ### [1.5.0] (2018-09-28) * [new] Configuration property `mjml.previewBackgroundColor`: preview background color ([#39](https://github.com/attilabuti/vscode-mjml/issues/39)). * [new] Configuration property `mjml.showSaveDialog`: show the save as dialog instead of input box. diff --git a/documentation/build.ts b/documentation/build.ts index 8f632c8..f176e8d 100644 --- a/documentation/build.ts +++ b/documentation/build.ts @@ -232,7 +232,7 @@ async function tryItLive(html: string): Promise { if (tryItLive.indexOf(match[2]) == -1) { let response = await fetch(match[1]); - let mjmlMatch = /"value":*?["']([\s\S]*?)["']*?}/gi.exec(await response.text()); + let mjmlMatch: RegExpExecArray = /"value":*?["']([\s\S]*?)["']*?"}/gi.exec(await response.text()); mjmlMatch[1].replace(/\\"/g, "\"").replace(/src="\/(assets\/img)\/(.*?)"/gi, "src=\"https://mjml.io/assets/img/$2\"").split("\\n").forEach((line) => { fs.appendFileSync(`./examples/${fileName}.mjml`, line.replace(/\\/g, "").toString() + "\n"); diff --git a/language-configuration.json b/language-configuration.json index aa25710..7496702 100644 --- a/language-configuration.json +++ b/language-configuration.json @@ -1,30 +1,33 @@ { "comments": { - // symbol used for single line comment. Remove this entry if your language does not support line comments - "lineComment": "//", - // symbols used for start and end a block comment. Remove this entry if your language does not support block comments - "blockComment": [ "/*", "*/" ] + "blockComment": [ "" ] }, - // symbols used as brackets "brackets": [ + [""], + ["<", ">"], ["{", "}"], - ["[", "]"], ["(", ")"] ], - // symbols that are auto closed when typing "autoClosingPairs": [ - ["{", "}"], - ["[", "]"], - ["(", ")"], - ["\"", "\""], - ["'", "'"] + { "open": "{", "close": "}"}, + { "open": "[", "close": "]"}, + { "open": "(", "close": ")" }, + { "open": "'", "close": "'" }, + { "open": "\"", "close": "\"" }, + { "open": "", "notIn": [ "comment", "string" ]} ], - // symbols that that can be used to surround a selection "surroundingPairs": [ - ["{", "}"], - ["[", "]"], - ["(", ")"], - ["\"", "\""], - ["'", "'"] - ] + { "open": "'", "close": "'" }, + { "open": "\"", "close": "\"" }, + { "open": "{", "close": "}"}, + { "open": "[", "close": "]"}, + { "open": "(", "close": ")" }, + { "open": "<", "close": ">" } + ], + "folding": { + "markers": { + "start": "^\\s*", + "end": "^\\s*" + } + } } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 909b067..ba29a05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vscode-mjml", - "version": "1.5.0", + "version": "1.5.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -43,9 +43,9 @@ "dev": true }, "@types/node": { - "version": "10.10.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-10.10.3.tgz", - "integrity": "sha512-dWk7F3b0m6uDLHero7tsnpAi9r2RGPQHGbb0/VCv7DPJRMFtk3RonY1/29vfJKnheRMBa7+uF+vunlg/mBGlxg==", + "version": "10.11.3", + "resolved": "https://registry.npmjs.org/@types/node/-/node-10.11.3.tgz", + "integrity": "sha512-3AvcEJAh9EMatxs+OxAlvAEs7OTy6AG94mcH1iqyVDwVVndekLxzwkWQ/Z4SDbY6GO2oyUXyWW8tQ4rENSSQVQ==", "dev": true }, "@types/nodemailer": { @@ -55,7 +55,7 @@ "dev": true, "requires": { "@types/events": "1.2.0", - "@types/node": "10.10.3" + "@types/node": "10.11.3" } }, "@types/npm": { @@ -64,7 +64,7 @@ "integrity": "sha512-McqGDdeT1tSMu8sPaL0ya7xBwojQYKGVwCrlPNBcaF+o+H4wLNH03nYRTfycU11Xdu8eziEb4cgdGmu4VF/NWA==", "dev": true, "requires": { - "@types/node": "10.10.3" + "@types/node": "10.11.3" } }, "@types/semver": { @@ -1158,11 +1158,6 @@ "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" }, - "file-url": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/file-url/-/file-url-2.0.2.tgz", - "integrity": "sha1-6VF4TXkJUSfTcTApqwY/QIGMoq4=" - }, "filename-regex": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/filename-regex/-/filename-regex-2.0.1.tgz", @@ -1324,7 +1319,7 @@ }, "get-stream": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", + "resolved": "http://registry.npmjs.org/get-stream/-/get-stream-3.0.0.tgz", "integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=" }, "get-uri": { @@ -3111,9 +3106,9 @@ "integrity": "sha512-OayFWziIxiHY8bCUyLX6sTpDH8Jsbp4FfYd1j1f7vZyfgkcOnAyM4oQR16f8a0s7Gl/viMGRey8eScYk4V4EZA==" }, "node-mailjet": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/node-mailjet/-/node-mailjet-3.2.1.tgz", - "integrity": "sha512-n8fO6NFdrttg2Ct6s266Jw7gFazqkC7e0FESHbvRfvTqam0nAF2yVkKKu1eRTXrVsBjTYmdCZ++ykyVYEO/Sxg==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/node-mailjet/-/node-mailjet-3.3.0.tgz", + "integrity": "sha512-kOs4ajsNrB7IdNfqSCjk8pO3hNuL6je64Aa5eScIQMHe7Gk/4G6k0/+3ywMvgT7wQW1UaRCDW1AMTYp5l688tg==", "requires": { "bluebird": "3.5.2", "json-bigint": "0.2.3", @@ -6236,7 +6231,7 @@ }, "kind-of": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", "integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ=", "dev": true } @@ -7038,25 +7033,25 @@ "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=" }, "spdx-correct": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.0.tgz", - "integrity": "sha512-N19o9z5cEyc8yQQPukRCZ9EUmb4HUpnrmaL/fxS2pBo2jbfcFRVuFZ/oFC+vZz0MNNk0h80iMn5/S6qGZOL5+g==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.0.1.tgz", + "integrity": "sha512-hxSPZbRZvSDuOvADntOElzJpenIR7wXJkuoUcUtS0erbgt2fgeaoPIYretfKpslMhfFDY4k0MZ2F5CUzhBsSvQ==", "requires": { "spdx-expression-parse": "3.0.0", "spdx-license-ids": "3.0.1" } }, "spdx-exceptions": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.1.0.tgz", - "integrity": "sha512-4K1NsmrlCU1JJgUrtgEeTVyfx8VaYea9J9LvARxhbHtVtohPs/gFGG5yy49beySjlIMhhXZ4QqujIZEfS4l6Cg==" + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.2.0.tgz", + "integrity": "sha512-2XQACfElKi9SlVb1CYadKDXvoajPgBVPn/gOQLrTvHdElaVhr7ZEbqJaRnJLVNeaI4cMEAgVCeBMKF6MWRDCRA==" }, "spdx-expression-parse": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.0.tgz", "integrity": "sha512-Yg6D3XpRD4kkOmTpdgbUiEJFKghJH03fiC1OPll5h/0sO6neh2jqRDVHOQ4o/LMea0tgCkbMgea5ip/e+MkWyg==", "requires": { - "spdx-exceptions": "2.1.0", + "spdx-exceptions": "2.2.0", "spdx-license-ids": "3.0.1" } }, @@ -7204,7 +7199,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "resolved": "http://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "requires": { "ansi-regex": "2.1.1" @@ -7465,9 +7460,9 @@ "optional": true }, "typescript": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.0.3.tgz", - "integrity": "sha512-kk80vLW9iGtjMnIv11qyxLqZm20UklzuR2tL0QAnDIygIUIemcZMxlMWudl9OOt76H3ntVzcTiddQ1/pAAJMYg==", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.1.1.tgz", + "integrity": "sha512-Veu0w4dTc/9wlWNf2jeRInNodKlcdLgemvPsrNpfu5Pq39sgfFjvIIgTsvUHCoLBnMhPoUA+tFxsXjU6VexVRQ==", "dev": true }, "uc.micro": { @@ -7631,7 +7626,7 @@ "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", "requires": { - "spdx-correct": "3.0.0", + "spdx-correct": "3.0.1", "spdx-expression-parse": "3.0.0" } }, diff --git a/package.json b/package.json index 61fc3ca..9f3f9cb 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-mjml", "displayName": "MJML", "description": "MJML preview, lint, compile for Visual Studio Code.", - "version": "1.5.0", + "version": "1.5.1", "publisher": "attilabuti", "license": "MIT", "readme": "README.md", @@ -189,7 +189,8 @@ } } }, - "commands": [{ + "commands": [ + { "command": "mjml.previewToSide", "title": "Open Preview to the Side", "category": "MJML", @@ -249,37 +250,47 @@ "category": "MJML" } ], - "languages": [{ - "id": "mjml", - "extensions": [ - ".mjml" - ], - "aliases": [ - "MJML", - "mjml" - ], - "configuration": "./language-configuration.json" - }], - "grammars": [{ - "language": "mjml", - "scopeName": "text.mjml.basic", - "path": "./syntaxes/MJML.tmLanguage" - }], - "snippets": [{ - "language": "mjml", - "path": "./snippets/mjml.json" - }], + "languages": [ + { + "id": "mjml", + "extensions": [ + ".mjml" + ], + "aliases": [ + "MJML", + "mjml" + ], + "configuration": "./language-configuration.json" + } + ], + "grammars": [ + { + "language": "mjml", + "scopeName": "text.mjml.basic", + "path": "./syntaxes/MJML.tmLanguage" + } + ], + "snippets": [ + { + "language": "mjml", + "path": "./snippets/mjml.json" + } + ], "menus": { - "editor/title": [{ - "when": "editorLangId == mjml", - "command": "mjml.previewToSide", - "group": "navigation" - }], - "editor/context": [{ - "when": "editorLangId == mjml", - "command": "mjml.searchInDocumentation", - "group": "mjml" - }] + "editor/title": [ + { + "when": "editorLangId == mjml", + "command": "mjml.previewToSide", + "group": "navigation" + } + ], + "editor/context": [ + { + "when": "editorLangId == mjml", + "command": "mjml.searchInDocumentation", + "group": "mjml" + } + ] } }, "scripts": { @@ -295,7 +306,7 @@ "@types/mime": "^2.0.0", "@types/node": "*", "@types/nodemailer": "^4.6.5", - "typescript": "^3.0.3", + "typescript": "^3.1.1", "vscode": "^1.1.18", "@types/npm": "^2.0.29", "markdown-it": "^8.4.2", @@ -305,14 +316,13 @@ "dependencies": { "ab-webshot": "^1.0.0", "copy-paste": "^1.3.0", - "file-url": "^2.0.2", "is-url": "^1.2.4", "js-beautify": "^1.8.6", "mime": "^2.3.1", "mjml": "^4.1.2", "node-fetch": "2.2.0", - "node-mailjet": "^3.2.1", + "node-mailjet": "^3.3.0", "nodemailer": "^4.6.8", - "npm": "^6.2.0" + "npm": "^6.4.1" } -} \ No newline at end of file +} diff --git a/src/helper.ts b/src/helper.ts index f7034ea..eb6f849 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -2,9 +2,10 @@ import * as vscode from "vscode"; import * as path from "path"; +import * as fs from "fs"; import * as beautifyJS from "js-beautify"; -import fileUrl = require("file-url"); +import * as mime from "mime"; import mjml2html = require("mjml"); export default class Helper { @@ -65,11 +66,27 @@ export default class Helper { } } + static encodeImage(filePath: string, original: string): string { + let mimeType: string = mime.getType(filePath); + if (!mimeType || ["bmp", "gif", "jpeg", "jpg", "png", "svg"].indexOf(mime.getExtension(mimeType)) == -1) { + return original; + } + + if (filePath && fs.existsSync(filePath) && fs.statSync(filePath).isFile()) { + let data: Buffer = fs.readFileSync(filePath); + if (data) { + return `data:${mimeType};base64,${data.toString("base64")}`; + } + } + + return original; + } + static fixLinks(text: string, mjmlPath?: string): string { return text.replace( new RegExp(/((?:src|href|url)(?:=|\()(?:[\'\"]|))((?!http|\\|"|#).+?)([\'\"]|\))/, "gmi"), (subString: string, p1: string, p2: string, p3: string): string => { - return [p1, fileUrl(path.join(path.dirname(((mjmlPath) ? mjmlPath : this.getPath())), p2)), p3].join(""); + return [p1, this.encodeImage(path.join(path.dirname(((mjmlPath) ? mjmlPath : this.getPath())), p2), p2), p3].join(""); } ); }