public void WrapSelection(string tag, IDictionary attributes) { //Create a string for all the attributes string attributeString = String.Empty; if (attributes != null) { foreach (string key in attributes.Keys) { attributeString += key + "=\"" + attributes[key] + "\" "; } } SynchronizeSelection(); if (_type == HtmlSelectionType.TextSelection) { Interop.IHTMLTxtRange textRange = (Interop.IHTMLTxtRange)MSHTMLSelection; string oldText = textRange.GetHtmlText(); if (oldText == null) { oldText = String.Empty; } string newText = "<" + tag + " " + attributeString + ">" + oldText + "</" + tag + ">"; textRange.PasteHTML(newText); } }