mdOutline(markdown)

This returns an object representing the structure of the markdown document according to its headings.

  • The object’s keys will be the document’s headings in order.
  • The object’s values will be the text of those sections or, if the section has its own headings, a subobject for that portion of the document.
  • For a given section that has subheadings, any text that appears before the first subheading is included in an initial _text property for that section.

Example: Suppose the markdown document headings.md contains various headings:

# Section 1

Introduction for section 1

## Section 1.1

Text of section 1.1.

More text

## Section 1.2

Text of section 1.2.

# Section 2

## Section 2.1

Introduction for section 2.1

### Section 2.1.1

Text of section 2.1.1.

The outline of this document looks like:

$ ori Origami.mdOutline headings.md
Section 1:
  _text: Introduction for section 1
  Section 1.1: |-
    Text of section 1.1.

    More text
  Section 1.2: Text of section 1.2.
Section 2:
  Section 2.1:
    _text: Introduction for section 2.1
    Section 2.1.1: Text of section 2.1.1.

A common use for an outline is to render the outline’s keys as navigation links. For example, the following template converts an outline to a list of links for the top-level headings:

(outline) => Tree.indent`
  <ul>
    ${ Tree.map(outline, (_, heading) => Tree.indent`
      <li>
        <a href="#${ Origami.slug(heading) }">${ heading }</a>
      </li>
    `)}
  </ul>
`

Applying this to the outline:

$ ori headings.ori Origami.mdOutline headings.md
<ul>
  <li>
    <a href="#section-1">Section 1</a>
  </li>
  <li>
    <a href="#section-2">Section 2</a>
  </li>
</ul>

See also Origami.mdHtml for translating a markdown document to HTML.