Exemple #1
0
        public static int GetHeadingLevel(this Block block)
        {
            ContainerBlock parent = block.Parent;

            if (parent != null)
            {
                int index = parent.IndexOf(block);
                for (int i = index; i > -1; i--)
                {
                    if (parent[i] is HeadingBlock headingBlock)
                    {
                        return(headingBlock.Level);
                    }
                }
            }
            if (block is ContainerBlock containerBlock)
            {
                int level = 7;
                foreach (var child in containerBlock)
                {
                    if (child is HeadingBlock headingBlock)
                    {
                        if (headingBlock.Level < level)
                        {
                            level = headingBlock.Level;
                        }
                    }
                }
                return(level == 7 ? 0 : level);
            }

            return(0);
        }
Exemple #2
0
        private static DefinitionList GetCurrentDefinitionList(ParagraphBlock paragraphBlock, ContainerBlock previousParent)
        {
            var index = previousParent.IndexOf(paragraphBlock) - 1;

            if (index < 0)
            {
                return(null);
            }
            var lastBlock = previousParent[index];

            if (lastBlock is BlankLineBlock)
            {
                lastBlock = previousParent[index - 1];
                previousParent.RemoveAt(index);
            }
            return(lastBlock as DefinitionList);
        }
        /// <summary>
        /// Closes a <typeparamref name="TProxy"/>.
        /// </summary>
        /// <param name="blockProcessor">The <see cref="BlockProcessor"/> processing the <typeparamref name="TProxy"/> to close. Never <c>null</c>.</param>
        /// <param name="block">The <typeparamref name="TProxy"/> to close. Never <c>null</c>.</param>
        /// <returns>False if the block should be discarded, true otherwise.</returns>
        protected sealed override bool CloseBlock(BlockProcessor blockProcessor, TProxy block)
        {
            TMain proxyReplacement = CloseProxy(blockProcessor, block);

            if (proxyReplacement == null)
            {
                return(false);
            }

            ContainerBlock parent = block.Parent;
            // TODO inefficient
            int index = parent.IndexOf(block);

            parent.RemoveAt(index);
            parent.Insert(index, proxyReplacement);

            return(true);
        }