Esempio n. 1
0
 public static RwHtmlRootNode ParseMarkup(string markup)
 {
     var tokenizer = new RwHtmlTokenizer();
     tokenizer.Tokenize(new StringReader(markup));
     var parser = new RwHtmlParser();
     var node = parser.Parse(tokenizer.Tokens);
     return node;
 }
Esempio n. 2
0
 public RwHtmlCompletionSource(RwHtmlCompletionSourceProvider sourceProvider, RwHtmlParser parser, 
     RwHtmlClassifier classifier, ITextBuffer textBuffer, VisualStudioWorkspace workspace, 
     IGlyphService glyphService, DTE2 dte, RedwoodConfigurationProvider configurationProvider,
     MetadataControlResolver metadataControlResolver)
 {
     this.sourceProvider = sourceProvider;
     this.textBuffer = textBuffer;
     this.classifier = classifier;
     this.parser = parser;
     this.workspace = workspace;
     this.glyphService = glyphService;
     this.dte = dte;
     this.configurationProvider = configurationProvider;
     this.MetadataControlResolver = metadataControlResolver;
 }
        protected override bool Execute(uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut, IOleCommandTarget nextCommandTarget)
        {
            var groupId = CommandGroupId;
            if (nextCommandTarget.Exec(ref groupId, nCmdID, nCmdexecopt, pvaIn, pvaOut) == VSConstants.S_OK)
            {
                // parse the content
                var tokenizer = new RwHtmlTokenizer();
                var text = TextView.TextSnapshot.GetText();
                tokenizer.Tokenize(new StringReader(text));
                var parser = new RwHtmlParser();
                var node = parser.Parse(tokenizer.Tokens);

                // prepare the metadata control resolver
                var completionSource = TextView.TextBuffer.Properties.GetProperty<RwHtmlCompletionSource>(typeof(RwHtmlCompletionSource));
                var metadataControlResolver = completionSource.MetadataControlResolver;
                metadataControlResolver.ReloadAllControls(completionSource.GetCompletionContext());

                try
                {
                    CompletionHelper.DTE.UndoContext.Open("Format RWHTML document");
                    var edit = TextView.TextBuffer.CreateEdit(EditOptions.None, null, null);

                    // fix the casing of all elements
                    var editText = new StringBuilder(text);
                    foreach (var element in node.EnumerateNodes().OfType<RwHtmlElementNode>())
                    {
                        FixElement(editText, metadataControlResolver, TextView.TextBuffer, element);
                    }
                    edit.Replace(0, editText.Length, editText.ToString());
                    edit.Apply();
                }
                finally
                {
                    CompletionHelper.DTE.UndoContext.Close();
                }
            }

            return true;
        }
        public ICompletionSource TryCreateCompletionSource(ITextBuffer textBuffer)
        {
            return textBuffer.Properties.GetOrCreateSingletonProperty(() =>
            {
                var classifierProvider = new RwHtmlClassifierProvider()
                {
                    Registry = Registry
                };

                ConfigurationProvider = new RedwoodConfigurationProvider();
                MetadataControlResolver = new MetadataControlResolver();

                WatchWorkspaceChanges();

                Parser = new RwHtmlParser();
                Classifier = (RwHtmlClassifier)classifierProvider.GetClassifier(textBuffer);

                return new RwHtmlCompletionSource(this, Parser, Classifier, textBuffer,
                    Workspace, GlyphService, CompletionHelper.DTE, ConfigurationProvider, MetadataControlResolver);
            });
        }