Example #1
0
        public void Visit(ListElement listElement)
        {
            // end the current paragraph
            EndParagraph();

            if (listElement.Type == ListType.Table)
            {
                MdTableRow CreateRow(ListItemElement?itemElement)
                {
                    if (itemElement == null)
                    {
                        return(new MdTableRow("", ""));
                    }

                    var term = itemElement.Term.IsEmpty
                        ? MdEmptySpan.Instance
                        : TextBlockToMarkdownConverter.ConvertToSpan(itemElement.Term, m_SpanFactory);

                    var description = itemElement.Description.IsEmpty
                        ? MdEmptySpan.Instance
                        : TextBlockToMarkdownConverter.ConvertToSpan(itemElement.Description, m_SpanFactory);

                    return(new MdTableRow(term, description));
                }

                var table = new MdTable(
                    CreateRow(listElement.ListHeader),
                    listElement.Items.Select(CreateRow)
                    );

                CurrentBlock.Add(table);
            }
            else
            {
                var list = listElement.Type == ListType.Number ? new MdOrderedList() : (MdList) new MdBulletList();

                // add list to current block
                CurrentBlock.Add(list);

                foreach (var listItemElement in listElement.Items)
                {
                    // create a new list item and add it to the list
                    var listItem = new MdListItem();
                    list.Add(listItem);

                    // make the list item the new current block
                    m_Blocks.Push(listItem);

                    // visit list item
                    listItemElement.Accept(this);

                    // end the current paragraph and restore previous current block
                    EndParagraph();
                    m_Blocks.Pop();
                }
            }
        }
Example #2
0
        public void Visit(ListItemElement element)
        {
            if (!element.Term.IsEmpty)
            {
                var term = TextBlockToMarkdownConverter.ConvertToSpan(element.Term, m_SpanFactory);

                AddToCurrentParagraph(new MdStrongEmphasisSpan(term, ":"));
                AddToCurrentParagraph(" ");
            }

            Visit(element.Description);
        }
Example #3
0
        public void Visit(SeeElement element)
        {
            if (element is null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            // While Visual Studio only allows referring to other code elements using the <c>cref</c> attribute,
            // linking to external resources (e.g. websites) is supported by as well using the <c>href</c> attribute.
            //
            // When a both attributes are present, the external link is ignored.

            MdSpan span;

            // <seealso /> references another assembly member
            if (element.MemberId != null)
            {
                if (element.Text.IsEmpty)
                {
                    span = m_SpanFactory.GetMdSpan(element.MemberId);
                }
                else
                {
                    var linkText = TextBlockToMarkdownConverter.ConvertToSpan(element.Text, m_SpanFactory);
                    span = m_SpanFactory.CreateLink(element.MemberId, linkText);
                }
            }
            // <seealso /> references an external resource
            else if (element.Target != null)
            {
                if (element.Text.IsEmpty)
                {
                    span = new MdLinkSpan(element.Target.ToString(), element.Target);
                }
                else
                {
                    var linkText = TextBlockToMarkdownConverter.ConvertToSpan(element.Text, m_SpanFactory);
                    span = new MdLinkSpan(linkText, element.Target);
                }
            }
            else
            {
                throw new InvalidOperationException($"Encountered instance of {nameof(SeeElement)} where both {nameof(SeeElement.MemberId)} and {nameof(SeeElement.Target)} were null.");
            }

            AddToCurrentParagraph(span);
        }
Example #4
0
        public void Visit(SeeElement element)
        {
            MdSpan span;

            // <seealso /> references another assembly member
            if (element.MemberId != null)
            {
                if (element.Text.IsEmpty)
                {
                    span = m_SpanFactory.GetMdSpan(element.MemberId);
                }
                else
                {
                    var linkText = TextBlockToMarkdownConverter.ConvertToSpan(element.Text, m_SpanFactory);
                    span = m_SpanFactory.CreateLink(element.MemberId, linkText);
                }
            }
            // <seealso /> references an external resource
            else if (element.Target != null)
            {
                if (element.Text.IsEmpty)
                {
                    span = new MdLinkSpan(element.Target.ToString(), element.Target);
                }
                else
                {
                    var linkText = TextBlockToMarkdownConverter.ConvertToSpan(element.Text, m_SpanFactory);
                    span = new MdLinkSpan(linkText, element.Target);
                }
            }
            else
            {
                throw new InvalidOperationException($"Encountered instance of {nameof(SeeElement)} where both {nameof(SeeElement.MemberId)} and {nameof(SeeElement.Target)} were null.");
            }
            Result.Add(span);
        }