Example #1
0
        public NamedParameterDetailsSection(NamedValuedParameterDocumentation model)
        {
            m_Model = model ?? throw new ArgumentNullException(nameof(model));

            var name = model.Name ?? model.ShortName;

            Heading = new MdHeading(3, new MdCompositeSpan(new MdCodeSpan(name !), " Parameter"));
        }
Example #2
0
        public void Anchor_is_initlaized_with_auto_generated_value(string headingText, string expectedAnchor)
        {
            // ARRANGE
            var heading = new MdHeading(1, new MdRawMarkdownSpan(headingText));

            // ACT / ASSERT
            Assert.Equal(expectedAnchor, heading.Anchor);
        }
Example #3
0
        public void MdHeading_can_be_initialized_with_span_content()
        {
            var text = new MdTextSpan("Content");

            var heading = new MdHeading(text, 1);

            Assert.Same(text, heading.Text.Content);
        }
Example #4
0
        public void MdHeading_can_be_initialized_with_string_content_01()
        {
            var heading = new MdHeading("Content", 1);

            Assert.IsType <MdTextSpan>(heading.Text.Content);

            var textSpan = (MdTextSpan)heading.Text.Content;

            Assert.Equal("Content", textSpan.Text);
        }
Example #5
0
        public void Anchor_can_be_set()
        {
            // ARRANGE
            var heading = new MdHeading(1, "My Heading")
            {
                // ACT
                Anchor = "custom-anchor"
            };

            // ASSERT
            Assert.Equal("custom-anchor", heading.Anchor);
        }
Example #6
0
        public PositionalParameterDetailsSection(PositionalParameterDocumentation model)
        {
            m_Model = model ?? throw new ArgumentNullException(nameof(model));

            if (!String.IsNullOrWhiteSpace(m_Model.InformationalName))
            {
                Heading = new MdHeading(3, new MdCompositeSpan(new MdCodeSpan(m_Model.InformationalName), $" Parameter (Position {m_Model.Position})"));
            }
            else
            {
                //TODO: Find a better heading
                Heading = new MdHeading(3, new MdCompositeSpan($"Parameter (Position {m_Model.Position})"));
            }
        }
Example #7
0
        public void DeepEquals_returns_expected_value(
            [CombinatorialValues(1, 2, 3, 4, 5, 6)] int level,
            [CombinatorialValues("Heading", "", "some text")] string text)
        {
            var instance1 = new MdHeading(level, text);
            var instance2 = new MdHeading(level, text);
            var instance3 = new MdHeading(level, "SomeOtherText");

            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 MdParagraph()));
        }
Example #8
0
        public void MdHeading_can_be_initialized_with_string_content_03()
        {
            var heading = new MdHeading(1, "Content1", "Content2");

            Assert.IsType <MdCompositeSpan>(heading.Text.Content);
            var compositeSpan = (MdCompositeSpan)heading.Text.Content;

            Assert.IsType <MdTextSpan>(compositeSpan.Spans[0]);
            Assert.IsType <MdTextSpan>(compositeSpan.Spans[1]);

            var textSpan1 = (MdTextSpan)compositeSpan.Spans[0];
            var textSpan2 = (MdTextSpan)compositeSpan.Spans[1];

            Assert.Equal("Content1", textSpan1.Text);
            Assert.Equal("Content2", textSpan2.Text);
        }
        public void Serializer_does_not_include_anchor_in_output_is_anchor_is_null_or_whitespace(string anchor)
        {
            var options = new MdSerializationOptions()
            {
                HeadingStyle       = MdHeadingStyle.Atx,
                HeadingAnchorStyle = MdHeadingAnchorStyle.Tag
            };

            var heading = new MdHeading(2, "Heading");

            heading.Anchor = anchor;

            AssertToStringEquals(
                "## Heading\r\n",
                new MdDocument(heading),
                options
                );
        }
Example #10
0
        public void Visit(MdHeading block)
        {
            m_Writer.RequestBlankLine();

            var anchor = "";

            if (!String.IsNullOrWhiteSpace(block.Anchor))
            {
                if (m_Options.HeadingAnchorStyle == MdHeadingAnchorStyle.Tag ||
                    (m_Options.HeadingAnchorStyle == MdHeadingAnchorStyle.Auto && !StringComparer.Ordinal.Equals(block.Anchor, block.AutoGeneratedId)))
                {
                    anchor = $"<a id=\"{block.Anchor}\"></a>";
                }
            }

            if (m_Options.HeadingStyle == MdHeadingStyle.Setext && block.Level <= 2)
            {
                var underlineChar = block.Level == 1 ? '=' : '-';
                var text          = block.Text.ToString(m_Options);

                if (!String.IsNullOrEmpty(anchor))
                {
                    m_Writer.WriteLine(anchor);
                    m_Writer.WriteLine("");
                }

                // if no maximum line length was specified, write heading into a single line
                if (m_Options.MaxLineLength <= 0)
                {
                    m_Writer.WriteLine(text);
                    m_Writer.WriteLine(new string(underlineChar, text.Length));
                }
                // if max line length was specified, split the value into multiple lines if necessary
                else
                {
                    var headingTextLines = LineFormatter.GetLines(text, m_Options.MaxLineLength - m_Writer.PrefixLength);

                    foreach (var line in headingTextLines)
                    {
                        m_Writer.WriteLine(line);
                    }
                    m_Writer.WriteLine(new string(underlineChar, headingTextLines.Max(x => x.Length)));
                }
            }
            else
            {
                var lineBuilder = new StringBuilder();

                lineBuilder.Append('#', block.Level);
                lineBuilder.Append(' ');

                if (!String.IsNullOrEmpty(anchor))
                {
                    lineBuilder
                    .Append(anchor)
                    .Append(" ");
                }

                lineBuilder.Append(block.Text.ToString(m_Options));

                m_Writer.WriteLine(lineBuilder.ToString());
            }

            m_Writer.RequestBlankLine();
        }