private void UpdateImageLink(string href, IHTMLElement ImgElement, ILinkOptions defaultOptions) { MshtmlMarkupServices markupServices = new MshtmlMarkupServices((IMarkupServicesRaw)ImgElement.document); IHTMLElement parentElement = ImgElement.parentElement; if (!(parentElement is IHTMLAnchorElement)) { parentElement = markupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_A, null); MarkupRange range = markupServices.CreateMarkupRange(); range.MoveToElement(ImgElement, true); markupServices.InsertElement(parentElement, range.Start, range.End); //set the default target attribute for the new element string target = defaultOptions.ShowInNewWindow ? "_blank" : null; IHTMLAnchorElement htmlAnchorElement = (parentElement as IHTMLAnchorElement); if (htmlAnchorElement.target != target) //don't set the target to null if its already null (avoids adding empty target attr) { htmlAnchorElement.target = target; } ImageViewer viewer = DhtmlImageViewers.GetImageViewer(DhtmlImageViewer); if (viewer != null) { if (defaultOptions.UseImageViewer) { viewer.Apply(htmlAnchorElement, defaultOptions.ImageViewerGroupName); } } } parentElement.setAttribute("href", href, 0); }
public override void Apply(MshtmlMarkupServices markupServices, MarkupRange markupRange, MshtmlCoreCommandSet commands) { const string smallCapsAttribute = "style=\"font-variant: small-caps\""; ElementFactory factory = () => markupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_FONT, smallCapsAttribute); WrapInElement(factory, markupServices, markupRange); }
public override void Apply(MshtmlMarkupServices markupServices, MarkupRange markupRange, MshtmlCoreCommandSet commands) { // Special case because MSHTML is not able remove underlines from <a> elements. if (!Underline) { // Find the parent <a> element (if one exists). IHTMLElement currentElement = markupRange.Start.CurrentScope; while (currentElement != null && !(currentElement is IHTMLAnchorElement)) { currentElement = currentElement.parentElement; } if (currentElement != null) { // Explicitly remove the underline. const string noTextDecorationAttribute = "style=\"text-decoration: none\""; ElementFactory factory = () => markupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_FONT, noTextDecorationAttribute); WrapInElement(factory, markupServices, markupRange); return; } } if (!commands[IDM.UNDERLINE].Enabled) { return; } commands[IDM.UNDERLINE].Execute(); Debug.Assert(commands[IDM.UNDERLINE].Latched == Underline, "UnderlineTextStyle did not yield the correct results."); }
public override void Apply(MshtmlMarkupServices markupServices, MarkupRange markupRange, MshtmlCoreCommandSet commands) { string fontSizeAttribute = String.Format(CultureInfo.InvariantCulture, "style=\"font-size:{0:F1}pt\"", FontSizeInPoints); ElementFactory factory = () => markupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_FONT, fontSizeAttribute); WrapInElement(factory, markupServices, markupRange); }
public override void Apply(MshtmlMarkupServices markupServices, MarkupRange markupRange, MshtmlCoreCommandSet commands) { const string overlineAttribute = "style=\"text-decoration: overline\""; ElementFactory factory = () => markupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_FONT, overlineAttribute); WrapInElement(factory, markupServices, markupRange); }
public static IHTMLElement WrapRangeInElement(MshtmlMarkupServices services, MarkupRange range, _ELEMENT_TAG_ID tagId, string attributes) { IHTMLElement newElement = services.CreateElement(tagId, attributes); services.InsertElement(newElement, range.Start, range.End); return(newElement); }
private IHTMLElement WrapRangeInSpanElement(_ELEMENT_TAG_ID tagId, string attributes, MarkupRange spanRange) { MarkupRange insertionRange = _markupServices.CreateMarkupRange(); IHTMLElement newSpanElement = _markupServices.CreateElement(tagId, attributes); //insert the new span element in front of the span content insertionRange.Start.MoveToPointer(spanRange.Start); insertionRange.End.MoveToPointer(spanRange.Start); _markupServices.InsertElement(newSpanElement, insertionRange.Start, insertionRange.End); //move the span content inside the new span element insertionRange.Start.MoveAdjacentToElement(newSpanElement, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterBegin); spanRange.Start.MoveAdjacentToElement(newSpanElement, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd); _markupServices.Move(spanRange.Start, spanRange.End, insertionRange.Start); return(newSpanElement); }
private IHTMLElement CreateNodeForCentering() { // Create markup services using the element's document that we are analyzing MshtmlMarkupServices MarkupServices = new MshtmlMarkupServices(_element.document as IMarkupServicesRaw); MarkupPointer end = MarkupServices.CreateMarkupPointer(); MarkupPointer start = MarkupServices.CreateMarkupPointer(); // Find the element that we will want to wrap. IHTMLElement elementToEncapsulate = _element; // If the elements parent is an A, we will also want to // wrap the A and not just the image inside if (_element.parentElement.tagName == "A") { elementToEncapsulate = _element.parentElement; } // Move the starting pointer to before the begining of the element we want to wrap start.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin); // Find this elements parent IHTMLElement3 currentBlockScope = start.CurrentBlockScope() as IHTMLElement3; // If its parent is also the div that is around the post // we need to actually create a new div and just put it around the element // If it is splittable block, split it // e.g "<DIV>Blah<IMG/>Blah</DIV>" => "<DIV>Blah</DIV><DIV><IMG/></DIV><DIV>Blah</DIV>" if (!IsBodyElement(currentBlockScope)) { // We are in a block that can be split so split it at the begining and end MarkupHelpers.SplitBlockForInsertionOrBreakout(MarkupServices, null, start); end.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd); MarkupHelpers.SplitBlockForInsertionOrBreakout(MarkupServices, null, end); // Position start back to the beginning of our element start.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeBegin); } // Now we can wrap it in an P tag (centering node) end.MoveAdjacentToElement(elementToEncapsulate, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterEnd); IHTMLElement centeringElement = MarkupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_P, string.Empty); MarkupServices.InsertElement(centeringElement, start, end); return(centeringElement); }
public override void Apply(MshtmlMarkupServices markupServices, MarkupRange markupRange, MshtmlCoreCommandSet commands) { ElementFactory factory = () => markupServices.CreateElement(_ELEMENT_TAG_ID.TAGID_SUP, String.Empty); WrapInElement(factory, markupServices, markupRange); }