diff --git a/EditorExtensions/Shared/Commands/MinifySelectionCommandTarget.cs b/EditorExtensions/Shared/Commands/MinifySelectionCommandTarget.cs index 589b798..2f97302 100644 --- a/EditorExtensions/Shared/Commands/MinifySelectionCommandTarget.cs +++ b/EditorExtensions/Shared/Commands/MinifySelectionCommandTarget.cs @@ -40,9 +40,9 @@ protected override bool Execute(MinifyCommandId commandId, uint nCmdexecopt, Int protected override bool IsEnabled() { - // Don't minify Markdown - _spansTuple = TextView.GetSelectedSpan(c => !c.IsOfType("Markdown") - && Mef.GetImport(c) != null); + //// Don't minify Markdown + //_spansTuple = TextView.GetSelectedSpan(c => !c.IsOfType("Markdown") + // && Mef.GetImport(c) != null); return _spansTuple != null; } } diff --git a/EditorExtensions/Shared/Compilers/CompilerRunner.cs b/EditorExtensions/Shared/Compilers/CompilerRunner.cs index b8d433d..88e0977 100644 --- a/EditorExtensions/Shared/Compilers/CompilerRunner.cs +++ b/EditorExtensions/Shared/Compilers/CompilerRunner.cs @@ -1,273 +1,273 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.Composition; -using System.Diagnostics.CodeAnalysis; -using System.IO; -using System.Text.RegularExpressions; -using System.Threading.Tasks; -using EnvDTE; -using MadsKristensen.EditorExtensions.Commands; -using MadsKristensen.EditorExtensions.Settings; -using Microsoft.VisualStudio.Utilities; - -namespace MadsKristensen.EditorExtensions.Compilers -{ - ///A base class to run a compiler on arbitrary project files and report the results. - /// - /// This class uses the project system. It - /// is used for all compilations, including - /// margins, build, and save. - /// - public abstract class CompilerRunnerBase - { - private readonly ICollection _listeners; - public abstract bool GenerateSourceMap { get; } - public abstract string TargetExtension { get; } - public IContentType SourceContentType { get; private set; } - public IContentType TargetContentType { get; private set; } - public ICompilerInvocationSettings Settings { get; private set; } - public IMarginSettings MarginSettings { get; private set; } - - [Import] - public IFileExtensionRegistryService FileExtensionRegistry { get; set; } - - [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "I can't think of a better design. (this is ugly)")] - protected CompilerRunnerBase(IContentType contentType) - { - Mef.SatisfyImportsOnce(this); - SourceContentType = contentType; - TargetContentType = FileExtensionRegistry.GetContentTypeForExtension(TargetExtension.TrimEnd('.')); - - _listeners = Mef.GetAllImports(TargetContentType); - Settings = WESettings.Instance.ForContentType(contentType); - MarginSettings = WESettings.Instance.ForContentType(contentType); - } - - ///Compiles a source file, optionally saving it to the default output directory. - /// The source file to compile. - /// True to save the compiled file(s) to the default output directory. - public Task CompileAsync(string sourcePath, bool save) - { - return save && !InvalidMarkdownRequest(sourcePath) ? CompileToDefaultOutputAsync(sourcePath) : CompileInMemoryAsync(sourcePath); - } - - private bool InvalidMarkdownRequest(string sourcePath) - { - if (SourceContentType.TypeName != "markdown") - return false; - - var targetPath = Path.GetFullPath(GetTargetPath(sourcePath)); - - return !File.Exists(targetPath); - } - - public Task CompileInMemoryAsync(string sourcePath) - { - return CompileAsync(sourcePath, null); - } - - public Task CompileToDefaultOutputAsync(string sourcePath) - { - if (!ShouldCompile(sourcePath)) - return CompileInMemoryAsync(sourcePath); - - var targetPath = Path.GetFullPath(GetTargetPath(sourcePath)); - - Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); - - return CompileAsync(sourcePath, targetPath); - } - - private static ISet _disallowedParentExtensions = new HashSet { ".png", ".jpg", ".jpeg", ".gif" }; - - ///Checks whether a file should never be compiled to disk, based on filename conventions. - public static bool ShouldCompile(string sourcePath) - { - if (Path.GetFileName(sourcePath).StartsWith("_", StringComparison.OrdinalIgnoreCase)) - return false; - - ProjectItem item = ProjectHelpers.GetProjectItem(sourcePath); - - if (item != null) - try - { - // Ignore files nested under other files such as bundle or TypeScript output - ProjectItem parent = item.Collection.Parent as ProjectItem; - - if (parent != null && parent.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile && - parent.FileNames[0].EndsWith(".sprite", StringComparison.OrdinalIgnoreCase)) - return false; - } - catch (InvalidOperationException) { } - - var parentExtension = Path.GetExtension(Path.GetFileNameWithoutExtension(sourcePath)); - return !_disallowedParentExtensions.Contains(parentExtension); - } - - ///Gets the default save location for the compiled results of the specified file, based on user settings. - public string GetTargetPath(string sourcePath) - { - var ext = TargetExtension; - - if (Settings != null && Settings.MinifyInPlace && WESettings.Instance.ForContentType(TargetContentType).AutoMinify) - ext = ".min" + ext; - - if (SourceContentType.TypeName == "css") - return Path.ChangeExtension(sourcePath, ".rtl.css"); - - if (Settings == null || string.IsNullOrEmpty(Settings.OutputDirectory)) - return Path.ChangeExtension(sourcePath, ext); - - string compiledFileName = Path.GetFileName(Path.ChangeExtension(sourcePath, ext)); - string sourceDir = Path.GetDirectoryName(sourcePath); - - // If the output path is not project-relative, combine it directly. - if (!Settings.OutputDirectory.StartsWith("~/", StringComparison.OrdinalIgnoreCase) - && !Settings.OutputDirectory.StartsWith("/", StringComparison.OrdinalIgnoreCase)) - return Path.Combine(sourceDir, Settings.OutputDirectory, compiledFileName); - - string rootDir = ProjectHelpers.GetRootFolder(); - - if (string.IsNullOrEmpty(rootDir)) - // If no project is loaded, assume relative to file anyway - rootDir = sourceDir; - - return Path.Combine( - rootDir, - Settings.OutputDirectory.TrimStart('~', '/'), - compiledFileName - ); - } - - ///Compiles the specified source file, notifying all s. - ///The path to the source file. - ///The path to save the compiled output, or null to compile in-memory. - public async Task CompileAsync(string sourcePath, string targetPath) - { - var result = await RunCompilerAsync(sourcePath, targetPath); - - if (result.IsSuccess && !string.IsNullOrEmpty(targetPath)) - { - ProjectHelpers.AddFileToProject(sourcePath, targetPath); - - var mapFile = targetPath + ".map"; - - if (GenerateSourceMap && File.Exists(mapFile)) - ProjectHelpers.AddFileToProject(targetPath, mapFile); - - if (!File.Exists(result.TargetFileName)) - return result; - - foreach (var listener in _listeners) - { - await listener.FileSaved(TargetContentType, result.TargetFileName, true, Settings != null ? Settings.MinifyInPlace : false); - - if (File.Exists(result.RtlTargetFileName)) - { - await listener.FileSaved(TargetContentType, result.RtlTargetFileName, true, Settings != null ? Settings.MinifyInPlace : false); - } - } - } - - return result; - } - - protected abstract Task RunCompilerAsync(string sourcePath, string targetPath); - } - - //[Export(typeof(ICompilerRunnerProvider))] - //[ContentType(Markdown.MarkdownContentTypeDefinition.MarkdownContentType)] - //public class MarkdownCompilerRunnerProvider : ICompilerRunnerProvider - //{ - // public CompilerRunnerBase GetCompiler(IContentType contentType) { return new MarkdownCompilerRunner(contentType); } - //} - - /////Compiles files asynchronously using MarkdownDeep and reports the results. - //class MarkdownCompilerRunner : CompilerRunnerBase - //{ - // public MarkdownCompilerRunner(IContentType contentType) : base(contentType) { } - // public override bool GenerateSourceMap { get { return false; } } - // public override string TargetExtension { get { return ".html"; } } - - // protected async override Task RunCompilerAsync(string sourcePath, string targetPath) - // { - // var markdown = new MarkdownDeep.Markdown(); - // markdown.ExtraMode = true; - // markdown.SafeMode = false; - // markdown.FormatCodeBlock = FormatCodePrettyPrint; - - // string content = await FileHelpers.ReadAllTextRetry(sourcePath); - - // // Issue with MarkdownDeep reported here https://github.com/toptensoftware/markdowndeep/issues/62 - // content = content.Replace("```", "~~~"); - - // // Change the fenced code block language for the markdown.FormatCodeBlock method - // content = Regex.Replace(content, @"(~~~\s?)(?[^\s]+)", "~~~\r{{${lang}}}"); - - // // Issue with MarkdownDeep reported here https://github.com/toptensoftware/markdowndeep/issues/63 - // foreach (Match match in Regex.Matches(content, "( {0,3}>)+( {0,3})([^\r\n]+)", RegexOptions.Multiline)) - // { - // content = content.Replace(match.Value, match.Value + " "); - // } - - // var result = markdown - // .Transform(content) - // .Replace("[ ] ", " ") - // .Replace("[x] ", " "); - - // if (!string.IsNullOrEmpty(targetPath) && - // (!File.Exists(targetPath) || await FileHelpers.ReadAllTextRetry(targetPath) != result)) - // { - // ProjectHelpers.CheckOutFileFromSourceControl(targetPath); - - // await FileHelpers.WriteAllTextRetry(targetPath, result); - // } - - // var compilerResult = await CompilerResultFactory.GenerateResult(sourcePath, targetPath, true, result, null); - - // Telemetry.TrackEvent("Compiled markdown"); - - // return compilerResult; - // } - - // public static Regex rxExtractLanguage = new Regex("^({{(.+)}}[\r\n])", RegexOptions.Compiled); - // public static string FormatCodePrettyPrint(MarkdownDeep.Markdown m, string code) - // { - // // Try to extract the language from the first line - // var match = rxExtractLanguage.Match(code); - // string language = string.Empty; - - // if (match.Success) - // { - // var g = match.Groups[2]; - // language = g.ToString().Trim().ToLowerInvariant(); - - // code = code.Substring(match.Groups[1].Length); - // } - - // if (string.IsNullOrEmpty(language)) - // { - // var d = m.GetLinkDefinition("default_syntax"); - // if (d != null) - // language = d.title; - // } - - // // Common replacements - // if (language.Equals("C#", StringComparison.OrdinalIgnoreCase)) - // language = "cs"; - // else if (language.Equals("csharp", StringComparison.OrdinalIgnoreCase)) - // language = "cs"; - // else if (language.Equals("C++", StringComparison.OrdinalIgnoreCase)) - // language = "cpp"; - - // if (string.IsNullOrEmpty(language)) - // { - // return $"
{code}
\n"; - // } - // else - // { - // return $"
{code}
\n"; - // } - // } - //} -} +//using System; +//using System.Collections.Generic; +//using System.ComponentModel.Composition; +//using System.Diagnostics.CodeAnalysis; +//using System.IO; +//using System.Text.RegularExpressions; +//using System.Threading.Tasks; +//using EnvDTE; +//using MadsKristensen.EditorExtensions.Commands; +//using MadsKristensen.EditorExtensions.Settings; +//using Microsoft.VisualStudio.Utilities; + +//namespace MadsKristensen.EditorExtensions.Compilers +//{ +// ///A base class to run a compiler on arbitrary project files and report the results. +// /// +// /// This class uses the project system. It +// /// is used for all compilations, including +// /// margins, build, and save. +// /// +// public abstract class CompilerRunnerBase +// { +// private readonly ICollection _listeners; +// public abstract bool GenerateSourceMap { get; } +// public abstract string TargetExtension { get; } +// public IContentType SourceContentType { get; private set; } +// public IContentType TargetContentType { get; private set; } +// public ICompilerInvocationSettings Settings { get; private set; } +// public IMarginSettings MarginSettings { get; private set; } + +// [Import] +// public IFileExtensionRegistryService FileExtensionRegistry { get; set; } + +// [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "I can't think of a better design. (this is ugly)")] +// protected CompilerRunnerBase(IContentType contentType) +// { +// Mef.SatisfyImportsOnce(this); +// SourceContentType = contentType; +// TargetContentType = FileExtensionRegistry.GetContentTypeForExtension(TargetExtension.TrimEnd('.')); + +// _listeners = Mef.GetAllImports(TargetContentType); +// Settings = WESettings.Instance.ForContentType(contentType); +// MarginSettings = WESettings.Instance.ForContentType(contentType); +// } + +// ///Compiles a source file, optionally saving it to the default output directory. +// /// The source file to compile. +// /// True to save the compiled file(s) to the default output directory. +// public Task CompileAsync(string sourcePath, bool save) +// { +// return save && !InvalidMarkdownRequest(sourcePath) ? CompileToDefaultOutputAsync(sourcePath) : CompileInMemoryAsync(sourcePath); +// } + +// private bool InvalidMarkdownRequest(string sourcePath) +// { +// if (SourceContentType.TypeName != "markdown") +// return false; + +// var targetPath = Path.GetFullPath(GetTargetPath(sourcePath)); + +// return !File.Exists(targetPath); +// } + +// public Task CompileInMemoryAsync(string sourcePath) +// { +// return CompileAsync(sourcePath, null); +// } + +// public Task CompileToDefaultOutputAsync(string sourcePath) +// { +// if (!ShouldCompile(sourcePath)) +// return CompileInMemoryAsync(sourcePath); + +// var targetPath = Path.GetFullPath(GetTargetPath(sourcePath)); + +// Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); + +// return CompileAsync(sourcePath, targetPath); +// } + +// private static ISet _disallowedParentExtensions = new HashSet { ".png", ".jpg", ".jpeg", ".gif" }; + +// ///Checks whether a file should never be compiled to disk, based on filename conventions. +// public static bool ShouldCompile(string sourcePath) +// { +// if (Path.GetFileName(sourcePath).StartsWith("_", StringComparison.OrdinalIgnoreCase)) +// return false; + +// ProjectItem item = ProjectHelpers.GetProjectItem(sourcePath); + +// if (item != null) +// try +// { +// // Ignore files nested under other files such as bundle or TypeScript output +// ProjectItem parent = item.Collection.Parent as ProjectItem; + +// if (parent != null && parent.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile && +// parent.FileNames[0].EndsWith(".sprite", StringComparison.OrdinalIgnoreCase)) +// return false; +// } +// catch (InvalidOperationException) { } + +// var parentExtension = Path.GetExtension(Path.GetFileNameWithoutExtension(sourcePath)); +// return !_disallowedParentExtensions.Contains(parentExtension); +// } + +// ///Gets the default save location for the compiled results of the specified file, based on user settings. +// public string GetTargetPath(string sourcePath) +// { +// var ext = TargetExtension; + +// if (Settings != null && Settings.MinifyInPlace && WESettings.Instance.ForContentType(TargetContentType).AutoMinify) +// ext = ".min" + ext; + +// if (SourceContentType.TypeName == "css") +// return Path.ChangeExtension(sourcePath, ".rtl.css"); + +// if (Settings == null || string.IsNullOrEmpty(Settings.OutputDirectory)) +// return Path.ChangeExtension(sourcePath, ext); + +// string compiledFileName = Path.GetFileName(Path.ChangeExtension(sourcePath, ext)); +// string sourceDir = Path.GetDirectoryName(sourcePath); + +// // If the output path is not project-relative, combine it directly. +// if (!Settings.OutputDirectory.StartsWith("~/", StringComparison.OrdinalIgnoreCase) +// && !Settings.OutputDirectory.StartsWith("/", StringComparison.OrdinalIgnoreCase)) +// return Path.Combine(sourceDir, Settings.OutputDirectory, compiledFileName); + +// string rootDir = ProjectHelpers.GetRootFolder(); + +// if (string.IsNullOrEmpty(rootDir)) +// // If no project is loaded, assume relative to file anyway +// rootDir = sourceDir; + +// return Path.Combine( +// rootDir, +// Settings.OutputDirectory.TrimStart('~', '/'), +// compiledFileName +// ); +// } + +// ///Compiles the specified source file, notifying all s. +// ///The path to the source file. +// ///The path to save the compiled output, or null to compile in-memory. +// public async Task CompileAsync(string sourcePath, string targetPath) +// { +// var result = await RunCompilerAsync(sourcePath, targetPath); + +// if (result.IsSuccess && !string.IsNullOrEmpty(targetPath)) +// { +// ProjectHelpers.AddFileToProject(sourcePath, targetPath); + +// var mapFile = targetPath + ".map"; + +// if (GenerateSourceMap && File.Exists(mapFile)) +// ProjectHelpers.AddFileToProject(targetPath, mapFile); + +// if (!File.Exists(result.TargetFileName)) +// return result; + +// foreach (var listener in _listeners) +// { +// await listener.FileSaved(TargetContentType, result.TargetFileName, true, Settings != null ? Settings.MinifyInPlace : false); + +// if (File.Exists(result.RtlTargetFileName)) +// { +// await listener.FileSaved(TargetContentType, result.RtlTargetFileName, true, Settings != null ? Settings.MinifyInPlace : false); +// } +// } +// } + +// return result; +// } + +// protected abstract Task RunCompilerAsync(string sourcePath, string targetPath); +// } + +// //[Export(typeof(ICompilerRunnerProvider))] +// //[ContentType(Markdown.MarkdownContentTypeDefinition.MarkdownContentType)] +// //public class MarkdownCompilerRunnerProvider : ICompilerRunnerProvider +// //{ +// // public CompilerRunnerBase GetCompiler(IContentType contentType) { return new MarkdownCompilerRunner(contentType); } +// //} + +// /////Compiles files asynchronously using MarkdownDeep and reports the results. +// //class MarkdownCompilerRunner : CompilerRunnerBase +// //{ +// // public MarkdownCompilerRunner(IContentType contentType) : base(contentType) { } +// // public override bool GenerateSourceMap { get { return false; } } +// // public override string TargetExtension { get { return ".html"; } } + +// // protected async override Task RunCompilerAsync(string sourcePath, string targetPath) +// // { +// // var markdown = new MarkdownDeep.Markdown(); +// // markdown.ExtraMode = true; +// // markdown.SafeMode = false; +// // markdown.FormatCodeBlock = FormatCodePrettyPrint; + +// // string content = await FileHelpers.ReadAllTextRetry(sourcePath); + +// // // Issue with MarkdownDeep reported here https://github.com/toptensoftware/markdowndeep/issues/62 +// // content = content.Replace("```", "~~~"); + +// // // Change the fenced code block language for the markdown.FormatCodeBlock method +// // content = Regex.Replace(content, @"(~~~\s?)(?[^\s]+)", "~~~\r{{${lang}}}"); + +// // // Issue with MarkdownDeep reported here https://github.com/toptensoftware/markdowndeep/issues/63 +// // foreach (Match match in Regex.Matches(content, "( {0,3}>)+( {0,3})([^\r\n]+)", RegexOptions.Multiline)) +// // { +// // content = content.Replace(match.Value, match.Value + " "); +// // } + +// // var result = markdown +// // .Transform(content) +// // .Replace("[ ] ", " ") +// // .Replace("[x] ", " "); + +// // if (!string.IsNullOrEmpty(targetPath) && +// // (!File.Exists(targetPath) || await FileHelpers.ReadAllTextRetry(targetPath) != result)) +// // { +// // ProjectHelpers.CheckOutFileFromSourceControl(targetPath); + +// // await FileHelpers.WriteAllTextRetry(targetPath, result); +// // } + +// // var compilerResult = await CompilerResultFactory.GenerateResult(sourcePath, targetPath, true, result, null); + +// // Telemetry.TrackEvent("Compiled markdown"); + +// // return compilerResult; +// // } + +// // public static Regex rxExtractLanguage = new Regex("^({{(.+)}}[\r\n])", RegexOptions.Compiled); +// // public static string FormatCodePrettyPrint(MarkdownDeep.Markdown m, string code) +// // { +// // // Try to extract the language from the first line +// // var match = rxExtractLanguage.Match(code); +// // string language = string.Empty; + +// // if (match.Success) +// // { +// // var g = match.Groups[2]; +// // language = g.ToString().Trim().ToLowerInvariant(); + +// // code = code.Substring(match.Groups[1].Length); +// // } + +// // if (string.IsNullOrEmpty(language)) +// // { +// // var d = m.GetLinkDefinition("default_syntax"); +// // if (d != null) +// // language = d.title; +// // } + +// // // Common replacements +// // if (language.Equals("C#", StringComparison.OrdinalIgnoreCase)) +// // language = "cs"; +// // else if (language.Equals("csharp", StringComparison.OrdinalIgnoreCase)) +// // language = "cs"; +// // else if (language.Equals("C++", StringComparison.OrdinalIgnoreCase)) +// // language = "cpp"; + +// // if (string.IsNullOrEmpty(language)) +// // { +// // return $"
{code}
\n"; +// // } +// // else +// // { +// // return $"
{code}
\n"; +// // } +// // } +// //} +//} diff --git a/EditorExtensions/Source.extension.cs b/EditorExtensions/Source.extension.cs index d238f52..11bc976 100644 --- a/EditorExtensions/Source.extension.cs +++ b/EditorExtensions/Source.extension.cs @@ -1,6 +1,6 @@ // ------------------------------------------------------------------------------ // -// This file was generated by Extensibility Tools 2015 v1.7.160 +// This file was generated by Extensibility Tools v1.8.174 // // ------------------------------------------------------------------------------ namespace MadsKristensen.EditorExtensions @@ -13,6 +13,6 @@ static class Vsix public const string Language = "en-US"; public const string Version = "2.0"; public const string Author = "Mads Kristensen"; - public const string Tags = "css, javascript, html, json, markdown"; + public const string Tags = "css, javascript, html, json"; } } diff --git a/EditorExtensions/Source.extension.vsixmanifest b/EditorExtensions/Source.extension.vsixmanifest index 323ffd6..43826cb 100644 --- a/EditorExtensions/Source.extension.vsixmanifest +++ b/EditorExtensions/Source.extension.vsixmanifest @@ -1,28 +1,28 @@  - - - Web Essentials 2015.2 - Adds many useful features to Visual Studio for web developers. Requires Visual Studio 2015 - http://vswebessentials.com/ - License.txt - http://vswebessentials.com/changelog - http://vswebessentials.com/changelog - Resources/Images/WebEssentials2012logo.png - Resources/Images/preview.png - css, javascript, html, json, markdown - - - - - - - - - - - - - - + + + Web Essentials 2015.2 + Adds many useful features to Visual Studio for web developers. Requires Visual Studio 2015 + http://vswebessentials.com/ + License.txt + http://vswebessentials.com/changelog + http://vswebessentials.com/changelog + Resources/Images/WebEssentials2012logo.png + Resources/Images/preview.png + css, javascript, html, json + + + + + + + + + + + + + + diff --git a/EditorExtensions/WebEssentials2015.csproj b/EditorExtensions/WebEssentials2015.csproj index 9644f93..f5e6880 100644 --- a/EditorExtensions/WebEssentials2015.csproj +++ b/EditorExtensions/WebEssentials2015.csproj @@ -562,13 +562,6 @@ - - - - - - -