当前位置: 首页>>代码示例>>C#>>正文


C# MarkupRange.WalkRange方法代码示例

本文整理汇总了C#中OpenLiveWriter.Mshtml.MarkupRange.WalkRange方法的典型用法代码示例。如果您正苦于以下问题:C# MarkupRange.WalkRange方法的具体用法?C# MarkupRange.WalkRange怎么用?C# MarkupRange.WalkRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenLiveWriter.Mshtml.MarkupRange的用法示例。


在下文中一共展示了MarkupRange.WalkRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FixupHeaderRange

        /// <summary>
        /// Fixes up a range that is contained in a single header element.
        /// </summary>
        /// <param name="range">A range that is contained in a single header element.</param>
        /// <param name="turnBold">Whether or not the text should be turning bold.</param>
        private void FixupHeaderRange(MarkupRange range, bool turnBold)
        {
            IHTMLElement parentHeaderElement = range.ParentBlockElement();
            if (parentHeaderElement == null || !ElementFilters.IsHeaderElement(parentHeaderElement))
            {
                Debug.Fail("Expected entire range to be inside a single header element.");
                return;
            }

            MarkupRange expandedRange = range.Clone();

            // Make sure we expand the selection to include any <font> tags that may be wrapping us.
            MarkupPointerMoveHelper.MoveUnitBounded(expandedRange.Start, MarkupPointerMoveHelper.MoveDirection.LEFT,
                                                    MarkupPointerAdjacency.BeforeVisible, parentHeaderElement);
            MarkupPointerMoveHelper.MoveUnitBounded(expandedRange.End, MarkupPointerMoveHelper.MoveDirection.RIGHT,
                                                    MarkupPointerAdjacency.BeforeVisible, parentHeaderElement);

            // Walks in-scope elements and clears out any elements or styles that might affect the bold formatting.
            var elementsToRemove = new List<IHTMLElement>();
            expandedRange.WalkRange(
                delegate (MarkupRange currentexpandedRange, MarkupContext context, string text)
                {
                    IHTMLElement currentElement = context.Element;
                    if (currentElement != null && context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope)
                    {
                        if (IsStrongOrBold(currentElement))
                        {
                            elementsToRemove.Add(currentElement);
                        }
                        else if (IsFontableElement(currentElement) && HTMLElementHelper.IsBold((IHTMLElement2)currentElement) != turnBold)
                        {
                            currentElement.style.fontWeight = String.Empty;
                        }
                    }

                    return true;

                }, true);

            elementsToRemove.ForEach(e => markupServices.RemoveElement(e));

            // Walks the range to find any segments of text that need to be fixed up.
            var rangesToWrap = new List<MarkupRange>();
            range.WalkRange(
                delegate (MarkupRange currentRange, MarkupContext context, string text)
                {
                    if (context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_Text)
                    {
                        TextStyles currentTextStyles = new TextStyles(currentRange.Start);
                        if (currentTextStyles.Bold != turnBold)
                        {
                            rangesToWrap.Add(currentRange.Clone());
                        }
                    }

                    return true;

                }, true);

            rangesToWrap.ForEach(r => WrapRangeInFontIfNecessary(r, turnBold));
        }
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:66,代码来源:BoldApplier.cs


注:本文中的OpenLiveWriter.Mshtml.MarkupRange.WalkRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。