├── art
└── screenshot.png
├── src
├── Resources
│ └── Icon.png
├── HtmlForJavascriptPackage.cs
├── Properties
│ └── AssemblyInfo.cs
├── source.extension.cs
├── Helpers
│ └── ThemeColorHelper.cs
├── Classification
│ ├── HtmlClassifierProvider.cs
│ ├── JsClassificationFormats.cs
│ └── JsStringClassifier.cs
├── source.extension.vsixmanifest
└── HtmlForJavascript.csproj
├── appveyor.yml
├── README.md
├── HtmlForJavascript.sln
├── .gitattributes
├── .editorconfig
├── .gitignore
└── LICENSE
/art/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/HtmlForJavascript/HEAD/art/screenshot.png
--------------------------------------------------------------------------------
/src/Resources/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/madskristensen/HtmlForJavascript/HEAD/src/Resources/Icon.png
--------------------------------------------------------------------------------
/src/HtmlForJavascriptPackage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using Microsoft.VisualStudio.Shell;
4 |
5 | namespace HtmlForJavascript
6 | {
7 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)]
8 | [Guid("0e5590ff-fcc4-4c8c-a4d7-b7bd17ddede4")]
9 | public sealed class HtmlForJavascriptPackage : AsyncPackage
10 | {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.InteropServices;
3 | using HtmlForJavascript;
4 |
5 | [assembly: AssemblyTitle(Vsix.Name)]
6 | [assembly: AssemblyDescription(Vsix.Description)]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany(Vsix.Author)]
9 | [assembly: AssemblyProduct(Vsix.Name)]
10 | [assembly: AssemblyCopyright(Vsix.Author)]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: AssemblyVersion(Vsix.Version)]
17 | [assembly: AssemblyFileVersion(Vsix.Version)]
18 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | image: Visual Studio 2019
2 |
3 | install:
4 | - ps: (new-object Net.WebClient).DownloadString("https://raw.github.com/madskristensen/ExtensionScripts/master/AppVeyor/vsix.ps1") | iex
5 |
6 | before_build:
7 | - ps: Vsix-IncrementVsixVersion | Vsix-UpdateBuildVersion
8 | - ps: Vsix-TokenReplacement src\source.extension.cs 'Version = "([0-9\\.]+)"' 'Version = "{version}"'
9 |
10 | build_script:
11 | - nuget restore -Verbosity quiet
12 | - msbuild /p:configuration=Release /p:DeployExtension=false /p:ZipPackageCompressionLevel=normal /v:m
13 |
14 | after_test:
15 | - ps: Vsix-PushArtifacts | Vsix-PublishToGallery
16 |
--------------------------------------------------------------------------------
/src/source.extension.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace HtmlForJavascript
7 | {
8 | internal sealed partial class Vsix
9 | {
10 | public const string Id = "7a31876a-307d-42f3-8394-49482314ae7a";
11 | public const string Name = "HTML for JavaScript";
12 | public const string Description = @"Colorizes HTML strings inside JavaScript and TypeScript. Works great for embedding HTML inside your script files.";
13 | public const string Language = "en-US";
14 | public const string Version = "1.0";
15 | public const string Author = "Mads Kristensen";
16 | public const string Tags = "html. javascript, typescript, strings";
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HTML for JavaScript
2 |
3 | [](https://ci.appveyor.com/project/madskristensen/htmlforjavascript)
4 |
5 | Colorizes HTML strings inside JavaScript and TypeScript. Works great for embedding HTML inside your script files.
6 |
7 | Download this extension from the [CI build](https://www.vsixgallery.com/extension/7a31876a-307d-42f3-8394-49482314ae7a).
8 |
9 | -----------------------------------------
10 |
11 | An updated version of [Html Syntax Highlighter for JS String](https://marketplace.visualstudio.com/items?itemName=AvoBright.HtmlSyntaxHighlighterforJSString) extension by [AvoBright](https://github.com/AvoBright) with support for Visual Studio 2019.
12 |
13 | Colorizes HTML strings inside JavaScript and TypeScript. Works great for embedding HTML inside your script files.
14 |
15 | 
16 |
17 | ## License
18 | [Apache 2.0](LICENSE)
19 |
--------------------------------------------------------------------------------
/src/Helpers/ThemeColorHelper.cs:
--------------------------------------------------------------------------------
1 | using System.Windows.Media;
2 | using EnvDTE80;
3 | using Microsoft.VisualStudio.PlatformUI;
4 |
5 | namespace HtmlForJavascript
6 | {
7 | internal static class ThemeColorHelper
8 | {
9 | public static bool IsThemeLight => CurrentColorTheme == ThemeColor.Light;
10 | public static Color TextColor
11 | {
12 | get
13 | {
14 | System.Drawing.Color textColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);
15 | return Color.FromArgb(textColor.A, textColor.R, textColor.G, textColor.B);
16 | }
17 | }
18 |
19 | internal static ThemeColor CurrentColorTheme
20 | {
21 | get
22 | {
23 | System.Drawing.Color bgColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
24 | var luminance = (bgColor.R * 0.2126) + (bgColor.G * 0.7152) + (bgColor.B * 0.0722);
25 | if (luminance > (255 / 2))
26 | {
27 | return ThemeColor.Light;
28 | }
29 | return ThemeColor.Dark;
30 | }
31 | }
32 | }
33 |
34 | internal enum ThemeColor
35 | {
36 | Light,
37 | Dark
38 | }
39 | }
--------------------------------------------------------------------------------
/src/Classification/HtmlClassifierProvider.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.Composition;
2 | using Microsoft.VisualStudio.Text;
3 | using Microsoft.VisualStudio.Text.Classification;
4 | using Microsoft.VisualStudio.Utilities;
5 |
6 | namespace HtmlForJavascript
7 | {
8 | [Export(typeof(IClassifierProvider))]
9 | [ContentType("TypeScript")]
10 | internal class HtmlClassifierProvider : IClassifierProvider
11 | {
12 | [Import]
13 | internal IClassificationTypeRegistryService ClassificationTypeRegistry = null;
14 |
15 | [Import]
16 | internal IClassifierAggregatorService ClassifierAggregator = null;
17 |
18 | private static bool createdClassifier = false;
19 |
20 | public IClassifier GetClassifier(ITextBuffer buffer)
21 | {
22 | if (createdClassifier)
23 | {
24 | return null;
25 | }
26 |
27 | try
28 | {
29 | createdClassifier = true;
30 |
31 | return buffer.Properties.GetOrCreateSingletonProperty(delegate
32 | {
33 | return new HtmlClassifier(ClassificationTypeRegistry, ClassifierAggregator.GetClassifier(buffer));
34 | });
35 | }
36 | finally
37 | {
38 | createdClassifier = false;
39 | }
40 |
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/HtmlForJavascript.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30928.19
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HtmlForJavascript", "src\HtmlForJavascript.csproj", "{56001E3E-74C5-4998-B3D9-EBC607C7DBBF}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{D1C71B49-A5E8-43D9-A9BE-6ACAC6C7FBA2}"
9 | ProjectSection(SolutionItems) = preProject
10 | .editorconfig = .editorconfig
11 | appveyor.yml = appveyor.yml
12 | README.md = README.md
13 | EndProjectSection
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|Any CPU = Debug|Any CPU
18 | Release|Any CPU = Release|Any CPU
19 | EndGlobalSection
20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
21 | {56001E3E-74C5-4998-B3D9-EBC607C7DBBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22 | {56001E3E-74C5-4998-B3D9-EBC607C7DBBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
23 | {56001E3E-74C5-4998-B3D9-EBC607C7DBBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
24 | {56001E3E-74C5-4998-B3D9-EBC607C7DBBF}.Release|Any CPU.Build.0 = Release|Any CPU
25 | EndGlobalSection
26 | GlobalSection(SolutionProperties) = preSolution
27 | HideSolutionNode = FALSE
28 | EndGlobalSection
29 | GlobalSection(ExtensibilityGlobals) = postSolution
30 | SolutionGuid = {D2B71D58-63DD-44B1-BCBE-9DFF61F0D64C}
31 | EndGlobalSection
32 | EndGlobal
33 |
--------------------------------------------------------------------------------
/src/source.extension.vsixmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | HTML for JavaScript
6 | Colorizes HTML strings inside JavaScript and TypeScript. Works great for embedding HTML inside your script files.
7 | https://github.com/madskristensen/HtmlForJavascript
8 | Resources\LICENSE
9 | Resources\Icon.png
10 | Resources\Icon.png
11 | html. javascript, typescript, strings
12 |
13 |
14 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/src/HtmlForJavascript.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16.0
5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
6 |
7 |
8 |
9 | Debug
10 | AnyCPU
11 | 2.0
12 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
13 | {56001E3E-74C5-4998-B3D9-EBC607C7DBBF}
14 | Library
15 | Properties
16 | HtmlForJavascript
17 | HtmlForJavascript
18 | v4.7.2
19 | true
20 | true
21 | true
22 | false
23 | false
24 | true
25 | true
26 | Program
27 | $(DevEnvDir)devenv.exe
28 | /rootsuffix Exp
29 |
30 |
31 | true
32 | full
33 | false
34 | bin\Debug\
35 | DEBUG;TRACE
36 | prompt
37 | 4
38 |
39 |
40 | pdbonly
41 | true
42 | bin\Release\
43 | TRACE
44 | prompt
45 | 4
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | True
56 | True
57 | source.extension.vsixmanifest
58 |
59 |
60 |
61 |
62 | Resources\LICENSE
63 | true
64 |
65 |
66 | Designer
67 | VsixManifestGenerator
68 | source.extension.cs
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | runtime; build; native; contentfiles; analyzers; buildtransitive
81 | all
82 |
83 |
84 |
85 |
86 | true
87 |
88 |
89 |
90 |
91 |
98 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | # EditorConfig is awesome:http://EditorConfig.org
2 |
3 | # top-most EditorConfig file
4 | root = true
5 |
6 | # Don't use tabs for indentation.
7 | [*]
8 | indent_style = space
9 | end_of_line = crlf
10 | # (Please don't specify an indent_size here; that has too many unintended consequences.)
11 |
12 | # Code files
13 | [*.{cs,csx,vb,vbx}]
14 | indent_size = 4
15 |
16 | # Xml project files
17 | [*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
18 | indent_size = 2
19 |
20 | # Xml config files
21 | [*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
22 | indent_size = 2
23 |
24 | # JSON files
25 | [*.json]
26 | indent_size = 2
27 |
28 | # Dotnet code style settings:
29 | [*.{cs,vb}]
30 | # Sort using and Import directives with System.* appearing first
31 | dotnet_sort_system_directives_first = true
32 | dotnet_separate_import_directive_groups = false
33 |
34 | # Avoid "this." and "Me." if not necessary
35 | dotnet_style_qualification_for_field = false : suggestion
36 | dotnet_style_qualification_for_property = false : suggestion
37 | dotnet_style_qualification_for_method = false : suggestion
38 | dotnet_style_qualification_for_event = false : suggestion
39 |
40 | # Use language keywords instead of framework type names for type references
41 | dotnet_style_predefined_type_for_locals_parameters_members = true : suggestion
42 | dotnet_style_predefined_type_for_member_access = true : suggestion
43 |
44 | # Suggest more modern language features when available
45 | dotnet_style_object_initializer = true : suggestion
46 | dotnet_style_collection_initializer = true : suggestion
47 | dotnet_style_coalesce_expression = true : suggestion
48 | dotnet_style_null_propagation = true : suggestion
49 | dotnet_style_explicit_tuple_names = true : suggestion
50 |
51 | # Naming rules - async methods to be prefixed with Async
52 | dotnet_naming_rule.async_methods_must_end_with_async.severity = warning
53 | dotnet_naming_rule.async_methods_must_end_with_async.symbols = method_symbols
54 | dotnet_naming_rule.async_methods_must_end_with_async.style = end_in_async_style
55 |
56 | dotnet_naming_symbols.method_symbols.applicable_kinds = method
57 | dotnet_naming_symbols.method_symbols.required_modifiers = async
58 |
59 | dotnet_naming_style.end_in_async_style.capitalization = pascal_case
60 | dotnet_naming_style.end_in_async_style.required_suffix = Async
61 |
62 | # Naming rules - private fields must start with an underscore
63 | dotnet_naming_rule.field_must_start_with_underscore.severity = warning
64 | dotnet_naming_rule.field_must_start_with_underscore.symbols = private_fields
65 | dotnet_naming_rule.field_must_start_with_underscore.style = start_underscore_style
66 |
67 | dotnet_naming_symbols.private_fields.applicable_kinds = field
68 | dotnet_naming_symbols.private_fields.applicable_accessibilities = private
69 |
70 | dotnet_naming_style.start_underscore_style.capitalization = camel_case
71 | dotnet_naming_style.start_underscore_style.required_prefix = _
72 |
73 | # CSharp code style settings:
74 | [*.cs]
75 | # Prefer "var" everywhere
76 | csharp_style_var_for_built_in_types = true : suggestion
77 | csharp_style_var_when_type_is_apparent = true : suggestion
78 | csharp_style_var_elsewhere = false : suggestion
79 |
80 | # Prefer method-like constructs to have a block body
81 | csharp_style_expression_bodied_methods = false : none
82 | csharp_style_expression_bodied_constructors = false : none
83 | csharp_style_expression_bodied_operators = false : none
84 |
85 | # Prefer property-like constructs to have an expression-body
86 | csharp_style_expression_bodied_properties = true : none
87 | csharp_style_expression_bodied_indexers = true : none
88 | csharp_style_expression_bodied_accessors = true : none
89 |
90 | # Suggest more modern language features when available
91 | csharp_style_pattern_matching_over_is_with_cast_check = true : suggestion
92 | csharp_style_pattern_matching_over_as_with_null_check = true : suggestion
93 | csharp_style_inlined_variable_declaration = true : suggestion
94 | csharp_style_throw_expression = true : suggestion
95 | csharp_style_conditional_delegate_call = true : suggestion
96 |
97 | # Newline settings
98 | csharp_new_line_before_open_brace = all
99 | csharp_new_line_before_else = true
100 | csharp_new_line_before_catch = true
101 | csharp_new_line_before_finally = true
102 | csharp_new_line_before_members_in_object_initializers = true
103 | csharp_new_line_before_members_in_anonymous_types = true
--------------------------------------------------------------------------------
/src/Classification/JsClassificationFormats.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.Composition;
2 | using System.Windows.Media;
3 | using Microsoft.VisualStudio.Text.Classification;
4 | using Microsoft.VisualStudio.Utilities;
5 |
6 | namespace HtmlForJavascript
7 | {
8 | internal static class FormatNames
9 | {
10 | public const string Delimiter = "HtmlDelimiter";
11 | public const string Element = "HtmlElement";
12 | public const string AttributeName = "HtmlAttributeName";
13 | public const string Quote = "HtmlQuote";
14 | public const string AttributeValue = "HtmlAttributeValue";
15 | public const string Text = "HtmlText";
16 | }
17 |
18 | internal static class ClassificationTypeDefinitions
19 | {
20 | [Export(typeof(ClassificationTypeDefinition))]
21 | [Name(FormatNames.Delimiter)]
22 | internal static ClassificationTypeDefinition Delimiter = null;
23 |
24 | [Export(typeof(ClassificationTypeDefinition))]
25 | [Name(FormatNames.Element)]
26 | internal static ClassificationTypeDefinition Element = null;
27 |
28 | [Export(typeof(ClassificationTypeDefinition))]
29 | [Name(FormatNames.AttributeName)]
30 | internal static ClassificationTypeDefinition AttributeName = null;
31 |
32 | [Export(typeof(ClassificationTypeDefinition))]
33 | [Name(FormatNames.Quote)]
34 | internal static ClassificationTypeDefinition Quote = null;
35 |
36 | [Export(typeof(ClassificationTypeDefinition))]
37 | [Name(FormatNames.AttributeValue)]
38 | internal static ClassificationTypeDefinition AttributeValue = null;
39 |
40 | [Export(typeof(ClassificationTypeDefinition))]
41 | [Name(FormatNames.Text)]
42 | internal static ClassificationTypeDefinition Text = null;
43 | }
44 |
45 | // When JS file is opened, the format definitions are created
46 | // Closing and reopen JS file, doesn't recreate the definitions
47 |
48 | [Export(typeof(EditorFormatDefinition))]
49 | [ClassificationType(ClassificationTypeNames = FormatNames.Delimiter)]
50 | [Name(FormatNames.Delimiter)]
51 | [UserVisible(true)]
52 | [Order(After = Priority.High)]
53 | internal sealed class HtmlDelimiterFormatDefinition : ClassificationFormatDefinition
54 | {
55 | public HtmlDelimiterFormatDefinition()
56 | {
57 | DisplayName = "HTML Delimiter Character (JS String Literal)";
58 | ForegroundColor = ThemeColorHelper.IsThemeLight ? Colors.Blue :
59 | Colors.Silver;
60 | }
61 | }
62 |
63 | [Export(typeof(EditorFormatDefinition))]
64 | [ClassificationType(ClassificationTypeNames = FormatNames.Element)]
65 | [Name(FormatNames.Element)]
66 | [UserVisible(true)]
67 | [Order(After = Priority.High)]
68 | internal sealed class HtmlElementFormatDefinition : ClassificationFormatDefinition
69 | {
70 |
71 | public HtmlElementFormatDefinition()
72 | {
73 | DisplayName = "HTML Element (JS String Literal)";
74 | ForegroundColor = ThemeColorHelper.IsThemeLight ? Color.FromRgb(128, 0, 0) :
75 | Color.FromRgb(86, 156, 214);
76 |
77 | }
78 | }
79 |
80 | [Export(typeof(EditorFormatDefinition))]
81 | [ClassificationType(ClassificationTypeNames = FormatNames.AttributeName)]
82 | [Name(FormatNames.AttributeName)]
83 | [UserVisible(true)]
84 | [Order(After = Priority.High)] // VS2013 only needs Before = Priority.Default, VS2012 needs Before = Priority.High, VS2010 needs After = Priority.High
85 | internal sealed class HtmlAttributeNameFormatDefinition : ClassificationFormatDefinition
86 | {
87 | public HtmlAttributeNameFormatDefinition()
88 | {
89 | DisplayName = "HTML Attribute Name (JS String Literal)";
90 | ForegroundColor = ThemeColorHelper.IsThemeLight ? Colors.Red :
91 | Color.FromRgb(156, 220, 254);
92 | }
93 | }
94 |
95 | [Export(typeof(EditorFormatDefinition))]
96 | [ClassificationType(ClassificationTypeNames = FormatNames.Quote)]
97 | [Name(FormatNames.Quote)]
98 | [UserVisible(true)]
99 | [Order(After = Priority.High)]
100 | internal sealed class HtmlQuoteFormatDefinition : ClassificationFormatDefinition
101 | {
102 | public HtmlQuoteFormatDefinition()
103 | {
104 | DisplayName = "HTML Quote (JS String Literal)";
105 | ForegroundColor = ThemeColorHelper.IsThemeLight ? Colors.Black :
106 | Color.FromRgb(210, 210, 210);
107 | }
108 | }
109 |
110 | [Export(typeof(EditorFormatDefinition))]
111 | [ClassificationType(ClassificationTypeNames = FormatNames.AttributeValue)]
112 | [Name(FormatNames.AttributeValue)]
113 | [UserVisible(true)]
114 | [Order(After = Priority.High)]
115 | internal sealed class HtmlAttributeValueFormatDefinition : ClassificationFormatDefinition
116 | {
117 | public HtmlAttributeValueFormatDefinition()
118 | {
119 | DisplayName = "HTML Attribute Value (JS String Literal)";
120 | ForegroundColor = ThemeColorHelper.IsThemeLight ? Colors.Blue :
121 | Color.FromRgb(200, 200, 200);
122 | }
123 | }
124 |
125 | [Export(typeof(EditorFormatDefinition))]
126 | [ClassificationType(ClassificationTypeNames = FormatNames.Text)]
127 | [Name(FormatNames.Text)]
128 | [UserVisible(true)]
129 | [Order(After = Priority.High)]
130 | internal sealed class HtmlTextFormatDefinition : ClassificationFormatDefinition
131 | {
132 | public HtmlTextFormatDefinition()
133 | {
134 | DisplayName = "HTML Text (JS String Literal)";
135 | ForegroundColor = ThemeColorHelper.IsThemeLight ? Colors.Black :
136 | Color.FromRgb(214, 157, 133);
137 | }
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Build results
17 | [Dd]ebug/
18 | [Dd]ebugPublic/
19 | [Rr]elease/
20 | [Rr]eleases/
21 | x64/
22 | x86/
23 | [Aa][Rr][Mm]/
24 | [Aa][Rr][Mm]64/
25 | bld/
26 | [Bb]in/
27 | [Oo]bj/
28 | [Ll]og/
29 |
30 | # Visual Studio 2015/2017 cache/options directory
31 | .vs/
32 | # Uncomment if you have tasks that create the project's static files in wwwroot
33 | #wwwroot/
34 |
35 | # Visual Studio 2017 auto generated files
36 | Generated\ Files/
37 |
38 | # MSTest test Results
39 | [Tt]est[Rr]esult*/
40 | [Bb]uild[Ll]og.*
41 |
42 | # NUNIT
43 | *.VisualState.xml
44 | TestResult.xml
45 |
46 | # Build Results of an ATL Project
47 | [Dd]ebugPS/
48 | [Rr]eleasePS/
49 | dlldata.c
50 |
51 | # Benchmark Results
52 | BenchmarkDotNet.Artifacts/
53 |
54 | # .NET Core
55 | project.lock.json
56 | project.fragment.lock.json
57 | artifacts/
58 |
59 | # StyleCop
60 | StyleCopReport.xml
61 |
62 | # Files built by Visual Studio
63 | *_i.c
64 | *_p.c
65 | *_h.h
66 | *.ilk
67 | *.meta
68 | *.obj
69 | *.iobj
70 | *.pch
71 | *.pdb
72 | *.ipdb
73 | *.pgc
74 | *.pgd
75 | *.rsp
76 | *.sbr
77 | *.tlb
78 | *.tli
79 | *.tlh
80 | *.tmp
81 | *.tmp_proj
82 | *_wpftmp.csproj
83 | *.log
84 | *.vspscc
85 | *.vssscc
86 | .builds
87 | *.pidb
88 | *.svclog
89 | *.scc
90 |
91 | # Chutzpah Test files
92 | _Chutzpah*
93 |
94 | # Visual C++ cache files
95 | ipch/
96 | *.aps
97 | *.ncb
98 | *.opendb
99 | *.opensdf
100 | *.sdf
101 | *.cachefile
102 | *.VC.db
103 | *.VC.VC.opendb
104 |
105 | # Visual Studio profiler
106 | *.psess
107 | *.vsp
108 | *.vspx
109 | *.sap
110 |
111 | # Visual Studio Trace Files
112 | *.e2e
113 |
114 | # TFS 2012 Local Workspace
115 | $tf/
116 |
117 | # Guidance Automation Toolkit
118 | *.gpState
119 |
120 | # ReSharper is a .NET coding add-in
121 | _ReSharper*/
122 | *.[Rr]e[Ss]harper
123 | *.DotSettings.user
124 |
125 | # JustCode is a .NET coding add-in
126 | .JustCode
127 |
128 | # TeamCity is a build add-in
129 | _TeamCity*
130 |
131 | # DotCover is a Code Coverage Tool
132 | *.dotCover
133 |
134 | # AxoCover is a Code Coverage Tool
135 | .axoCover/*
136 | !.axoCover/settings.json
137 |
138 | # Visual Studio code coverage results
139 | *.coverage
140 | *.coveragexml
141 |
142 | # NCrunch
143 | _NCrunch_*
144 | .*crunch*.local.xml
145 | nCrunchTemp_*
146 |
147 | # MightyMoose
148 | *.mm.*
149 | AutoTest.Net/
150 |
151 | # Web workbench (sass)
152 | .sass-cache/
153 |
154 | # Installshield output folder
155 | [Ee]xpress/
156 |
157 | # DocProject is a documentation generator add-in
158 | DocProject/buildhelp/
159 | DocProject/Help/*.HxT
160 | DocProject/Help/*.HxC
161 | DocProject/Help/*.hhc
162 | DocProject/Help/*.hhk
163 | DocProject/Help/*.hhp
164 | DocProject/Help/Html2
165 | DocProject/Help/html
166 |
167 | # Click-Once directory
168 | publish/
169 |
170 | # Publish Web Output
171 | *.[Pp]ublish.xml
172 | *.azurePubxml
173 | # Note: Comment the next line if you want to checkin your web deploy settings,
174 | # but database connection strings (with potential passwords) will be unencrypted
175 | *.pubxml
176 | *.publishproj
177 |
178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
179 | # checkin your Azure Web App publish settings, but sensitive information contained
180 | # in these scripts will be unencrypted
181 | PublishScripts/
182 |
183 | # NuGet Packages
184 | *.nupkg
185 | # The packages folder can be ignored because of Package Restore
186 | **/[Pp]ackages/*
187 | # except build/, which is used as an MSBuild target.
188 | !**/[Pp]ackages/build/
189 | # Uncomment if necessary however generally it will be regenerated when needed
190 | #!**/[Pp]ackages/repositories.config
191 | # NuGet v3's project.json files produces more ignorable files
192 | *.nuget.props
193 | *.nuget.targets
194 |
195 | # Microsoft Azure Build Output
196 | csx/
197 | *.build.csdef
198 |
199 | # Microsoft Azure Emulator
200 | ecf/
201 | rcf/
202 |
203 | # Windows Store app package directories and files
204 | AppPackages/
205 | BundleArtifacts/
206 | Package.StoreAssociation.xml
207 | _pkginfo.txt
208 | *.appx
209 |
210 | # Visual Studio cache files
211 | # files ending in .cache can be ignored
212 | *.[Cc]ache
213 | # but keep track of directories ending in .cache
214 | !?*.[Cc]ache/
215 |
216 | # Others
217 | ClientBin/
218 | ~$*
219 | *~
220 | *.dbmdl
221 | *.dbproj.schemaview
222 | *.jfm
223 | *.pfx
224 | *.publishsettings
225 | orleans.codegen.cs
226 |
227 | # Including strong name files can present a security risk
228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
229 | #*.snk
230 |
231 | # Since there are multiple workflows, uncomment next line to ignore bower_components
232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
233 | #bower_components/
234 |
235 | # RIA/Silverlight projects
236 | Generated_Code/
237 |
238 | # Backup & report files from converting an old project file
239 | # to a newer Visual Studio version. Backup files are not needed,
240 | # because we have git ;-)
241 | _UpgradeReport_Files/
242 | Backup*/
243 | UpgradeLog*.XML
244 | UpgradeLog*.htm
245 | ServiceFabricBackup/
246 | *.rptproj.bak
247 |
248 | # SQL Server files
249 | *.mdf
250 | *.ldf
251 | *.ndf
252 |
253 | # Business Intelligence projects
254 | *.rdl.data
255 | *.bim.layout
256 | *.bim_*.settings
257 | *.rptproj.rsuser
258 | *- Backup*.rdl
259 |
260 | # Microsoft Fakes
261 | FakesAssemblies/
262 |
263 | # GhostDoc plugin setting file
264 | *.GhostDoc.xml
265 |
266 | # Node.js Tools for Visual Studio
267 | .ntvs_analysis.dat
268 | node_modules/
269 |
270 | # Visual Studio 6 build log
271 | *.plg
272 |
273 | # Visual Studio 6 workspace options file
274 | *.opt
275 |
276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
277 | *.vbw
278 |
279 | # Visual Studio LightSwitch build output
280 | **/*.HTMLClient/GeneratedArtifacts
281 | **/*.DesktopClient/GeneratedArtifacts
282 | **/*.DesktopClient/ModelManifest.xml
283 | **/*.Server/GeneratedArtifacts
284 | **/*.Server/ModelManifest.xml
285 | _Pvt_Extensions
286 |
287 | # Paket dependency manager
288 | .paket/paket.exe
289 | paket-files/
290 |
291 | # FAKE - F# Make
292 | .fake/
293 |
294 | # JetBrains Rider
295 | .idea/
296 | *.sln.iml
297 |
298 | # CodeRush personal settings
299 | .cr/personal
300 |
301 | # Python Tools for Visual Studio (PTVS)
302 | __pycache__/
303 | *.pyc
304 |
305 | # Cake - Uncomment if you are using it
306 | # tools/**
307 | # !tools/packages.config
308 |
309 | # Tabs Studio
310 | *.tss
311 |
312 | # Telerik's JustMock configuration file
313 | *.jmconfig
314 |
315 | # BizTalk build output
316 | *.btp.cs
317 | *.btm.cs
318 | *.odx.cs
319 | *.xsd.cs
320 |
321 | # OpenCover UI analysis results
322 | OpenCover/
323 |
324 | # Azure Stream Analytics local run output
325 | ASALocalRun/
326 |
327 | # MSBuild Binary and Structured Log
328 | *.binlog
329 |
330 | # NVidia Nsight GPU debugger configuration file
331 | *.nvuser
332 |
333 | # MFractors (Xamarin productivity tool) working folder
334 | .mfractor/
335 |
336 | # Local History for Visual Studio
337 | .localhistory/
338 |
339 | # BeatPulse healthcheck temp database
340 | healthchecksdb
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright (c) 2015 AvoBright
190 | Copyright 2021 Mads Kristensen
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/src/Classification/JsStringClassifier.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Microsoft.VisualStudio.Text;
4 | using Microsoft.VisualStudio.Text.Classification;
5 |
6 | namespace HtmlForJavascript
7 | {
8 | #region Classifier
9 |
10 | internal class HtmlClassifier : IClassifier
11 | {
12 | private readonly IClassificationType _htmlDelimiterType;
13 | private readonly IClassificationType _htmlElementType;
14 | private readonly IClassificationType _htmlAttributeNameType;
15 | private readonly IClassificationType _htmlQuoteType;
16 | private readonly IClassificationType _htmlAttributeValueType;
17 | private readonly IClassificationType _htmlTextType;
18 | private readonly IClassifier _classifier;
19 |
20 | internal HtmlClassifier(IClassificationTypeRegistryService registry, IClassifier classifier)
21 | {
22 | _htmlDelimiterType = registry.GetClassificationType(FormatNames.Delimiter);
23 | _htmlElementType = registry.GetClassificationType(FormatNames.Element);
24 | _htmlAttributeNameType = registry.GetClassificationType(FormatNames.AttributeName);
25 | _htmlQuoteType = registry.GetClassificationType(FormatNames.Quote);
26 | _htmlAttributeValueType = registry.GetClassificationType(FormatNames.AttributeValue);
27 | _htmlTextType = registry.GetClassificationType(FormatNames.Text);
28 |
29 | _classifier = classifier;
30 | }
31 |
32 | public IList GetClassificationSpans(SnapshotSpan span)
33 | {
34 | var result = new List();
35 |
36 |
37 | foreach (ClassificationSpan cs in _classifier.GetClassificationSpans(span))
38 | {
39 | var csClass = cs.ClassificationType.Classification.ToLower();
40 |
41 | // Only apply our rules if we found a string literal
42 | if (csClass == "string")
43 | {
44 | if (cs.Span.Length > 2)
45 | {
46 | // the quotes are excluded in ScanLiteral
47 | List classification = ScanLiteral(cs.Span);
48 |
49 | if (classification != null)
50 | {
51 | result.AddRange(classification);
52 | }
53 | else
54 | {
55 | result.Add(cs);
56 | }
57 | }
58 | else
59 | {
60 | result.Add(cs);
61 | }
62 | }
63 | else
64 | {
65 | result.Add(cs);
66 | }
67 |
68 | }
69 |
70 | return result;
71 | }
72 |
73 | private enum State
74 | {
75 | Default,
76 | AfterOpenAngleBracket,
77 | ElementName,
78 | InsideAttributeList,
79 | AttributeName,
80 | AfterAttributeName,
81 | AfterAttributeEqualSign,
82 | AfterOpenDoubleQuote,
83 | AfterOpenSingleQuote,
84 | AttributeValue,
85 | InsideElement,
86 | AfterCloseAngleBracket,
87 | AfterOpenTagSlash,
88 | AfterCloseTagSlash,
89 | }
90 |
91 | private bool IsNameChar(char c)
92 | {
93 | return c == '_' || char.IsLetterOrDigit(c);
94 | }
95 |
96 | private List ScanLiteral(SnapshotSpan span)
97 | {
98 | State state = State.Default;
99 |
100 | var result = new List();
101 |
102 | var literal = span.GetText();
103 | var currentCharIndex = 0;
104 |
105 | int? continuousMark = null;
106 | var insideSingleQuote = false;
107 | var insideDoubleQuote = false;
108 |
109 | while (currentCharIndex < literal.Length)
110 | {
111 | var c = literal[currentCharIndex];
112 |
113 | //check is quote of start and end
114 | if ((currentCharIndex == 0 || currentCharIndex == (literal.Length-1)) && IsQuote(c))
115 | {
116 | currentCharIndex++;
117 | continue;
118 | }
119 |
120 | switch (state)
121 | {
122 | case State.Default:
123 | {
124 | if (c == '<')
125 | {
126 | state = State.AfterOpenAngleBracket;
127 | continuousMark = null;
128 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
129 | }
130 | break;
131 | }
132 | case State.AfterOpenAngleBracket:
133 | {
134 | if (IsNameChar(c))
135 | {
136 | continuousMark = currentCharIndex;
137 | state = State.ElementName;
138 | }
139 | else if (c == '/')
140 | {
141 | state = State.AfterCloseTagSlash;
142 | continuousMark = null;
143 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
144 | }
145 | else
146 | {
147 | return null;
148 | }
149 | break;
150 | }
151 | case State.ElementName:
152 | {
153 | if (IsNameChar(c))
154 | {
155 |
156 | }
157 | else if (char.IsWhiteSpace(c))
158 | {
159 | if (continuousMark.HasValue)
160 | {
161 | var length = currentCharIndex - continuousMark.Value;
162 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + continuousMark.Value, length), _htmlElementType));
163 | continuousMark = null;
164 | }
165 | state = State.InsideAttributeList;
166 | }
167 | else if (c == '>')
168 | {
169 | if (continuousMark.HasValue)
170 | {
171 | var length = currentCharIndex - continuousMark.Value;
172 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + continuousMark.Value, length), _htmlElementType));
173 | continuousMark = null;
174 | }
175 |
176 | state = State.AfterCloseAngleBracket;
177 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
178 | }
179 | else if (c == '/')
180 | {
181 | if (continuousMark.HasValue)
182 | {
183 | var length = currentCharIndex - continuousMark.Value;
184 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + continuousMark.Value, length), _htmlElementType));
185 | continuousMark = null;
186 | }
187 |
188 | state = State.AfterOpenTagSlash;
189 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
190 | }
191 | else
192 | {
193 | return null;
194 | }
195 | break;
196 | }
197 | case State.InsideAttributeList:
198 | {
199 | if (char.IsWhiteSpace(c))
200 | {
201 |
202 | }
203 | else if (IsNameChar(c))
204 | {
205 | continuousMark = currentCharIndex;
206 | state = State.AttributeName;
207 | }
208 | else if (c == '>')
209 | {
210 | state = State.AfterCloseAngleBracket;
211 | continuousMark = null;
212 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
213 | }
214 | else if (c == '/')
215 | {
216 | state = State.AfterOpenTagSlash;
217 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
218 | }
219 | else
220 | {
221 | return null;
222 | }
223 | break;
224 | }
225 | case State.AttributeName:
226 | {
227 | if (char.IsWhiteSpace(c))
228 | {
229 | if (continuousMark.HasValue)
230 | {
231 | var length = currentCharIndex - continuousMark.Value;
232 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + continuousMark.Value, length), _htmlAttributeNameType));
233 | continuousMark = null;
234 | }
235 | state = State.AfterAttributeName;
236 | }
237 | else if (IsNameChar(c))
238 | {
239 |
240 | }
241 | else if (c == '=')
242 | {
243 | if (continuousMark.HasValue)
244 | {
245 | var attrNameStart = continuousMark.Value;
246 | var attrNameLength = currentCharIndex - attrNameStart;
247 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + attrNameStart, attrNameLength), _htmlAttributeNameType));
248 | }
249 |
250 | state = State.AfterAttributeEqualSign;
251 | continuousMark = null;
252 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
253 | }
254 | else if (c == '>')
255 | {
256 | if (continuousMark.HasValue)
257 | {
258 | var attrNameStart = continuousMark.Value;
259 | var attrNameLength = currentCharIndex - attrNameStart;
260 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + attrNameStart, attrNameLength), _htmlAttributeNameType));
261 | }
262 |
263 | state = State.AfterCloseAngleBracket;
264 | continuousMark = null;
265 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
266 | }
267 | else if (c == '/')
268 | {
269 | if (continuousMark.HasValue)
270 | {
271 | var attrNameStart = continuousMark.Value;
272 | var attrNameLength = currentCharIndex - attrNameStart;
273 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + attrNameStart, attrNameLength), _htmlAttributeNameType));
274 | }
275 |
276 | state = State.AfterOpenTagSlash;
277 | continuousMark = null;
278 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
279 | }
280 | else
281 | {
282 | return null;
283 | }
284 | break;
285 | }
286 | case State.AfterAttributeName:
287 | {
288 | if (char.IsWhiteSpace(c))
289 | {
290 |
291 | }
292 | else if (IsNameChar(c))
293 | {
294 | continuousMark = currentCharIndex;
295 | state = State.AttributeName;
296 | }
297 | else if (c == '=')
298 | {
299 | state = State.AfterAttributeEqualSign;
300 | continuousMark = null;
301 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
302 | }
303 | else if (c == '/')
304 | {
305 | state = State.AfterOpenTagSlash;
306 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
307 | }
308 | else if (c == '>')
309 | {
310 | state = State.AfterCloseAngleBracket;
311 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
312 | }
313 | else
314 | {
315 | return null;
316 | }
317 | break;
318 | }
319 | case State.AfterAttributeEqualSign:
320 | {
321 | if (char.IsWhiteSpace(c))
322 | {
323 |
324 | }
325 | else if (IsNameChar(c))
326 | {
327 | continuousMark = currentCharIndex;
328 | state = State.AttributeValue;
329 | }
330 | else if (c == '\"')
331 | {
332 | state = State.AfterOpenDoubleQuote;
333 | insideDoubleQuote = true;
334 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlQuoteType));
335 | }
336 | else if (c == '\'')
337 | {
338 | state = State.AfterOpenSingleQuote;
339 | insideSingleQuote = true;
340 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlQuoteType));
341 | }
342 | else
343 | {
344 | return null;
345 | }
346 | break;
347 | }
348 | case State.AfterOpenDoubleQuote:
349 | {
350 | if (c == '\"')
351 | {
352 | state = State.InsideAttributeList;
353 | insideDoubleQuote = false;
354 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlQuoteType));
355 | }
356 | else
357 | {
358 | continuousMark = currentCharIndex;
359 | state = State.AttributeValue;
360 | }
361 | break;
362 | }
363 | case State.AfterOpenSingleQuote:
364 | {
365 | if (c == '\'')
366 | {
367 | state = State.InsideAttributeList;
368 | insideSingleQuote = false;
369 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlQuoteType));
370 | }
371 | else
372 | {
373 | continuousMark = currentCharIndex;
374 | state = State.AttributeValue;
375 | }
376 | break;
377 | }
378 | case State.AttributeValue:
379 | {
380 | if (c == '\'')
381 | {
382 | if (insideSingleQuote)
383 | {
384 | state = State.InsideAttributeList;
385 | insideSingleQuote = false;
386 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlQuoteType));
387 |
388 | if (continuousMark.HasValue)
389 | {
390 | var start = continuousMark.Value;
391 | var length = currentCharIndex - start;
392 | continuousMark = null;
393 |
394 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + start, length), _htmlAttributeValueType));
395 | }
396 | }
397 | }
398 | else if (c == '\"')
399 | {
400 | if (insideDoubleQuote)
401 | {
402 | state = State.InsideAttributeList;
403 | insideDoubleQuote = false;
404 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlQuoteType));
405 |
406 | if (continuousMark.HasValue)
407 | {
408 | var start = continuousMark.Value;
409 | var length = currentCharIndex - start;
410 | continuousMark = null;
411 |
412 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + start, length), _htmlAttributeValueType));
413 | }
414 | }
415 | }
416 | else
417 | {
418 |
419 | }
420 |
421 | break;
422 | }
423 | case State.AfterCloseAngleBracket:
424 | {
425 | if (c == '<')
426 | {
427 | state = State.AfterOpenAngleBracket;
428 | continuousMark = null;
429 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
430 | }
431 | else
432 | {
433 | continuousMark = currentCharIndex;
434 | state = State.InsideElement;
435 | }
436 | break;
437 | }
438 | case State.InsideElement:
439 | {
440 | if (c == '<')
441 | {
442 | state = State.AfterOpenAngleBracket;
443 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
444 |
445 | if (continuousMark.HasValue)
446 | {
447 | var start = continuousMark.Value;
448 | var length = currentCharIndex - start;
449 | continuousMark = null;
450 |
451 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + start, length), _htmlTextType));
452 | }
453 | }
454 | else
455 | {
456 |
457 | }
458 |
459 | break;
460 | }
461 | case State.AfterCloseTagSlash:
462 | {
463 | if (char.IsWhiteSpace(c))
464 | {
465 |
466 | }
467 | else if (IsNameChar(c))
468 | {
469 | continuousMark = currentCharIndex;
470 | state = State.ElementName;
471 | }
472 | else
473 | {
474 | return null;
475 | }
476 | break;
477 | }
478 | case State.AfterOpenTagSlash:
479 | {
480 | if (c == '>')
481 | {
482 | state = State.AfterCloseAngleBracket;
483 | continuousMark = null;
484 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + currentCharIndex, 1), _htmlDelimiterType));
485 | }
486 | else
487 | {
488 | return null;
489 | }
490 | break;
491 | }
492 | default:
493 | break;
494 | }
495 |
496 | ++currentCharIndex;
497 | }
498 |
499 | // if the continuous span is stopped because of end of literal,
500 | // the span was not colored, handle it here
501 | if (currentCharIndex >= literal.Length)
502 | {
503 | if (continuousMark.HasValue)
504 | {
505 | if (state == State.ElementName)
506 | {
507 | var start = continuousMark.Value;
508 | var length = literal.Length - start;
509 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + start, length), _htmlElementType));
510 | }
511 | else if (state == State.AttributeName)
512 | {
513 | var attrNameStart = continuousMark.Value;
514 | var attrNameLength = literal.Length - attrNameStart;
515 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + attrNameStart, attrNameLength), _htmlAttributeNameType));
516 | }
517 | else if (state == State.AttributeValue)
518 | {
519 | var start = continuousMark.Value;
520 | var length = literal.Length - start;
521 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + start, length), _htmlAttributeValueType));
522 | }
523 | else if (state == State.InsideElement)
524 | {
525 | var start = continuousMark.Value;
526 | var length = literal.Length - start;
527 | result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + start, length), _htmlTextType));
528 | }
529 | }
530 | }
531 |
532 | return result;
533 | }
534 | public event EventHandler ClassificationChanged;
535 |
536 | private bool IsQuote(char c)
537 | {
538 | return c == '\'' || c == '"' || c == '`';
539 | }
540 | }
541 | #endregion //Classifier
542 | }
543 |
--------------------------------------------------------------------------------