Пример #1
0
        [InlineData("xref:some_topic")]     // DocFX cross-reference
        public void ToString_returns_the_expected_value(string link)
        {
            var text          = "Link Title";
            var expectedValue = $"[{text}]({link})";

            var span = new MdLinkSpan(text, link);

            Assert.Equal(expectedValue, span.ToString());
        }
Пример #2
0
        public void ToString_escapes_special_characters_in_link_text(char charToEscape)
        {
            var title = $"prefix{charToEscape}suffix";
            var link  = "file.md";
            var span  = new MdLinkSpan(title, link);

            var expectedValue = $"[prefix\\{charToEscape}suffix]({link})";

            Assert.Equal(expectedValue, span.ToString());
        }
Пример #3
0
        public void DeepEquals_returns_expected_value()
        {
            var instance1 = new MdLinkSpan("content", "http://uri");
            var instance2 = new MdLinkSpan("content", "http://uri");
            var instance3 = new MdLinkSpan("other content", "http://uri");
            var instance4 = new MdLinkSpan("other content", "http://uri2");

            Assert.True(instance1.DeepEquals(instance1));
            Assert.True(instance1.DeepEquals(instance2));

            Assert.False(instance1.DeepEquals(null));
            Assert.False(instance1.DeepEquals(instance3));
            Assert.False(instance1.DeepEquals(new MdTextSpan("")));
            Assert.False(instance3.DeepEquals(instance4));
        }
Пример #4
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);
        }
Пример #5
0
        protected void AddOverloadsTableSection(MdContainerBlock block, IEnumerable <TOverload> overloads, int headingLevel)
        {
            var table = new MdTable(new MdTableRow("Signature", "Description"));

            foreach (var overload in overloads)
            {
                // optimization: we know the section we're linking to is on the same page
                // so we can create the link to the anchor without going through PageBase.CreateLink()
                var link = new MdLinkSpan(overload.Signature, "#" + m_Headings.Value[overload.MemberId].Anchor);
                table.Add(
                    new MdTableRow(link, ConvertToSpan(overload.Summary))
                    );
            }

            block.Add(
                new MdHeading("Overloads", headingLevel),
                table
                );
        }
Пример #6
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);
        }