示例#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;
 }
        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;
        }