Example #1
0
        private ListPrefixHandler GetListPrefixHandler(MdList list)
        {
            switch (list)
            {
            case MdBulletList _:
                return(new BulletListPrefixHandler(m_Options));

            case MdOrderedList _:
                return(new OrderedListPrefixHandler(m_Options));

            default:
                throw new NotSupportedException($"Unsupported list type: {list.GetType().FullName}");
            }
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of <see cref="MdTaskListItem"/> containing the specified content.
 /// </summary>
 /// <param name="content">The list to initially add to the list item.</param>
 public MdTaskListItem(MdList content) : base(content)
 {
 }
Example #3
0
 public static MdAdmonition Admonition(string type, MdSpan title, MdList content) => new MdAdmonition(type, title, content);
Example #4
0
        private void VisitList(MdList list)
        {
            m_ListLevel += 1;


            if (m_ListLevel == 1)
            {
                // top-level lists should be surrounded by blank lines
                m_Writer.RequestBlankLine();
            }
            else
            {
                // prevent blank lines before nested lists
                // (blank lines may have been requested by block in parent list item)
                m_Writer.CancelRequestBlankLine();
            }

            // add prefix handler for the list
            var prefixHandler = GetListPrefixHandler(list);

            m_Writer.PushPrefixHandler(prefixHandler);

            var listItemNumber = 1;

            foreach (var listItem in list)
            {
                prefixHandler.BeginListItem();

                var lineWritten = false;

                // event handler to prevent blank lines at the start of list items
                void OnBlankLineRequested(object s, EventArgs e)
                {
                    // blank lines before top level lists ( = before the first item)
                    // should not be suppressed
                    if (listItemNumber == 1 && m_ListLevel == 1)
                    {
                        return;
                    }

                    // while no other line was written, suppress blank lines
                    if (!lineWritten)
                    {
                        m_Writer.CancelRequestBlankLine();
                    }
                }

                // event handler to update the prefix after the first line of a list item
                void OnLineWritten(object s, EventArgs e)
                {
                    lineWritten = true;
                }

                // attach event handlers
                m_Writer.LineWritten        += OnLineWritten;
                m_Writer.BlankLineRequested += OnBlankLineRequested;

                // write list item
                listItem.Accept(this);

                // detach event handlers
                m_Writer.LineWritten        -= OnLineWritten;
                m_Writer.BlankLineRequested -= OnBlankLineRequested;

                // prevent blank lines from being inserted after list items
                m_Writer.CancelRequestBlankLine();

                listItemNumber += 1;
            }

            // remove prefix handler
            m_Writer.PopPrefixHandler();

            // top-level lists should be surrounded by blank lines
            if (m_ListLevel == 1)
            {
                m_Writer.RequestBlankLine();
            }

            m_ListLevel -= 1;
        }
Example #5
0
 /// <summary>
 /// Initializes a new instance of <see cref="MdAdmonition"/>.
 /// </summary>
 ///
 /// <param name="type">
 /// The admonition's type. Any non-empty string is allowed.
 /// Recommended values are <c>attention</c>, <c>caution</c>, <c>danger</c>, <c>error</c>,
 /// <c>hint</c>, <c>important</c>, <c>note</c>, <c>tip</c> and <c>warning</c>
 /// </param>
 ///
 /// <param name="title">
 /// The admonition's title. To create a admonition without title, use a different constructor overload.
 /// </param>
 ///
 /// <param name="content">
 /// The admonition's content.
 /// </param>
 ///
 /// <exception cref="ArgumentException">Thrown when <paramref name="type"/> is null or whitespace.</exception>
 /// <exception cref="ArgumentNullException">Thrown when <paramref name="title"/> is <c>null</c>.</exception>
 public MdAdmonition(string type, MdSpan title, MdList content) : this(type, title, (MdBlock)content)
 {
 }
Example #6
0
 /// <summary>
 /// Initializes a new instance of <see cref="MdAdmonition"/>.
 /// </summary>
 ///
 /// <param name="type">
 /// The admonition's type. Any non-empty string is allowed.
 /// Recommended values are <c>attention</c>, <c>caution</c>, <c>danger</c>, <c>error</c>,
 /// <c>hint</c>, <c>important</c>, <c>note</c>, <c>tip</c> and <c>warning</c>
 /// </param>
 ///
 /// <param name="content">
 /// The admonition's content.
 /// </param>
 ///
 /// <exception cref="ArgumentException">Thrown when <paramref name="type"/> is null or whitespace.</exception>
 public MdAdmonition(string type, MdList content) : this(type, MdEmptySpan.Instance, (MdBlock)content)
 {
 }