Documentation

Lean.Data.Markdown.Parser.BlockZipper

The In-Progress Zipper #

While identifying the block structure of a document, lines are checked one at a time and added in order. A zipper-like structure makes it easy to see the surrounding block context and to modify it at the right-hand edge.

A container that is currently open and may still receive child blocks.

  • blockquote {s : String.Slice} (markers : Array s.Subslice) : OpenContainer s

    A blockquote. markers accumulates the > markers from every continuation line that has been seen so far.

  • listItem {s : String.Slice} (list : OpenList s) (marker : s.Subslice) (contentColumn : Columns) : OpenContainer s

    A list item that is open, which makes it the last item of its list so far.

    • list is the list that the item belongs to, with the items that closed before this one.
    • marker is this item's bullet or ordered marker.
    • contentColumn is the column at which the item's content begins. Subsequent lines must be indented to at least this column to count as continuations of this item (CommonMark §5.2).
Instances For

    A frame of the zipper's spine, which is an open container plus the children that have already been closed inside it, in source order.

    • container : OpenContainer s

      The container in this frame. Subsequent frames in the stack represent the last child of this open container.

    • children : Children s

      The children that have already been closed inside this frame's container.

    Instances For

      A leaf block that is currently open and may still accept additional source lines.

      • paragraph {s : String.Slice} (lines : Lines s) : OpenLeaf s

        An open paragraph that is being extended line by line. Closing the paragraph (because of a blank line, a new block opener, or the parent container closing) finalizes it as Block.Raw.paragraph.

      • fencedCode {s : String.Slice} (info : FenceInfo s) (openFence : s.Subslice) (lines : Array (VerbatimLine s)) : OpenLeaf s

        An open fenced code block. lines accumulates content lines until either a matching closing fence appears (yielding Block.Raw.fencedCode with closeFence? := some _) or the parent container closes at EOF (yielding closeFence? := none).

      • indentedCode {s : String.Slice} (lines pendingBlanks : Array (VerbatimLine s)) : OpenLeaf s

        An open indented code block.

        • lines are the content lines that have been committed so far, after the four columns of indentation.
        • pendingBlanks records blank lines that may belong to this block. They are promoted to lines when a subsequent indented line continues the block, and discarded when an unindented non-blank line closes the block. This matches CommonMark's rule that blank lines between indented chunks are part of the code block, but blank lines that follow the final chunk are not.
      • html {s : String.Slice} (kind : HtmlBlockKind) (lines : Array (VerbatimLine s)) : OpenLeaf s

        An open HTML block. kind selects the end condition, and lines accumulates the block's lines, starting with the one that met the start condition.

      Instances For

        The block parsing state. Maintains the spine of currently-open containers plus an optional open leaf at the bottom.

        An empty spine means that only the document is open.

        Invariants:

        • If openLeaf? is some _, that leaf logically lives inside the deepest spine frame, or directly under the document if the spine is empty. Extending the leaf adds to its content, and closing the leaf pushes a Block.Raw onto that container's children.
        • A list contains only list items. An OpenList has items and nothing else, and every open list is either the list of an item frame or the pending list of the container around it. Children.push, the one operation that appends a block, finishes the pending list first.
        • document : Children s

          The children of the document root.

        • spine : Array (ZipperFrame s)

          Open containers below the document root, deepest last.

        • openLeaf? : Option (OpenLeaf s)

          An open leaf node, if one is present.

        • blankLineFloor? : Option Nat

          The position in spine of the outermost list that the most recent blank line could still make loose (CommonMark §5.3), or none when there is no such list or the next block has begun. A list is at the position of its open item's frame, or one past the deepest frame when it is the pending list of the deepest container.

          A blank line makes a list loose when the next block begins in one of the list's items. The lists it could make loose are therefore the open lists around it, from this position inward. The outermost of them is inside the nearest enclosing blockquote, because a blank line inside a blockquote separates blocks of the blockquote, not blocks of a list that contains the blockquote.

        Instances For

          A zipper with only the document root open, no children, and no open leaf.

          Equations
          Instances For

            The deepest currently-open container, or none if only the document is open.

            Equations
            Instances For

              Closes any open leaf, attaching it to the deepest container.

              Equations
              • One or more equations did not get rendered due to their size.
              Instances For

                The least spine index from which every deeper frame is a list item.

                It is one past the deepest blockquote, or 0 when there is none.

                Equations
                • One or more equations did not get rendered due to their size.
                Instances For

                  Records a blank line in the deepest open container.

                  A blank line between two blocks of a list item, or between two items, makes the list loose (CommonMark §5.3). Which list that is depends on where the next block begins, so the blank line is remembered until then, along with the outermost list it could affect. A blank line inside a blockquote affects only the blockquote's own content.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    Records a line that continues the open block. Any blank line before it was inside that block instead of between two blocks, so it doesn't make any list loose.

                    Equations
                    Instances For

                      Closes the deepest container. A blockquote becomes the last child of the container around it. A list item is added to its list, which becomes the pending list of the container around it, since the next line may add another item. Does nothing when only the document is open.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For

                        Opens a blockquote as the last child of the deepest open container, closing any open leaf first.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For
                          def Lean.Markdown.BlockZipper.openItem {s : String.Slice} (z : BlockZipper s) (kind : ListKind) (marker : s.Subslice) (contentColumn : Columns) :

                          Opens a list item as the last child of the deepest open container, closing any open leaf first. The item joins the container's pending list when that list is of the item's kind; otherwise the item begins a new list. A blank line before the item makes the list that it joins loose.

                          Equations
                          • One or more equations did not get rendered due to their size.
                          Instances For

                            Replaces the open leaf at the bottom of the spine, closing any prior one.

                            Equations
                            Instances For

                              Adds a finalized block as a child of the deepest open container, closing any open leaf first. Used for blocks like ATX headings that don't go through OpenLeaf.

                              Equations
                              Instances For

                                Appends a source line to the open paragraph, if any. Otherwise, does nothing.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  Appends a verbatim line to the open fenced code block, if any. Otherwise, does nothing.

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Appends a verbatim line to the open HTML block, if any. Otherwise, does nothing.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For

                                      Closes the open fenced code block with a matching closing fence.

                                      Equations
                                      • One or more equations did not get rendered due to their size.
                                      Instances For

                                        Appends an indented content line to the open indented code block. Any pending blanks that were recorded since the last content line are promoted to real content lines first.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For

                                          Records a blank line provisionally inside the open indented code block. It is incorporated into the block if a later indented line continues the block; otherwise, it is discarded when the block closes.

                                          Equations
                                          • One or more equations did not get rendered due to their size.
                                          Instances For

                                            Appends m to the markers of the blockquote frame at spine index i. A frame of another kind is left as it is.

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For

                                              Closes every container down to the document root and returns its children.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For