예제 #1
0
        private static void SetRowSpanState(List <GridTableState.ColumnSlice> columns, StringSlice line, out bool isHeaderRow, out bool hasRowSpan)
        {
            var lineStart = line.Start;

            isHeaderRow = line.PeekChar(1) == '=' || line.PeekChar(2) == '=';
            hasRowSpan  = false;
            foreach (var columnSlice in columns)
            {
                if (columnSlice.CurrentCell != null)
                {
                    line.Start = lineStart + columnSlice.Start + 1;
                    line.End   = lineStart + columnSlice.End - 1;
                    line.Trim();
                    if (line.IsEmptyOrWhitespace() || !IsRowSeperator(line))
                    {
                        hasRowSpan = true;
                        columnSlice.CurrentCell.RowSpan++;
                        columnSlice.CurrentCell.AllowClose = false;
                    }
                    else
                    {
                        columnSlice.CurrentCell.AllowClose = true;
                    }
                }
            }
        }
예제 #2
0
        public override bool Match(InlineProcessor processor, ref StringSlice slice)
        {
            var startPosition = slice.Start;

            if (TryParse(ref slice, out HtmlAttributes attributes))
            {
                var inline = processor.Inline;

                // If the current object to attach is either a literal or delimiter
                // try to find a suitable parent, otherwise attach the html attributes to the block
                if (inline is LiteralInline)
                {
                    while (true)
                    {
                        inline = inline.Parent;
                        if (!(inline is DelimiterInline))
                        {
                            break;
                        }
                    }
                }
                var objectToAttach = inline == null || inline == processor.Root ? (MarkdownObject)processor.Block : inline;

                // If the current block is a Paragraph, but only the HtmlAttributes is used,
                // Try to attach the attributes to the following block
                if (objectToAttach is ParagraphBlock paragraph &&
                    paragraph.Inline.FirstChild == null &&
                    processor.Inline == null &&
                    slice.IsEmptyOrWhitespace())
                {
                    var parent           = paragraph.Parent;
                    var indexOfParagraph = parent.IndexOf(paragraph);
                    if (indexOfParagraph + 1 < parent.Count)
                    {
                        objectToAttach = parent[indexOfParagraph + 1];
                        // We can remove the paragraph as it is empty
                        paragraph.RemoveAfterProcessInlines = true;
                    }
                }

                var currentHtmlAttributes = objectToAttach.GetAttributes();
                attributes.CopyTo(currentHtmlAttributes, true, false);

                // Update the position of the attributes
                currentHtmlAttributes.Span.Start = processor.GetSourcePosition(startPosition, out int line, out int column);
                currentHtmlAttributes.Line       = line;
                currentHtmlAttributes.Column     = column;
                currentHtmlAttributes.Span.End   = currentHtmlAttributes.Span.Start + slice.Start - startPosition - 1;

                // We don't set the processor.Inline as we don't want to add attach attributes to a particular entity
                return(true);
            }

            return(false);
        }